Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
build
.env
dist
example-config
example-config
.fallow
10 changes: 4 additions & 6 deletions apps/finicky/src/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ var file *os.File
type windowWriter struct{}

func (w *windowWriter) Write(p []byte) (n int, err error) {
// Remove trailing newline if present
msg := string(p)
if len(msg) > 0 && msg[len(msg)-1] == '\n' {
msg = msg[:len(msg)-1]
payload := p
if len(payload) > 0 && payload[len(payload)-1] == '\n' {
payload = payload[:len(payload)-1]
}

window.SendMessageToWebView("log", msg)
window.BroadcastSSERaw("log", payload)
return len(p), nil
}

Expand Down
101 changes: 50 additions & 51 deletions apps/finicky/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ type URLInfo struct {
}

type ConfigInfo struct {
Handlers int16
Rewrites int16
DefaultBrowser string
ConfigPath string
Handlers int16 `json:"handlers"`
Rewrites int16 `json:"rewrites"`
DefaultBrowser string `json:"defaultBrowser"`
ConfigPath string `json:"configPath"`
}

var urlListener chan URLInfo = make(chan URLInfo)
Expand All @@ -62,6 +62,7 @@ var dryRun bool = false
var skipJSConfig bool = false
var updateInfo UpdateInfo
var configInfo *ConfigInfo
var lastConfigPayload map[string]interface{}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
var shouldKeepRunning bool = true

func main() {
Expand Down Expand Up @@ -132,9 +133,36 @@ func main() {

go checkForUpdates()

// Set up test URL handler
window.TestUrlHandler = func(url string) {
go TestURLInternal(url)
window.TestURLFunc = func(url string) (interface{}, error) {
slog.Debug("Testing URL", "url", url)
cfg, err := resolver.ResolveURL(vm, url, nil, false)
if err != nil {
return nil, err
}
return map[string]interface{}{
"url": cfg.URL,
"browser": cfg.Name,
"openInBackground": cfg.OpenInBackground,
"profile": cfg.Profile,
"args": cfg.Args,
}, nil
}

window.GetVersionFunc = version.GetCurrentVersion

window.GetConfigFunc = func() interface{} {
return lastConfigPayload
}

window.GetUpdateInfoFunc = func() interface{} {
if updateInfo.ReleaseInfo == nil && !updateInfo.UpdateCheckEnabled {
return nil
}
return buildUpdateInfoPayload()
}

if err := window.StartAPIServer(); err != nil {
slog.Error("Failed to start API server", "error", err)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

// Set up rules save handler.
Expand Down Expand Up @@ -299,32 +327,6 @@ func HandleURL(url *C.char, name *C.char, bundleId *C.char, path *C.char, window
}
}

//export TestURL
func TestURL(url *C.char) {
urlString := C.GoString(url)
TestURLInternal(urlString)
}

func TestURLInternal(urlString string) {
slog.Debug("Testing URL", "url", urlString)

config, err := resolver.ResolveURL(vm, urlString, nil, false)
if err != nil {
slog.Error("Failed to evaluate URL", "error", err)
window.SendMessageToWebView("testUrlResult", map[string]interface{}{
"error": err.Error(),
})
return
}

window.SendMessageToWebView("testUrlResult", map[string]interface{}{
"url": config.URL,
"browser": config.Name,
"openInBackground": config.OpenInBackground,
"profile": config.Profile,
"args": config.Args,
})
}

func handleFatalError(errorMessage string) {
slog.Error("Fatal error", "msg", errorMessage)
Expand All @@ -341,11 +343,6 @@ func QueueWindowDisplay(openWindow int32) {
func ShowConfigWindow() {
slog.Debug("Showing window")
window.ShowWindow()

// Send version information
currentVersion := version.GetCurrentVersion()
window.SendMessageToWebView("version", currentVersion)

}

//export WindowDidClose
Expand Down Expand Up @@ -383,22 +380,23 @@ func checkForUpdates() {
slog.Info("New version is available", "version", updateInfo.ReleaseInfo.LatestVersion)
}

window.BroadcastSSE("updateInfo", buildUpdateInfoPayload())
}

func buildUpdateInfoPayload() map[string]interface{} {
if updateInfo.ReleaseInfo != nil {
window.SendMessageToWebView("updateInfo", map[string]interface{}{
return map[string]interface{}{
"version": updateInfo.ReleaseInfo.LatestVersion,
"hasUpdate": updateInfo.ReleaseInfo.HasUpdate,
"updateCheckEnabled": updateInfo.UpdateCheckEnabled,
"downloadUrl": updateInfo.ReleaseInfo.DownloadUrl,
"releaseUrl": updateInfo.ReleaseInfo.ReleaseUrl,
})
} else {
window.SendMessageToWebView("updateInfo", map[string]interface{}{
"version": "",
"hasUpdate": false,
"updateCheckEnabled": updateInfo.UpdateCheckEnabled,
"downloadUrl": "",
"releaseUrl": "",
})
}
}
return map[string]interface{}{
"version": "", "hasUpdate": false,
"updateCheckEnabled": updateInfo.UpdateCheckEnabled,
"downloadUrl": "", "releaseUrl": "",
}
}

Expand Down Expand Up @@ -480,19 +478,20 @@ func setupVM(cfw *config.ConfigFileWatcher, namespace string) (*config.VM, error
opts := newVM.GetAllConfigOptions()
logRequests = opts.LogRequests

window.SendMessageToWebView("config", map[string]interface{}{
lastConfigPayload = map[string]interface{}{
"handlers": configInfo.Handlers,
"rewrites": configInfo.Rewrites,
"defaultBrowser": configInfo.DefaultBrowser,
"configPath": util.ShortenPath(configInfo.ConfigPath),
"isJSConfig": newVM.IsJSConfig(),
"hasJsConfig": newVM.IsJSConfig(),
"options": map[string]interface{}{
"keepRunning": opts.KeepRunning,
"hideIcon": opts.HideIcon,
"logRequests": opts.LogRequests,
"checkForUpdates": opts.CheckForUpdates,
},
})
}
window.BroadcastSSE("config", lastConfigPayload)

return newVM, nil
}
16 changes: 7 additions & 9 deletions apps/finicky/src/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ func (r *Rule) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON serializes match as a plain string when there is only one entry.
// MarshalJSON serializes match always as an array for consistency.
func (r Rule) MarshalJSON() ([]byte, error) {
type RuleAlias struct {
Match interface{} `json:"match"`
Browser string `json:"browser"`
Profile string `json:"profile,omitempty"`
Match []string `json:"match"`
Browser string `json:"browser"`
Profile string `json:"profile,omitempty"`
}
var match interface{}
if len(r.Match) == 1 {
match = r.Match[0]
} else {
match = r.Match
match := r.Match
if match == nil {
match = []string{}
}
return json.Marshal(RuleAlias{Match: match, Browser: r.Browser, Profile: r.Profile})
}
Expand Down
Loading
Loading