add DPI Scaling setting
This commit is contained in:
parent
ce915cdf6a
commit
285e8b1577
@ -2,6 +2,7 @@ package backend_golang
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -14,9 +15,11 @@ import (
|
|||||||
|
|
||||||
// App struct
|
// App struct
|
||||||
type App struct {
|
type App struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
exDir string
|
HasConfigData bool
|
||||||
cmdPrefix string
|
ConfigData map[string]any
|
||||||
|
exDir string
|
||||||
|
cmdPrefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewApp creates a new App application struct
|
// NewApp creates a new App application struct
|
||||||
@ -64,6 +67,19 @@ func (a *App) UpdateApp(url string) (broken bool, err error) {
|
|||||||
return false, nil
|
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 {
|
func (a *App) GetPlatform() string {
|
||||||
return runtime.GOOS
|
return runtime.GOOS
|
||||||
}
|
}
|
||||||
|
@ -148,5 +148,8 @@
|
|||||||
"Are you sure you want to clear the conversation? It cannot be undone.": "你确定要清空对话吗?这无法撤销",
|
"Are you sure you want to clear the conversation? It cannot be undone.": "你确定要清空对话吗?这无法撤销",
|
||||||
"Save": "保存",
|
"Save": "保存",
|
||||||
"Conversation Saved": "对话已保存",
|
"Conversation Saved": "对话已保存",
|
||||||
"Open": "打开"
|
"Open": "打开",
|
||||||
|
"DPI Scaling": "显示缩放",
|
||||||
|
"Restart the app to apply DPI Scaling.": "重启应用以使显示缩放生效",
|
||||||
|
"Restart": "重启"
|
||||||
}
|
}
|
@ -14,7 +14,8 @@ import { Labeled } from '../components/Labeled';
|
|||||||
import commonStore from '../stores/commonStore';
|
import commonStore from '../stores/commonStore';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { useTranslation } from 'react-i18next';
|
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 = {
|
export const Languages = {
|
||||||
dev: 'English', // i18n default
|
dev: 'English', // i18n default
|
||||||
@ -30,6 +31,7 @@ export type SettingsType = {
|
|||||||
giteeUpdatesSource: boolean
|
giteeUpdatesSource: boolean
|
||||||
cnMirror: boolean
|
cnMirror: boolean
|
||||||
host: string
|
host: string
|
||||||
|
dpiScaling: number
|
||||||
customModelsPath: string
|
customModelsPath: string
|
||||||
customPythonPath: string
|
customPythonPath: string
|
||||||
}
|
}
|
||||||
@ -45,7 +47,7 @@ export const Settings: FC = observer(() => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Page title={t('Settings')} content={
|
<Page title={t('Settings')} content={
|
||||||
<div className="flex flex-col gap-2 overflow-hidden">
|
<div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden p-1">
|
||||||
<Labeled label={t('Language')} flex spaceBetween content={
|
<Labeled label={t('Language')} flex spaceBetween content={
|
||||||
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||||
value={Languages[commonStore.settings.language]}
|
value={Languages[commonStore.settings.language]}
|
||||||
@ -56,7 +58,6 @@ export const Settings: FC = observer(() => {
|
|||||||
commonStore.setSettings({
|
commonStore.setSettings({
|
||||||
language: lang
|
language: lang
|
||||||
});
|
});
|
||||||
i18n.changeLanguage(lang);
|
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
{
|
{
|
||||||
@ -65,6 +66,31 @@ export const Settings: FC = observer(() => {
|
|||||||
}
|
}
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
} />
|
} />
|
||||||
|
{
|
||||||
|
commonStore.platform === 'windows' &&
|
||||||
|
<Labeled label={t('DPI Scaling')} flex spaceBetween content={
|
||||||
|
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||||
|
value={commonStore.settings.dpiScaling + '%'}
|
||||||
|
selectedOptions={[commonStore.settings.dpiScaling.toString()]}
|
||||||
|
onOptionSelect={(_, data) => {
|
||||||
|
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) =>
|
||||||
|
<Option key={i} value={v.toString()}>{v + '%'}</Option>)
|
||||||
|
}
|
||||||
|
</Dropdown>
|
||||||
|
} />
|
||||||
|
}
|
||||||
<Labeled label={t('Dark Mode')} flex spaceBetween content={
|
<Labeled label={t('Dark Mode')} flex spaceBetween content={
|
||||||
<Switch checked={commonStore.settings.darkMode}
|
<Switch checked={commonStore.settings.darkMode}
|
||||||
onChange={(e, data) => {
|
onChange={(e, data) => {
|
||||||
|
@ -63,6 +63,7 @@ class CommonStore {
|
|||||||
giteeUpdatesSource: getUserLanguage() === 'zh',
|
giteeUpdatesSource: getUserLanguage() === 'zh',
|
||||||
cnMirror: getUserLanguage() === 'zh',
|
cnMirror: getUserLanguage() === 'zh',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
|
dpiScaling: 100,
|
||||||
customModelsPath: './models',
|
customModelsPath: './models',
|
||||||
customPythonPath: ''
|
customPythonPath: ''
|
||||||
};
|
};
|
||||||
|
2
frontend/wailsjs/go/backend_golang/App.d.ts
generated
vendored
2
frontend/wailsjs/go/backend_golang/App.d.ts
generated
vendored
@ -34,6 +34,8 @@ export function ReadFileInfo(arg1:string):Promise<backend_golang.FileInfo>;
|
|||||||
|
|
||||||
export function ReadJson(arg1:string):Promise<any>;
|
export function ReadJson(arg1:string):Promise<any>;
|
||||||
|
|
||||||
|
export function RestartApp():Promise<void>;
|
||||||
|
|
||||||
export function SaveJson(arg1:string,arg2:any):Promise<void>;
|
export function SaveJson(arg1:string,arg2:any):Promise<void>;
|
||||||
|
|
||||||
export function StartServer(arg1:string,arg2:number,arg3:string):Promise<string>;
|
export function StartServer(arg1:string,arg2:number,arg3:string):Promise<string>;
|
||||||
|
4
frontend/wailsjs/go/backend_golang/App.js
generated
4
frontend/wailsjs/go/backend_golang/App.js
generated
@ -66,6 +66,10 @@ export function ReadJson(arg1) {
|
|||||||
return window['go']['backend_golang']['App']['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) {
|
export function SaveJson(arg1, arg2) {
|
||||||
return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2);
|
return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2);
|
||||||
}
|
}
|
||||||
|
19
main.go
19
main.go
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/options/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed all:frontend/dist
|
//go:embed all:frontend/dist
|
||||||
@ -36,13 +37,29 @@ func main() {
|
|||||||
// Create an instance of the app structure
|
// Create an instance of the app structure
|
||||||
app := backend.NewApp()
|
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
|
// Create application with options
|
||||||
err := wails.Run(&options.App{
|
err = wails.Run(&options.App{
|
||||||
Title: "RWKV-Runner",
|
Title: "RWKV-Runner",
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
Height: 680,
|
Height: 680,
|
||||||
MinWidth: 375,
|
MinWidth: 375,
|
||||||
MinHeight: 640,
|
MinHeight: 640,
|
||||||
|
Windows: &windows.Options{
|
||||||
|
ZoomFactor: zoomFactor,
|
||||||
|
IsZoomControlEnabled: true,
|
||||||
|
},
|
||||||
AssetServer: &assetserver.Options{
|
AssetServer: &assetserver.Options{
|
||||||
Assets: assets,
|
Assets: assets,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user