Skip to content

Commit dacf99c

Browse files
committed
feat: clean up app start page and css
1 parent ad69933 commit dacf99c

33 files changed

+1420
-706
lines changed

apps/finicky/src/config/configfiles.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ func (cfw *ConfigFileWatcher) StartWatching() error {
333333
// handleConfigFileEvent processes configuration file events and takes appropriate actions
334334
// Returns an error if the configuration file was removed
335335
func (cfw *ConfigFileWatcher) handleConfigFileEvent(event fsnotify.Event) error {
336+
// Ignore CHMOD-only events (permission changes) as they don't affect config content
337+
// Note: Some editors may send CHMOD along with WRITE, so we only ignore pure CHMOD
338+
if event.Op == fsnotify.Chmod {
339+
return nil
340+
}
341+
336342
if event.Has(fsnotify.Create) {
337343
slog.Debug("Configuration file created", "path", event.Name)
338344
}

apps/finicky/src/config/vm.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,6 @@ func (vm *VM) setup(embeddedFiles embed.FS, bundlePath string) error {
100100
return nil
101101
}
102102

103-
func (vm *VM) ShouldLogToFile(hasError bool) bool {
104-
105-
logRequests := vm.runtime.ToValue(hasError)
106-
107-
if !hasError {
108-
var err error
109-
logRequests, err = vm.runtime.RunString("finickyConfigAPI.getOption('logRequests', finalConfig)")
110-
if err != nil {
111-
slog.Warn("Failed to get logRequests option", "error", err)
112-
logRequests = vm.runtime.ToValue(true)
113-
}
114-
}
115-
116-
return logRequests.ToBoolean()
117-
}
118-
119103
func (vm *VM) GetConfigState() *ConfigState {
120104
state, err := vm.runtime.RunString("finickyConfigAPI.getConfigState(finalConfig)")
121105
if err != nil {

apps/finicky/src/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module finicky
22

3-
go 1.23.4
3+
go 1.24.0
44

55
require (
66
al.essio.dev/pkg/shellescape v1.6.0
77
github.com/Masterminds/semver v1.5.0
8-
github.com/dop251/goja v0.0.0-20250307175808-203961f822d6
8+
github.com/dop251/goja v0.0.0-20251008123653-cf18d89f3cf6
99
github.com/evanw/esbuild v0.24.2
1010
github.com/fsnotify/fsnotify v1.8.0
1111
github.com/jvatic/goja-babel v0.0.0-20250308121736-c08d87dbdc10
@@ -14,7 +14,7 @@ require (
1414
require (
1515
github.com/dlclark/regexp2 v1.11.5 // indirect
1616
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
17-
github.com/google/pprof v0.0.0-20250302191652-9094ed2288e7 // indirect
18-
golang.org/x/sys v0.13.0 // indirect
19-
golang.org/x/text v0.23.0 // indirect
17+
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d // indirect
18+
golang.org/x/sys v0.32.0 // indirect
19+
golang.org/x/text v0.30.0 // indirect
2020
)

apps/finicky/src/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZ
88
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
99
github.com/dop251/goja v0.0.0-20250307175808-203961f822d6 h1:G73yPVwEaihFs6WYKFFfSstwNY2vENyECvRnR0tye0g=
1010
github.com/dop251/goja v0.0.0-20250307175808-203961f822d6/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
11+
github.com/dop251/goja v0.0.0-20251008123653-cf18d89f3cf6 h1:6dE1TmjqkY6tehR4A67gDNhvDtuZ54ocu7ab4K9o540=
12+
github.com/dop251/goja v0.0.0-20251008123653-cf18d89f3cf6/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
1113
github.com/evanw/esbuild v0.24.2 h1:PQExybVBrjHjN6/JJiShRGIXh1hWVm6NepVnhZhrt0A=
1214
github.com/evanw/esbuild v0.24.2/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
1315
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
@@ -16,6 +18,8 @@ github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TC
1618
github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
1719
github.com/google/pprof v0.0.0-20250302191652-9094ed2288e7 h1:+J3r2e8+RsmN3vKfo75g0YSY61ms37qzPglu4p0sGro=
1820
github.com/google/pprof v0.0.0-20250302191652-9094ed2288e7/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
21+
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d h1:KJIErDwbSHjnp/SGzE5ed8Aol7JsKiI5X7yWKAtzhM0=
22+
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d/go.mod h1:I6V7YzU0XDpsHqbsyrghnFZLO1gwK6NPTNvmetQIk9U=
1923
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
2024
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
2125
github.com/jvatic/goja-babel v0.0.0-20250308121736-c08d87dbdc10 h1:vWIOMaPN3MJ9W2U+0sKPoouDoSdRP6TNEfmfmT8AmfA=
@@ -31,7 +35,11 @@ github.com/stvp/assert v0.0.0-20170616060220-4bc16443988b/go.mod h1:CC7OXV9IjEZR
3135
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3236
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
3337
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
39+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
3440
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
3541
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
42+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
43+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
3644
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
3745
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

apps/finicky/src/main.go

Lines changed: 90 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,18 @@ func main() {
126126

127127
go checkForUpdates()
128128

129+
// Set up test URL handler
130+
window.TestUrlHandler = func(url string) {
131+
go TestURLInternal(url)
132+
}
133+
129134
const oneDay = 24 * time.Hour
130135

131136
var showingWindow bool = false
132137
timeoutChan := time.After(1 * time.Second)
133138
updateChan := time.After(oneDay)
134139

135-
shouldKeepRunning = getKeepRunning()
140+
shouldKeepRunning = getConfigOption("keepRunning", true)
136141
if shouldKeepRunning {
137142
timeoutChan = nil
138143
}
@@ -186,12 +191,13 @@ func main() {
186191
case <-configChange:
187192
startTime := time.Now()
188193
var setupErr error
194+
slog.Debug("Config has changed")
189195
vm, setupErr = setupVM(cfw, embeddedFiles, namespace)
190196
if setupErr != nil {
191197
handleRuntimeError(setupErr)
192198
}
193199
slog.Debug("VM refresh complete", "duration", fmt.Sprintf("%.2fms", float64(time.Since(startTime).Microseconds())/1000))
194-
shouldKeepRunning = getKeepRunning()
200+
shouldKeepRunning = getConfigOption("keepRunning", true)
195201

196202
case shouldShowWindow := <-queueWindowOpen:
197203
if !showingWindow && shouldShowWindow {
@@ -219,8 +225,9 @@ func main() {
219225
}
220226
}()
221227

222-
showIcon := !getHideIcon()
223-
C.RunApp(C.bool(forceWindowOpen), C.bool(showIcon), C.bool(shouldKeepRunning))
228+
hideIcon := getConfigOption("hideIcon", false)
229+
230+
C.RunApp(C.bool(forceWindowOpen), C.bool(!hideIcon), C.bool(shouldKeepRunning))
224231
}
225232

226233
func handleRuntimeError(err error) {
@@ -229,32 +236,21 @@ func handleRuntimeError(err error) {
229236
go QueueWindowDisplay(1)
230237
}
231238

232-
func getKeepRunning() bool {
233-
if vm == nil {
234-
return false
235-
}
236-
237-
keepRunning, err := vm.Runtime().RunString("finickyConfigAPI.getOption('keepRunning', finalConfig, true)")
238-
if err != nil {
239-
return false
239+
func getConfigOption(optionName string, defaultValue bool) bool {
240+
if vm == nil || vm.Runtime() == nil {
241+
slog.Debug("VM not initialized, returning default for config option", "option", optionName, "default", defaultValue)
242+
return defaultValue
240243
}
241-
result := keepRunning.ToBoolean()
242244

243-
return result
244-
}
245-
246-
func getHideIcon() bool {
247-
if vm == nil {
248-
return false
249-
}
245+
script := fmt.Sprintf("finickyConfigAPI.getOption('%s', finalConfig, %t)", optionName, defaultValue)
246+
optionVal, err := vm.Runtime().RunString(script)
250247

251-
hideIcon, err := vm.Runtime().RunString("finickyConfigAPI.getOption('hideIcon', finalConfig, false)")
252248
if err != nil {
253-
return false
249+
slog.Error("Failed to get config option", "option", optionName, "error", err)
250+
return defaultValue
254251
}
255-
result := hideIcon.ToBoolean()
256252

257-
return result
253+
return optionVal.ToBoolean()
258254
}
259255

260256
//export HandleURL
@@ -289,16 +285,59 @@ func HandleURL(url *C.char, name *C.char, bundleId *C.char, path *C.char, openIn
289285
}
290286
}
291287

288+
//export TestURL
289+
func TestURL(url *C.char) {
290+
urlString := C.GoString(url)
291+
TestURLInternal(urlString)
292+
}
293+
294+
func TestURLInternal(urlString string) {
295+
slog.Debug("Testing URL", "url", urlString)
296+
297+
if vm == nil {
298+
slog.Error("VM not initialized")
299+
window.SendMessageToWebView("testUrlResult", map[string]interface{}{
300+
"error": "Configuration not loaded",
301+
})
302+
return
303+
}
304+
305+
browserConfig, err := evaluateURL(vm.Runtime(), urlString, nil)
306+
if err != nil {
307+
slog.Error("Failed to evaluate URL", "error", err)
308+
window.SendMessageToWebView("testUrlResult", map[string]interface{}{
309+
"error": err.Error(),
310+
})
311+
return
312+
}
313+
314+
if browserConfig == nil {
315+
window.SendMessageToWebView("testUrlResult", map[string]interface{}{
316+
"error": "No browser config returned",
317+
})
318+
return
319+
}
320+
321+
window.SendMessageToWebView("testUrlResult", map[string]interface{}{
322+
"url": browserConfig.URL,
323+
"browser": browserConfig.Name,
324+
"openInBackground": browserConfig.OpenInBackground,
325+
"profile": browserConfig.Profile,
326+
"args": browserConfig.Args,
327+
})
328+
}
329+
292330
func evaluateURL(vm *goja.Runtime, url string, opener *ProcessInfo) (*browser.BrowserConfig, error) {
293331
resolvedURL, err := shorturl.ResolveURL(url)
332+
vm.Set("originalUrl", url)
333+
294334
if err != nil {
295335
// Continue with original URL if resolution fails
296-
slog.Info("Failed to resolve short URL", "error", err)
297-
298-
} else {
299-
url = resolvedURL
336+
slog.Info("Failed to resolve short URL", "error", err, "url", url, "using", resolvedURL)
300337
}
301338

339+
url = resolvedURL
340+
302341
vm.Set("url", resolvedURL)
303342

304343
if opener != nil {
@@ -313,7 +352,7 @@ func evaluateURL(vm *goja.Runtime, url string, opener *ProcessInfo) (*browser.Br
313352
slog.Debug("No opener detected")
314353
}
315354

316-
openResult, err := vm.RunString("finickyConfigAPI.openUrl(url, opener, finalConfig)")
355+
openResult, err := vm.RunString("finickyConfigAPI.openUrl(url, opener, originalUrl, finalConfig)")
317356
if err != nil {
318357
return nil, fmt.Errorf("failed to evaluate URL in config: %v", err)
319358
}
@@ -427,11 +466,11 @@ func tearDown() {
427466
}
428467

429468
func setupVM(cfw *config.ConfigFileWatcher, embeddedFS embed.FS, namespace string) (*config.VM, error) {
430-
shouldLogToFile := true
469+
logRequests := true
431470
var err error
432471

433472
defer func() {
434-
err = logger.SetupFile(shouldLogToFile)
473+
err = logger.SetupFile(logRequests)
435474
if err != nil {
436475
slog.Warn("Failed to setup file logging", "error", err)
437476
}
@@ -444,14 +483,12 @@ func setupVM(cfw *config.ConfigFileWatcher, embeddedFS embed.FS, namespace strin
444483
}
445484

446485
if currentBundlePath != "" {
447-
vm, err := config.New(embeddedFS, namespace, currentBundlePath)
486+
vm, err = config.New(embeddedFS, namespace, currentBundlePath)
487+
448488
if err != nil {
449489
return nil, fmt.Errorf("failed to setup VM: %v", err)
450490
}
451491

452-
// Update logging preference based on VM if available
453-
shouldLogToFile = vm.ShouldLogToFile(false)
454-
455492
currentConfigState = vm.GetConfigState()
456493

457494
if currentConfigState != nil {
@@ -461,48 +498,26 @@ func setupVM(cfw *config.ConfigFileWatcher, embeddedFS embed.FS, namespace strin
461498
DefaultBrowser: currentConfigState.DefaultBrowser,
462499
ConfigPath: configPath,
463500
}
464-
465-
keepRunning := getKeepRunning()
466-
hideIcon := getHideIcon()
467-
468-
// Get logRequests option
469-
logRequests := false
470-
if logRequestsVal, err := vm.Runtime().RunString("finickyConfigAPI.getOption('logRequests', finalConfig, false)"); err == nil {
471-
logRequests = logRequestsVal.ToBoolean()
472-
}
473-
474-
// Get checkForUpdate option
475-
checkForUpdate := true
476-
if checkForUpdateVal, err := vm.Runtime().RunString("finickyConfigAPI.getOption('checkForUpdate', finalConfig, true)"); err == nil {
477-
checkForUpdate = checkForUpdateVal.ToBoolean()
478-
}
479-
480-
window.SendMessageToWebView("config", map[string]interface{}{
481-
"handlers": configInfo.Handlers,
482-
"rewrites": configInfo.Rewrites,
483-
"defaultBrowser": configInfo.DefaultBrowser,
484-
"configPath": configInfo.ConfigPath,
485-
"keepRunning": keepRunning,
486-
"hideIcon": hideIcon,
487-
"logRequests": logRequests,
488-
"checkForUpdate": checkForUpdate,
489-
})
490-
} else if configInfo != nil {
491-
keepRunning := getKeepRunning()
492-
hideIcon := getHideIcon()
493-
494-
window.SendMessageToWebView("config", map[string]interface{}{
495-
"handlers": 0,
496-
"rewrites": 0,
497-
"defaultBrowser": "",
498-
"configPath": configInfo.ConfigPath,
499-
"keepRunning": keepRunning,
500-
"hideIcon": hideIcon,
501-
"logRequests": false,
502-
"checkForUpdate": true,
503-
})
504501
}
505502

503+
keepRunning := getConfigOption("keepRunning", true)
504+
hideIcon := getConfigOption("hideIcon", false)
505+
logRequests = getConfigOption("logRequests", false)
506+
checkForUpdates := getConfigOption("checkForUpdates", true)
507+
508+
window.SendMessageToWebView("config", map[string]interface{}{
509+
"handlers": configInfo.Handlers,
510+
"rewrites": configInfo.Rewrites,
511+
"defaultBrowser": configInfo.DefaultBrowser,
512+
"configPath": configInfo.ConfigPath,
513+
"options": map[string]interface{}{
514+
"keepRunning": keepRunning,
515+
"hideIcon": hideIcon,
516+
"logRequests": logRequests,
517+
"checkForUpdates": checkForUpdates,
518+
},
519+
})
520+
506521
return vm, nil
507522
}
508523

0 commit comments

Comments
 (0)