main.go RawHistoryFolder
1package main
2
3import (
4 "embed"
5 "fmt"
6 "os"
7 "runtime"
8
9 "github.com/bnema/dumber/internal/app/browser"
10 "github.com/bnema/dumber/internal/app/cli"
11 "github.com/bnema/dumber/internal/config"
12 "github.com/bnema/dumber/internal/logging"
13 "github.com/bnema/dumber/pkg/webkit"
14)
15
16//go:embed assets
17var assets embed.FS
18
19// Build information set via ldflags
20var (
21 version = "dev"
22 commit = "none"
23 buildDate = "unknown"
24)
25
26func main() {
27 // Setup basic crash handling early (before any potential crashes)
28 logging.SetupCrashHandler()
29
30 // Check if we should run the CLI mode
31 if shouldRunCLI() {
32 cli.Execute(version, commit, buildDate)
33 return
34 }
35
36 // Load config file first, then initialize logging with actual config
37 if err := config.Init(); err != nil {
38 // Use fmt.Printf for early errors before logging is initialized
39 fmt.Printf("Warning: failed to load config: %v, using defaults\n", err)
40 }
41 cfg := config.Get()
42
43 if err := logging.Init(
44 cfg.Logging.LogDir,
45 cfg.Logging.Level,
46 cfg.Logging.Format,
47 cfg.Logging.EnableFileLog,
48 cfg.Logging.MaxSize,
49 cfg.Logging.MaxBackups,
50 cfg.Logging.MaxAge,
51 cfg.Logging.Compress,
52 ); err != nil {
53 // Use fmt.Printf for early errors before logging is initialized
54 fmt.Printf("Warning: failed to initialize logging: %v\n", err)
55 }
56
57 logging.Info(fmt.Sprintf("Starting dumber browser v%s (commit: %s, built: %s)", version, commit, buildDate))
58
59 // GTK requires all UI calls to run on the main OS thread
60 if webkit.IsNativeAvailable() {
61 runtime.LockOSThread()
62 defer runtime.UnlockOSThread()
63 }
64
65 // Otherwise run the GUI browser
66 browser.Run(assets, version, commit, buildDate)
67}
68
69// shouldRunCLI determines if we should run in CLI mode based on arguments
70func shouldRunCLI() bool {
71 // No args = show CLI help with available commands
72 if len(os.Args) <= 1 {
73 return true
74 }
75
76 // Check for GUI-specific flags
77 for _, arg := range os.Args[1:] {
78 if arg == "--gui" || arg == "-g" {
79 return false // Explicit GUI mode
80 }
81 }
82
83 // Check for browse command - this should open GUI in direct navigation mode
84 if len(os.Args) >= 2 && os.Args[1] == "browse" {
85 return false // Browse command uses GUI mode but navigates directly
86 }
87
88 // Any other arguments mean CLI mode
89 return true
90}