search and/or read your saved and liked bluesky posts
wails go svelte sqlite desktop bluesky
at main 86 lines 2.2 kB view raw
1package main 2 3import ( 4 "context" 5 "os" 6 "path/filepath" 7 8 "github.com/wailsapp/wails/v2/pkg/runtime" 9) 10 11// App struct 12type App struct { 13 ctx context.Context 14 authService *AuthService 15 indexService *IndexService 16 searchService *SearchService 17 logService *LogService 18} 19 20// NewApp creates a new App application struct 21func NewApp() *App { 22 return &App{ 23 authService: NewAuthService(), 24 indexService: NewIndexService(), 25 searchService: NewSearchService(), 26 logService: NewLogService(), 27 } 28} 29 30// startup is called when the app starts. The context is saved so we can call 31// the runtime methods. 32func (a *App) startup(ctx context.Context) { 33 a.ctx = ctx 34 35 a.authService.setContext(ctx) 36 a.indexService.setContext(ctx) 37 a.logService.setContext(ctx) 38 39 // Initialize log service first 40 if err := a.logService.Initialize(); err != nil { 41 runtime.LogErrorf(a.ctx, "failed to initialize log service: %v", err) 42 } else { 43 InitLogger(a.logService) 44 LogInfo("Application started") 45 } 46 47 dbPath := getDBPath() 48 if err := Open(dbPath); err != nil { 49 LogErrorf("failed to open database: %v", err) 50 runtime.LogErrorf(a.ctx, "failed to open database: %v", err) 51 return 52 } 53 54 if a.authService.IsAuthenticated() { 55 if err := a.authService.RefreshSession(); err != nil { 56 LogWarnf("token refresh failed on startup: %v", err) 57 runtime.LogWarningf(a.ctx, "token refresh failed on startup: %v", err) 58 } 59 } 60} 61 62// shutdown is called when the app shuts down 63func (a *App) shutdown(ctx context.Context) { 64 if err := Close(); err != nil { 65 LogErrorf("failed to close database: %v", err) 66 runtime.LogErrorf(ctx, "failed to close database: %v", err) 67 } 68 if err := a.logService.Close(); err != nil { 69 runtime.LogErrorf(ctx, "failed to close log service: %v", err) 70 } 71} 72 73// getDBPath returns the path to the shared database 74func getDBPath() string { 75 if dir := os.Getenv("BSKY_BROWSER_DATA"); dir != "" { 76 return filepath.Join(dir, "bsky-browser.db") 77 } 78 79 configDir := os.Getenv("XDG_CONFIG_HOME") 80 if configDir == "" { 81 home, _ := os.UserHomeDir() 82 configDir = filepath.Join(home, ".config") 83 } 84 85 return filepath.Join(configDir, "bsky-browser", "bsky-browser.db") 86}