perf: add minimum window size
perf: maximize the window automatically if screen size is lower than minimum window size #19
This commit is contained in:
parent
d61eb1323f
commit
72144bc996
|
@ -4,3 +4,5 @@ const DEFAULT_FONT_SIZE = 14
|
|||
const DEFAULT_ASIDE_WIDTH = 300
|
||||
const DEFAULT_WINDOW_WIDTH = 1024
|
||||
const DEFAULT_WINDOW_HEIGHT = 768
|
||||
const MIN_WINDOW_WIDTH = 960
|
||||
const MIN_WINDOW_HEIGHT = 640
|
||||
|
|
|
@ -113,7 +113,7 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) {
|
|||
}
|
||||
|
||||
func (p *preferencesService) SaveWindowSize(width, height int) {
|
||||
if width >= consts.DEFAULT_WINDOW_WIDTH && height >= consts.DEFAULT_WINDOW_HEIGHT {
|
||||
if width >= consts.MIN_WINDOW_WIDTH && height >= consts.MIN_WINDOW_HEIGHT {
|
||||
p.UpdatePreferences(map[string]any{
|
||||
"behavior.windowWidth": width,
|
||||
"behavior.windowHeight": height,
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
"tinyrdm/backend/consts"
|
||||
"tinyrdm/backend/types"
|
||||
)
|
||||
|
||||
|
@ -28,6 +29,18 @@ func System() *systemService {
|
|||
|
||||
func (s *systemService) Start(ctx context.Context) {
|
||||
s.ctx = ctx
|
||||
|
||||
// maximize the window if screen size is lower than the minimum window size
|
||||
if screen, err := runtime.ScreenGetAll(ctx); err == nil && len(screen) > 0 {
|
||||
for _, sc := range screen {
|
||||
if sc.IsCurrent {
|
||||
if sc.Size.Width < consts.MIN_WINDOW_WIDTH || sc.Size.Height < consts.MIN_WINDOW_HEIGHT {
|
||||
runtime.WindowMaximise(ctx)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SelectFile open file dialog to select a file
|
||||
|
|
|
@ -47,8 +47,8 @@ func (p *PreferencesStorage) GetPreferences() (ret types.Preferences) {
|
|||
|
||||
ret = p.getPreferences()
|
||||
ret.Behavior.AsideWidth = max(ret.Behavior.AsideWidth, consts.DEFAULT_ASIDE_WIDTH)
|
||||
ret.Behavior.WindowWidth = max(ret.Behavior.WindowWidth, consts.DEFAULT_WINDOW_WIDTH)
|
||||
ret.Behavior.WindowHeight = max(ret.Behavior.WindowHeight, consts.DEFAULT_WINDOW_HEIGHT)
|
||||
ret.Behavior.WindowWidth = max(ret.Behavior.WindowWidth, consts.MIN_WINDOW_WIDTH)
|
||||
ret.Behavior.WindowHeight = max(ret.Behavior.WindowHeight, consts.MIN_WINDOW_HEIGHT)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
4
main.go
4
main.go
|
@ -44,8 +44,8 @@ func main() {
|
|||
Title: "Tiny RDM",
|
||||
Width: windowWidth,
|
||||
Height: windowHeight,
|
||||
MinWidth: consts.DEFAULT_WINDOW_WIDTH,
|
||||
MinHeight: consts.DEFAULT_WINDOW_HEIGHT,
|
||||
MinWidth: consts.MIN_WINDOW_WIDTH,
|
||||
MinHeight: consts.MIN_WINDOW_HEIGHT,
|
||||
Frameless: runtime.GOOS != "darwin",
|
||||
Menu: appMenu,
|
||||
AssetServer: &assetserver.Options{
|
||||
|
|
Loading…
Reference in New Issue