diff --git a/backend-golang/app.go b/backend-golang/app.go index 9eadc39..11e88b5 100644 --- a/backend-golang/app.go +++ b/backend-golang/app.go @@ -2,6 +2,7 @@ package backend_golang import ( "context" + "errors" "net/http" "os" "os/exec" @@ -14,9 +15,11 @@ import ( // App struct type App struct { - ctx context.Context - exDir string - cmdPrefix string + ctx context.Context + HasConfigData bool + ConfigData map[string]any + exDir string + cmdPrefix string } // NewApp creates a new App application struct @@ -64,6 +67,19 @@ func (a *App) UpdateApp(url string) (broken bool, err error) { return false, nil } +func (a *App) RestartApp() error { + if runtime.GOOS == "windows" { + name, err := os.Executable() + if err != nil { + return err + } + exec.Command(name, os.Args[1:]...).Start() + wruntime.Quit(a.ctx) + return nil + } + return errors.New("unsupported OS") +} + func (a *App) GetPlatform() string { return runtime.GOOS } diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 6edadd1..7fb5399 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -148,5 +148,8 @@ "Are you sure you want to clear the conversation? It cannot be undone.": "你确定要清空对话吗?这无法撤销", "Save": "保存", "Conversation Saved": "对话已保存", - "Open": "打开" + "Open": "打开", + "DPI Scaling": "显示缩放", + "Restart the app to apply DPI Scaling.": "重启应用以使显示缩放生效", + "Restart": "重启" } \ No newline at end of file diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx index aa9e795..4685c68 100644 --- a/frontend/src/pages/Settings.tsx +++ b/frontend/src/pages/Settings.tsx @@ -14,7 +14,8 @@ import { Labeled } from '../components/Labeled'; import commonStore from '../stores/commonStore'; import { observer } from 'mobx-react-lite'; import { useTranslation } from 'react-i18next'; -import { checkUpdate } from '../utils'; +import { checkUpdate, toastWithButton } from '../utils'; +import { RestartApp } from '../../wailsjs/go/backend_golang/App'; export const Languages = { dev: 'English', // i18n default @@ -30,6 +31,7 @@ export type SettingsType = { giteeUpdatesSource: boolean cnMirror: boolean host: string + dpiScaling: number customModelsPath: string customPythonPath: string } @@ -45,7 +47,7 @@ export const Settings: FC = observer(() => { return ( +
{ commonStore.setSettings({ language: lang }); - i18n.changeLanguage(lang); } }}> { @@ -65,6 +66,31 @@ export const Settings: FC = observer(() => { } } /> + { + commonStore.platform === 'windows' && + { + if (data.optionValue) { + commonStore.setSettings({ + dpiScaling: Number(data.optionValue) + }); + toastWithButton(t('Restart the app to apply DPI Scaling.'), t('Restart'), () => { + RestartApp(); + }, { + autoClose: 5000 + }); + } + }}> + { + Array.from({ length: 7 }, (_, i) => (i + 2) * 25).map((v, i) => + ) + } + + } /> + } { diff --git a/frontend/src/stores/commonStore.ts b/frontend/src/stores/commonStore.ts index 1cbdf08..d73d048 100644 --- a/frontend/src/stores/commonStore.ts +++ b/frontend/src/stores/commonStore.ts @@ -63,6 +63,7 @@ class CommonStore { giteeUpdatesSource: getUserLanguage() === 'zh', cnMirror: getUserLanguage() === 'zh', host: '127.0.0.1', + dpiScaling: 100, customModelsPath: './models', customPythonPath: '' }; diff --git a/frontend/wailsjs/go/backend_golang/App.d.ts b/frontend/wailsjs/go/backend_golang/App.d.ts index d2aceca..b7b62be 100755 --- a/frontend/wailsjs/go/backend_golang/App.d.ts +++ b/frontend/wailsjs/go/backend_golang/App.d.ts @@ -34,6 +34,8 @@ export function ReadFileInfo(arg1:string):Promise; export function ReadJson(arg1:string):Promise; +export function RestartApp():Promise; + export function SaveJson(arg1:string,arg2:any):Promise; export function StartServer(arg1:string,arg2:number,arg3:string):Promise; diff --git a/frontend/wailsjs/go/backend_golang/App.js b/frontend/wailsjs/go/backend_golang/App.js index 7593b10..ea9ef66 100755 --- a/frontend/wailsjs/go/backend_golang/App.js +++ b/frontend/wailsjs/go/backend_golang/App.js @@ -66,6 +66,10 @@ export function ReadJson(arg1) { return window['go']['backend_golang']['App']['ReadJson'](arg1); } +export function RestartApp() { + return window['go']['backend_golang']['App']['RestartApp'](); +} + export function SaveJson(arg1, arg2) { return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2); } diff --git a/main.go b/main.go index f9b2a90..d237709 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options/assetserver" + "github.com/wailsapp/wails/v2/pkg/options/windows" ) //go:embed all:frontend/dist @@ -36,13 +37,29 @@ func main() { // Create an instance of the app structure app := backend.NewApp() + var zoomFactor float64 = 1.0 + data, err := app.ReadJson("config.json") + if err == nil { + app.HasConfigData = true + app.ConfigData = data.(map[string]any) + if dpiScaling, ok := app.ConfigData["settings"].(map[string]any)["dpiScaling"]; ok { + zoomFactor = dpiScaling.(float64) / 100 + } + } else { + app.HasConfigData = false + } + // Create application with options - err := wails.Run(&options.App{ + err = wails.Run(&options.App{ Title: "RWKV-Runner", Width: 1024, Height: 680, MinWidth: 375, MinHeight: 640, + Windows: &windows.Options{ + ZoomFactor: zoomFactor, + IsZoomControlEnabled: true, + }, AssetServer: &assetserver.Options{ Assets: assets, },