diff --git a/frontend/src/locales/de.yaml b/frontend/src/locales/de.yaml index 1fd3d8bc..ece90598 100644 --- a/frontend/src/locales/de.yaml +++ b/frontend/src/locales/de.yaml @@ -132,6 +132,7 @@ tags: sys:file:location:dropbox: Dropbox sys:file:location:onedrive: OneDrive sys:file:location:google-drive: Google Drive + sys:file:location:pcloud: pCloud sys:file:location:elsewhere: Sonstwo sys:file:btime-year: Erstelltes Jahr diff --git a/frontend/src/locales/en.yaml b/frontend/src/locales/en.yaml index 49a5a987..994ce21e 100644 --- a/frontend/src/locales/en.yaml +++ b/frontend/src/locales/en.yaml @@ -132,6 +132,7 @@ tags: sys:file:location:dropbox: Dropbox sys:file:location:onedrive: OneDrive sys:file:location:google-drive: Google Drive + sys:file:location:pcloud: pCloud sys:file:location:elsewhere: Elsewhere sys:file:btime-year: Creation year diff --git a/service/.gitignore b/service/.gitignore index 123676c5..688566a0 100644 --- a/service/.gitignore +++ b/service/.gitignore @@ -1,2 +1,3 @@ /internal/webservice/.frontend/ -/ablegram \ No newline at end of file +/Ablegram* +/*.log diff --git a/service/.idea/ablegram.iml b/service/.idea/ablegram.iml index 3e2d4951..ecf34dab 100644 --- a/service/.idea/ablegram.iml +++ b/service/.idea/ablegram.iml @@ -3,6 +3,8 @@ + + diff --git a/service/.idea/runConfigurations/Package_linux.xml b/service/.idea/runConfigurations/Package_linux.xml new file mode 100644 index 00000000..9182431d --- /dev/null +++ b/service/.idea/runConfigurations/Package_linux.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/service/.idea/runConfigurations/Package_windows.xml b/service/.idea/runConfigurations/Package_windows.xml new file mode 100644 index 00000000..483384d8 --- /dev/null +++ b/service/.idea/runConfigurations/Package_windows.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/service/.idea/runConfigurations/compile_windows_binary.xml b/service/.idea/runConfigurations/compile_windows_binary.xml deleted file mode 100755 index b599620f..00000000 --- a/service/.idea/runConfigurations/compile_windows_binary.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/service/.idea/runConfigurations/linux_build.xml b/service/.idea/runConfigurations/linux_build.xml index a817aa7f..faf6875f 100755 --- a/service/.idea/runConfigurations/linux_build.xml +++ b/service/.idea/runConfigurations/linux_build.xml @@ -1,5 +1,5 @@ - + diff --git a/service/.idea/runConfigurations/linux_build_gui_only.xml b/service/.idea/runConfigurations/linux_build_gui_only.xml index b2d493dc..cd3f62a2 100755 --- a/service/.idea/runConfigurations/linux_build_gui_only.xml +++ b/service/.idea/runConfigurations/linux_build_gui_only.xml @@ -1,5 +1,5 @@ - + diff --git a/service/.idea/runConfigurations/compile_linux_binary.xml b/service/.idea/runConfigurations/linux_build_webservice_only.xml old mode 100755 new mode 100644 similarity index 53% rename from service/.idea/runConfigurations/compile_linux_binary.xml rename to service/.idea/runConfigurations/linux_build_webservice_only.xml index 24cae534..972d3d1b --- a/service/.idea/runConfigurations/compile_linux_binary.xml +++ b/service/.idea/runConfigurations/linux_build_webservice_only.xml @@ -1,13 +1,11 @@ - + - + - - \ No newline at end of file diff --git a/service/.idea/runConfigurations/win_build.xml b/service/.idea/runConfigurations/win_build.xml index da8a2d86..4864b2bc 100755 --- a/service/.idea/runConfigurations/win_build.xml +++ b/service/.idea/runConfigurations/win_build.xml @@ -1,5 +1,5 @@ - + diff --git a/service/.idea/runConfigurations/win_build_gui_only.xml b/service/.idea/runConfigurations/win_build_gui_only.xml index 025edd68..028ffac3 100755 --- a/service/.idea/runConfigurations/win_build_gui_only.xml +++ b/service/.idea/runConfigurations/win_build_gui_only.xml @@ -1,5 +1,5 @@ - + diff --git a/service/.idea/runConfigurations/win_build_webservice_only.xml b/service/.idea/runConfigurations/win_build_webservice_only.xml index 84bac3a0..d3c9e81e 100755 --- a/service/.idea/runConfigurations/win_build_webservice_only.xml +++ b/service/.idea/runConfigurations/win_build_webservice_only.xml @@ -1,5 +1,5 @@ - + diff --git a/service/DEVELOPMENT.md b/service/DEVELOPMENT.md deleted file mode 100644 index 68b05f61..00000000 --- a/service/DEVELOPMENT.md +++ /dev/null @@ -1,16 +0,0 @@ -# Development - -## Setup - -Ensure you have the following things done: - -- Install the prerequisites from https://developer.fyne.io/started/ - -## Guides - -### Update bundled resources - -```shell -# see main go:generate headers -go generate -``` diff --git a/service/FyneApp.toml b/service/FyneApp.toml index 99849772..391f401d 100644 --- a/service/FyneApp.toml +++ b/service/FyneApp.toml @@ -1,8 +1,8 @@ Website = "https://www.ablegram.app" [Details] -Icon = "assets/icon.png" -Name = "Ablegram" -ID = "com.ablegram.app" -Version = "1.0.0" -Build = 1 + Icon = "assets/icon.png" + Name = "Ablegram" + ID = "com.ablegram.app" + Version = "1.0.0" + Build = 5 diff --git a/service/flags.go b/service/flags.go new file mode 100644 index 00000000..7ce6e7ba --- /dev/null +++ b/service/flags.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + "github.com/adrianrudnik/ablegram/internal/config" +) + +func parseFlags(c *config.Config) { + logLevel := flag.String("log-level", "info", "Set the log level [debug, info]") + logToFiles := flag.Bool("enable-logs", false, "Enable debug log writing to files") + logScannedFolders := flag.Bool("enable-scanned-log", false, "Enable scanned paths log file") + + noBrowserFlag := flag.Bool("no-browser", false, "Skip the automatic browser opening") + noGuiFlag := flag.Bool("no-gui", false, "Do no start the GUI.") + noWebserviceFlag := flag.Bool("no-webservice", false, "Do no start the webservice") + + flag.Parse() + + c.Log.Level = *logLevel + c.Log.ToFiles = *logToFiles + c.Log.ScannedFolders = *logScannedFolders + + c.Behaviour.BrowserAutostart = !*noBrowserFlag + c.Behaviour.ShowGui = !*noGuiFlag + c.Behaviour.WebserviceAutostart = !*noWebserviceFlag +} diff --git a/service/internal/collector/collector.go b/service/internal/collector/collector.go index 6721bb5c..f1a3c818 100644 --- a/service/internal/collector/collector.go +++ b/service/internal/collector/collector.go @@ -1,6 +1,7 @@ package collector import ( + "github.com/adrianrudnik/ablegram/internal/config" "github.com/adrianrudnik/ablegram/internal/pipeline" "github.com/adrianrudnik/ablegram/internal/pusher" "github.com/rs/zerolog" @@ -21,18 +22,17 @@ var excludePaths = []string{ } var excludeFolders = []string{ - ".git", - ".idea", + "node_modules", } type Collection struct { files []string } -func Collect(path string, filesChan chan<- *pipeline.FilesForProcessorMsg, broadcastChan chan<- interface{}) error { +func Collect(c *config.Config, path string, filesChan chan<- *pipeline.FilesForProcessorMsg, broadcastChan chan<- interface{}) error { allowedExtensions := []string{".als"} - err := findFilesByExtension(path, allowedExtensions, filesChan, broadcastChan) + err := findFilesByExtension(c, path, allowedExtensions, filesChan, broadcastChan) if err != nil { return err } @@ -44,27 +44,41 @@ func Collect(path string, filesChan chan<- *pipeline.FilesForProcessorMsg, broad return nil } -func findFilesByExtension(root string, extensions []string, filesChan chan<- *pipeline.FilesForProcessorMsg, broadcastChan chan<- interface{}) error { +func findFilesByExtension(c *config.Config, root string, extensions []string, filesChan chan<- *pipeline.FilesForProcessorMsg, broadcastChan chan<- interface{}) error { + + folders := make([]string, 0, 1000000) + err := filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error { + if e != nil { + Logger.Warn().Err(e).Str("path", s).Msg("Skipped folder due to error") + return nil + } + + // Exclude folders beginning with a dot + if c.Collector.ExcludeSystemFolders && d.IsDir() && strings.HasPrefix(d.Name(), ".") { + Logger.Debug().Str("path", s).Msg("Skipping dot folder") + return filepath.SkipDir + } + // Exclude paths by prefix - if d.IsDir() && slices.IndexFunc(excludePaths, func(s string) bool { + if c.Collector.ExcludeSystemFolders && d.IsDir() && slices.IndexFunc(excludePaths, func(s string) bool { return strings.HasPrefix(d.Name(), s) }) != -1 { - Logger.Info().Str("path", s).Msg("Skipping excluded path") + Logger.Debug().Str("path", s).Msg("Skipping excluded path") return filepath.SkipDir } // Exclude folders by name - if d.IsDir() && slices.IndexFunc(excludeFolders, func(s string) bool { + if c.Collector.ExcludeSystemFolders && d.IsDir() && slices.IndexFunc(excludeFolders, func(s string) bool { return s == filepath.Base(d.Name()) }) != -1 { - Logger.Info().Str("path", s).Msg("Skipping excluded folder") + Logger.Debug().Str("path", s).Msg("Skipping excluded folder") return filepath.SkipDir } - if e != nil { - Logger.Warn().Err(e).Str("path", s).Msg("Skipped folder due to error") - return nil + // Log at least the folders we are visiting + if d.IsDir() { + folders = append(folders, s) } for _, ext := range extensions { @@ -82,6 +96,15 @@ func findFilesByExtension(root string, extensions []string, filesChan chan<- *pi return nil }) + if c.Log.ScannedFolders { + scanLogPath := config.GetRelativeFilePath(".scanned-folders.log") + lines := strings.Join([]string(folders), "\n") + err := os.WriteFile(scanLogPath, []byte(lines), 0666) + if err != nil { + Logger.Warn().Err(err).Msg("Failed to write scanned folders to file") + } + } + if err != nil { return err } diff --git a/service/internal/collector/worker.go b/service/internal/collector/worker.go index d18aee1c..e40b6a77 100644 --- a/service/internal/collector/worker.go +++ b/service/internal/collector/worker.go @@ -1,6 +1,7 @@ package collector import ( + "github.com/adrianrudnik/ablegram/internal/config" "github.com/adrianrudnik/ablegram/internal/pipeline" "github.com/adrianrudnik/ablegram/internal/stats" ) @@ -22,35 +23,35 @@ func NewWorkerPool(workerCount int, filesChan chan<- *pipeline.FilesForProcessor } } -func (p *WorkerPool) Run(progress *stats.ProcessProgress, paths []string) { +func (wp *WorkerPool) Run(c *config.Config, p *stats.ProcessProgress) { Logger.Info(). - Int("count", p.workerCount). - Strs("paths", paths). + Int("count", wp.workerCount). + Strs("paths", c.Collector.SearchablePaths). Msg("Starting collector workers") // Spool up workers first - for i := 0; i < p.workerCount; i++ { - go p.doWork(progress) + for i := 0; i < wp.workerCount; i++ { + go wp.doWork(c, p) } // Pipe in paths next - for _, path := range paths { - p.inPathChan <- path + for _, path := range c.Collector.SearchablePaths { + wp.inPathChan <- path } } -func (p *WorkerPool) doWork(progress *stats.ProcessProgress) { +func (wp *WorkerPool) doWork(c *config.Config, p *stats.ProcessProgress) { for { select { - case path := <-p.inPathChan: - progress.Add() + case path := <-wp.inPathChan: + p.Add() - err := Collect(path, p.outFilesChan, p.pushChan) + err := Collect(c, path, wp.outFilesChan, wp.pushChan) if err != nil { Logger.Warn().Err(err).Str("path", path).Msg("Failed to collect files") } - progress.Done() + p.Done() } } } diff --git a/service/internal/config/config.go b/service/internal/config/config.go index cbefca14..ad8fd8f2 100644 --- a/service/internal/config/config.go +++ b/service/internal/config/config.go @@ -1,6 +1,7 @@ package config import ( + "errors" "github.com/rs/zerolog" "gopkg.in/yaml.v3" "os" @@ -11,14 +12,46 @@ import ( var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger() type Config struct { - PrimaryLanguage string `yaml:"primary_search_language"` - SearchablePaths []string `yaml:"searchable_paths"` + Log LogConfig `yaml:"log"` + Behaviour BehaviourConfig `yaml:"behaviour"` + Collector CollectorConfig `yaml:"collector"` +} + +type LogConfig struct { + Level string `yaml:"level"` + ToFiles bool `yaml:"to_files"` + ScannedFolders bool `yaml:"scanned_folders"` +} + +type BehaviourConfig struct { + WebserviceAutostart bool `yaml:"autostart_webservice"` + BrowserAutostart bool `yaml:"autostart_browser"` + ShowGui bool `yaml:"show_gui"` +} + +type CollectorConfig struct { + SearchablePaths []string `yaml:"searchable_paths"` + ExcludeSystemFolders bool `yaml:"exclude_system_folders"` } func newConfig() *Config { return &Config{ - PrimaryLanguage: "en", - SearchablePaths: make([]string, 0, 100), + Log: LogConfig{ + Level: "info", + ToFiles: false, + ScannedFolders: false, + }, + + Behaviour: BehaviourConfig{ + WebserviceAutostart: true, + BrowserAutostart: true, + ShowGui: true, + }, + + Collector: CollectorConfig{ + SearchablePaths: make([]string, 0, 100), + ExcludeSystemFolders: true, + }, } } @@ -32,12 +65,10 @@ func LoadWithDefaults(path string) *Config { Logger.Info().Err(err).Msg("Could not load config, falling back to defaults") - c.PrimaryLanguage = "" - // For the searchable paths, we prefer the users home directory as initial configuration homeDir, err := os.UserHomeDir() if err == nil { - c.SearchablePaths = append(c.SearchablePaths, homeDir) + c.Collector.SearchablePaths = append(c.Collector.SearchablePaths, homeDir) } return c @@ -50,12 +81,7 @@ func LoadWithDefaults(path string) *Config { // If path is an empty string, a config file with the name of the executable with an ".config.yaml" extension will be tried. func Load(path string) (*Config, error) { if path == "" { - p, err := getDefaultPath() - if err != nil { - return nil, err - } - - path = p + path = GetRelativeFilePath(".config.yaml") } b, err := os.ReadFile(path) @@ -87,16 +113,35 @@ func Save(c *Config, path string) error { return nil } -func getDefaultPath() (string, error) { - execAbsPath, err := os.Executable() +func GetRelativeFilePath(sub string) string { + absPath, err := func() (string, error) { + p, err := os.Executable() + if err != nil { + return "", err + } + + if strings.Contains(p, ".cache") && strings.Contains(p, "GoLand") { + Logger.Warn().Err(err).Msg("Detected developer IDE, falling back to working directory for for executable path") + return "", errors.New("developer") + } + + return p, err + }() + if err != nil { - return "", err + Logger.Warn().Err(err).Msg("Failed to find the path of the executable, falling back to working directory") + absPath, err = os.Getwd() + if err != nil { + Logger.Warn().Err(err).Msg("Failed to find working directory, falling back to simple ./") + absPath = "./Ablegram" + } else { + absPath += "/Ablegram" + } } // Remove a possible extension, like with win - base := strings.TrimSuffix(execAbsPath, filepath.Ext(execAbsPath)) - - base += ".config.yaml" + base := strings.TrimSuffix(absPath, filepath.Ext(absPath)) + base += sub - return base, nil + return base } diff --git a/service/internal/indexer/search.go b/service/internal/indexer/search.go index fcf6680f..21ac2e3d 100644 --- a/service/internal/indexer/search.go +++ b/service/internal/indexer/search.go @@ -60,7 +60,7 @@ func NewSearch() *Search { indexMapping.AddDocumentMapping("LiveSet", buildLiveSetMapping()) indexMapping.AddDocumentMapping("MidiTrack", buildMidiTrackMapping()) - Logger.Info().Msg("Indexes created") + Logger.Info().Msg("Index documents mapped") return &Search{ Index: index, diff --git a/service/internal/parser/ablv5parser/parse_live_set.go b/service/internal/parser/ablv5parser/parse_live_set.go index aae54bf5..217e5260 100644 --- a/service/internal/parser/ablv5parser/parse_live_set.go +++ b/service/internal/parser/ablv5parser/parse_live_set.go @@ -39,6 +39,8 @@ func ParseLiveSet(m *stats.Metrics, path string, data *ablv5schema.Ableton) *pip tags.AddSystemTag("file:location:onedrive") } else if strings.Contains(simplePath, "/google drive") { tags.AddSystemTag("file:location:google-drive") + } else if strings.Contains(simplePath, "/pCloudDrive") { + tags.AddSystemTag("file:location:pcloud") } else { tags.AddSystemTag("file:location:elsewhere") } diff --git a/service/internal/stats/logger.go b/service/internal/stats/logger.go new file mode 100644 index 00000000..31b5c07a --- /dev/null +++ b/service/internal/stats/logger.go @@ -0,0 +1,8 @@ +package stats + +import ( + "github.com/rs/zerolog" + "os" +) + +var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger() diff --git a/service/internal/stats/progress.go b/service/internal/stats/progress.go index de0fec33..e8b7f648 100644 --- a/service/internal/stats/progress.go +++ b/service/internal/stats/progress.go @@ -25,6 +25,11 @@ func NewProcessProgress(pushChan chan<- interface{}) *ProcessProgress { p.pushTrigger, _ = lo.NewDebounce(50*time.Millisecond, func() { p.pushChan <- pusher.NewProcessingStatusPush(p.progressCount.Load()) + Logger.Debug().Int64("routines", p.progressCount.Load()).Msg("Processing progress updated") + + if p.progressCount.Load() == 0 { + Logger.Info().Msg("Processing finished") + } }) return p diff --git a/service/internal/ui/logger.go b/service/internal/ui/logger.go new file mode 100644 index 00000000..1693c1b8 --- /dev/null +++ b/service/internal/ui/logger.go @@ -0,0 +1,8 @@ +package ui + +import ( + "github.com/rs/zerolog" + "os" +) + +var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger() diff --git a/service/internal/ui/opener.go b/service/internal/ui/opener.go new file mode 100644 index 00000000..3eb7406c --- /dev/null +++ b/service/internal/ui/opener.go @@ -0,0 +1,20 @@ +package ui + +import ( + "github.com/icza/gox/osx" +) + +func OpenFrontend() { + err := osx.OpenDefault("http://localhost:10000") + if err != nil { + Logger.Warn().Err(err).Msg("Could not open default browser") + } +} + +func OpenDefault(path string) { + err := osx.OpenDefault(path) + + if err != nil { + Logger.Warn().Err(err).Msg("Could not open default browser") + } +} diff --git a/service/internal/webservice/server.go b/service/internal/webservice/server.go index b0e942ee..01922f9b 100644 --- a/service/internal/webservice/server.go +++ b/service/internal/webservice/server.go @@ -3,13 +3,13 @@ package webservice import ( "embed" "github.com/adrianrudnik/ablegram/internal/indexer" + "github.com/adrianrudnik/ablegram/internal/ui" bleveHttp "github.com/blevesearch/bleve/v2/http" "github.com/gin-contrib/cors" "github.com/gin-contrib/logger" "github.com/gin-contrib/static" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" - "github.com/icza/gox/osx" "github.com/rs/zerolog" "net/http" "os" @@ -33,7 +33,7 @@ func Serve(indexer *indexer.Search, pushChan *PushChannel, bindAddr string) erro // Wrap route logging into correct format // @see https://gin-gonic.com/docs/examples/define-format-for-the-log-of-routes/ gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { - Logger.Info(). + Logger.Debug(). Str("method", httpMethod). Str("path", absolutePath). Str("handler", handlerName). @@ -119,12 +119,9 @@ func registerApiRoutes(rg *gin.RouterGroup) { return } - err := osx.OpenDefault(json.Path) - if err != nil { - Logger.Warn().Err(err).Msg("Unable to open given path") - } + ui.OpenDefault(json.Path) - c.JSON(200, gin.H{"status": "opened"}) + c.JSON(200, gin.H{"status": "ok"}) }) } diff --git a/service/main.go b/service/main.go index 31e454d1..402a08bc 100644 --- a/service/main.go +++ b/service/main.go @@ -1,7 +1,6 @@ package main import ( - "flag" "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/canvas" @@ -17,7 +16,7 @@ import ( "github.com/adrianrudnik/ablegram/internal/stats" "github.com/adrianrudnik/ablegram/internal/ui" "github.com/adrianrudnik/ablegram/internal/webservice" - "github.com/icza/gox/osx" + "github.com/gin-gonic/gin" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "image/color" @@ -29,21 +28,35 @@ import ( //go:generate fyne bundle -o bundled.go -append assets/logo.png func main() { - // Parse flags - noBrowserFlag := flag.Bool("no-browser", false, "Skip the automatic browser opening") - noGuiFlag := flag.Bool("no-gui", false, "Do no start the GUI") - noWebserviceFlag := flag.Bool("no-webservice", false, "Do no start the webservice") - - flag.Parse() + // Let's look for a configuration within one of the folders + config.Logger = log.With().Str("module", "config").Logger() + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + appConfig := config.LoadWithDefaults("") - log.Info(). - Bool("no-browser", !*noBrowserFlag). - Bool("no-gui", !*noGuiFlag). - Bool("no-webservice", !*noWebserviceFlag). - Msg("Parsed executable flags") + parseFlags(appConfig) // Set up logging - log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + switch appConfig.Log.Level { + case "debug": + gin.SetMode(gin.DebugMode) + zerolog.SetGlobalLevel(zerolog.DebugLevel) + break + default: + gin.SetMode(gin.ReleaseMode) + zerolog.SetGlobalLevel(zerolog.InfoLevel) + } + + if appConfig.Log.ToFiles { + logPath := config.GetRelativeFilePath(".runtime.log") + logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Error().Err(err).Msg("Could not open log file") + } else { + defer logFile.Close() + log.Logger = zerolog.New(logFile).With().Timestamp().Logger() + } + } + log.Info().Msg("App starting") // Create some channel based pipelines to pass around the different workloads @@ -53,17 +66,17 @@ func main() { // ProcessProgress is responsible in holding the current progress and // notifying the frontend about it + stats.Logger = log.With().Str("module", "stats").Logger() progress := stats.NewProcessProgress(pusherPipeline.Chan) // Kick of the webservice go func() { - if *noWebserviceFlag { + if !appConfig.Behaviour.WebserviceAutostart { return } - // Let's look for a configuration within one of the folders - config.Logger = log.With().Str("module", "config").Logger() - appConfig := config.LoadWithDefaults("") + // Set the logger for the UI helper + ui.Logger = log.With().Str("module", "ui").Logger() // Metrics is responsible in keeping and communicating key metrics for the frontend appMetrics := stats.NewMetrics(pusherPipeline.Chan) @@ -76,7 +89,7 @@ func main() { // Collector is responsible for finding files that could be parsed collector.Logger = log.With().Str("module", "collector").Logger() collectorWorkers := collector.NewWorkerPool(10, filesPipeline.Chan, pusherPipeline.Chan) - go collectorWorkers.Run(progress, appConfig.SearchablePaths) + go collectorWorkers.Run(appConfig, progress) // Parser is responsible for parsing the files into results for the indexerWorker parser.Logger = log.With().Str("module", "parser").Logger() @@ -91,18 +104,18 @@ func main() { // Try to open the default browser on the given OS go func() { - if *noBrowserFlag { + if !appConfig.Behaviour.BrowserAutostart { return } time.Sleep(50 * time.Millisecond) - openBrowser() + ui.OpenFrontend() }() webservice.Serve(search, appPusher, ":10000") }() - if *noGuiFlag { + if !appConfig.Behaviour.ShowGui { select {} } else { // Define a clean theme @@ -118,7 +131,7 @@ func main() { statusTxt := canvas.NewText("The service is processing files...", color.White) quitBtn := widget.NewButton("Shut down service", func() { a.Quit() }) - startBtn := widget.NewButton("Open results in browser", func() { openBrowser() }) + startBtn := widget.NewButton("Open results in browser", func() { ui.OpenFrontend() }) progressBar := widget.NewProgressBarInfinite() uiUpdater := ui.NewUiUpdater(statusTxt, progressBar) @@ -139,10 +152,3 @@ func main() { time.Sleep(100 * time.Millisecond) } } - -func openBrowser() { - err := osx.OpenDefault("http://localhost:10000") - if err != nil { - log.Warn().Err(err).Msg("Could not open default browser") - } -}