mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 18:42:23 +08:00

* Security (#644) * Bump y18n from 3.2.1 to 3.2.2 in /runtime/js/runtime (#639) * Create FUNDING.yml * Update README.md * Bump y18n from 3.2.1 to 3.2.2 in /runtime/js/runtime Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump elliptic from 6.5.3 to 6.5.4 in /runtime/js (#617) Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.3 to 6.5.4. - [Release notes](https://github.com/indutny/elliptic/releases) - [Commits](https://github.com/indutny/elliptic/compare/v6.5.3...v6.5.4) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump y18n from 4.0.0 to 4.0.1 in /runtime/js (#643) * Create FUNDING.yml * Update README.md * Updated sponsors * Consistent styling of README.md * Bump y18n from 4.0.0 to 4.0.1 in /runtime/js (#638) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Revert "Bump y18n from 4.0.0 to 4.0.1 in /runtime/js (#638)" (#642) This reverts commit17b28a26bd
. * Bump y18n from 4.0.0 to 4.0.1 in /runtime/js Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Support for minimum and maximum window sizes (#612) * add support for minimum and maximum window sizes * attempt to fix windows * bug fixes * support min/max window sizes on Linux and Windows * fix min/max window sizes on Linux * formatting and comments * fixes Windows DPI issue, clamps width/height values to min/max * App can't go into full screen when max size is set for Mac * fixed Linux maximum width/height on window maximize * Revert "fixed Linux maximum width/height on window maximize" This reverts commit3f7ba8b264
. The fix glitches on PopOS Co-authored-by: Lea Anthony <lea.anthony@gmail.com> * v1.13.0 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: RH12503 <48951973+RH12503@users.noreply.github.com>
100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
package runtime
|
|
|
|
import (
|
|
"bytes"
|
|
"runtime"
|
|
|
|
"github.com/abadojack/whatlanggo"
|
|
"github.com/wailsapp/wails/lib/interfaces"
|
|
"golang.org/x/text/encoding"
|
|
"golang.org/x/text/encoding/japanese"
|
|
"golang.org/x/text/encoding/korean"
|
|
"golang.org/x/text/encoding/simplifiedchinese"
|
|
"golang.org/x/text/transform"
|
|
)
|
|
|
|
func detectEncoding(text string) (encoding.Encoding, string) {
|
|
// korean
|
|
var enc encoding.Encoding
|
|
info := whatlanggo.Detect(text)
|
|
//fmt.Println("Language:", info.Lang.String(), " Script:", whatlanggo.Scripts[info.Script], " Confidence: ", info.Confidence)
|
|
switch info.Lang.String() {
|
|
case "Korean":
|
|
enc = korean.EUCKR
|
|
case "Mandarin":
|
|
enc = simplifiedchinese.GBK
|
|
case "Japanese":
|
|
enc = japanese.EUCJP
|
|
}
|
|
return enc, info.Lang.String()
|
|
}
|
|
|
|
// ProcessEncoding attempts to convert CKJ strings to UTF-8
|
|
func ProcessEncoding(text string) string {
|
|
if runtime.GOOS != "windows" {
|
|
return text
|
|
}
|
|
|
|
encoding, _ := detectEncoding(text)
|
|
if encoding != nil {
|
|
var bufs bytes.Buffer
|
|
wr := transform.NewWriter(&bufs, encoding.NewEncoder())
|
|
_, err := wr.Write([]byte(text))
|
|
defer wr.Close()
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return bufs.String()
|
|
}
|
|
return text
|
|
}
|
|
|
|
// Window exposes an interface for manipulating the window
|
|
type Window struct {
|
|
renderer interfaces.Renderer
|
|
}
|
|
|
|
// NewWindow creates a new Window struct
|
|
func NewWindow(renderer interfaces.Renderer) *Window {
|
|
return &Window{
|
|
renderer: renderer,
|
|
}
|
|
}
|
|
|
|
// SetColour sets the the window colour
|
|
func (r *Window) SetColour(colour string) error {
|
|
return r.renderer.SetColour(colour)
|
|
}
|
|
|
|
// SetMinSize sets the minimum size of a resizable window
|
|
func (r *Window) SetMinSize(width, height int) {
|
|
r.renderer.SetMinSize(width, height)
|
|
}
|
|
|
|
// SetMaxSize sets the maximum size of a resizable window
|
|
func (r *Window) SetMaxSize(width, height int) {
|
|
r.renderer.SetMaxSize(width, height)
|
|
}
|
|
|
|
// Fullscreen makes the window fullscreen
|
|
func (r *Window) Fullscreen() {
|
|
r.renderer.Fullscreen()
|
|
}
|
|
|
|
// UnFullscreen attempts to restore the window to the size/position before fullscreen
|
|
func (r *Window) UnFullscreen() {
|
|
r.renderer.UnFullscreen()
|
|
}
|
|
|
|
// SetTitle sets the the window title
|
|
func (r *Window) SetTitle(title string) {
|
|
title = ProcessEncoding(title)
|
|
r.renderer.SetTitle(title)
|
|
}
|
|
|
|
// Close shuts down the window and therefore the app
|
|
func (r *Window) Close() {
|
|
r.renderer.Close()
|
|
}
|