-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.go
More file actions
89 lines (77 loc) · 2.9 KB
/
Copy pathstartup.go
File metadata and controls
89 lines (77 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Startup assembly loads persisted inputs once, constructs the complete
// viewer, and only then restores geometry. Runtime side effects remain in
// run.go and start after this sequence returns.
package ui
import (
"fyne.io/fyne/v2"
"github.com/frathe/picfetch/internal/filescan"
"github.com/frathe/picfetch/internal/imaging"
"github.com/frathe/picfetch/internal/preferences"
"github.com/frathe/picfetch/internal/session"
)
// startupState is the persisted input snapshot consumed by buildViewer and
// geometry restoration.
type startupState struct {
savedSession []fyne.URI
prefs preferences.State
}
// loadStartupState reads persistence and fills only preference defaults that
// have no distinct zero-value meaning.
func loadStartupState(application fyne.App) startupState {
return startupState{
savedSession: session.Load(application),
prefs: normalizePreferenceDefaults(preferences.Load(application)),
}
}
// buildStartupViewer is the shared load, construct, then restore entry point.
// It leaves noPollerStop installed for startViewerRuntime to replace.
func buildStartupViewer(application fyne.App) (*viewer, fyne.Window) {
startup := loadStartupState(application)
view, window := buildViewer(application, startup)
restoreStartupGeometry(view, window, startup)
return view, window
}
// normalizePreferenceDefaults fills only caps. The other zero values remain
// meaningful: an unset slideshow interval is chosen on first use, geometry
// flags distinguish unsaved positions, and zero secondary geometry uses each
// window's built-in placement and size.
func normalizePreferenceDefaults(prefs preferences.State) preferences.State {
if prefs.MaxScanFiles <= 0 {
prefs.MaxScanFiles = filescan.DefaultMax
}
if prefs.MaxWindowWidth <= 0 {
prefs.MaxWindowWidth = defaultMaxWindowWidth
}
if prefs.MaxWindowHeight <= 0 {
prefs.MaxWindowHeight = defaultMaxWindowHeight
}
if prefs.MaxImageCacheMB <= 0 {
prefs.MaxImageCacheMB = defaultMaxImageCacheMB
}
if prefs.MaxThumbCacheMB <= 0 {
prefs.MaxThumbCacheMB = defaultMaxThumbCacheMB
}
if prefs.MaxFileSizeMB <= 0 {
prefs.MaxFileSizeMB = defaultMaxFileSizeMB
}
if !prefs.DuplicateDistanceSet {
prefs.DuplicateDistance = imaging.DuplicateMaxDistance
}
return prefs
}
// restoreStartupGeometry runs after feature construction so the settings and
// EXIF windows exist before their remembered geometry is applied.
func restoreStartupGeometry(view *viewer, window fyne.Window, startup startupState) {
prefs := startup.prefs
view.settingsWin.RestoreGeometry(widgetGeometry(prefs.SettingsWindow))
view.exif.RestoreGeometry(widgetGeometry(prefs.ExifWindow))
initialSize := fyne.NewSize(startW, startH)
if prefs.WindowSize.Width > 0 && prefs.WindowSize.Height > 0 {
initialSize = prefs.WindowSize
}
window.Resize(initialSize)
if prefs.WindowPositionSet {
view.winPos.Store(prefs.WindowPosX, prefs.WindowPosY)
view.winPos.Restore(window)
}
}