Make desktop.Start run on main thread (#2475)

This commit is contained in:
WithoutPants 2022-04-05 14:58:08 +10:00 committed by GitHub
parent 61d9f57ce9
commit 230d8f6028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 12 deletions

View File

@ -5,12 +5,13 @@ import (
"fmt"
"os"
"os/signal"
"runtime/pprof"
"syscall"
"github.com/apenwarr/fixconsole"
"github.com/stashapp/stash/internal/api"
"github.com/stashapp/stash/internal/desktop"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/ui"
_ "github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
@ -28,18 +29,21 @@ func main() {
manager.Initialize()
api.Start()
go handleSignals()
desktop.Start(manager.GetInstance(), &manager.FaviconProvider{UIBox: ui.UIBox})
blockForever()
// stop any profiling at exit
pprof.StopCPUProfile()
manager.GetInstance().Shutdown(0)
}
func blockForever() {
func handleSignals() {
// handle signals
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
<-signals
manager.GetInstance().Shutdown(0)
}
func blockForever() {
select {}
}

View File

@ -26,6 +26,7 @@ type FaviconProvider interface {
}
// Start starts the desktop icon process. It blocks until the process exits.
// MUST be run on the main goroutine or will have no effect on macOS
func Start(shutdownHandler ShutdownHandler, faviconProvider FaviconProvider) {
if IsDesktop() {
c := config.GetInstance()

View File

@ -8,13 +8,13 @@ import (
const faviconDir = "v2.5/build/"
type FaviconProvider struct {
uiBox embed.FS
UIBox embed.FS
}
func (p *FaviconProvider) GetFavicon() []byte {
if runtime.GOOS == "windows" {
faviconPath := faviconDir + "favicon.ico"
ret, _ := p.uiBox.ReadFile(faviconPath)
ret, _ := p.UIBox.ReadFile(faviconPath)
return ret
}
@ -23,6 +23,6 @@ func (p *FaviconProvider) GetFavicon() []byte {
func (p *FaviconProvider) GetFaviconPng() []byte {
faviconPath := faviconDir + "favicon.png"
ret, _ := p.uiBox.ReadFile(faviconPath)
ret, _ := p.UIBox.ReadFile(faviconPath)
return ret
}

View File

@ -255,7 +255,6 @@ func (s *singleton) PostInit(ctx context.Context) error {
s.ScraperCache = instance.initScraperCache()
writeStashIcon()
go desktop.Start(instance, &FaviconProvider{uiBox: ui.UIBox})
// clear the downloads and tmp directories
// #1021 - only clear these directories if the generated folder is non-empty
@ -289,7 +288,7 @@ func (s *singleton) PostInit(ctx context.Context) error {
func writeStashIcon() {
p := FaviconProvider{
uiBox: ui.UIBox,
UIBox: ui.UIBox,
}
iconPath := filepath.Join(instance.Config.GetConfigPath(), "icon.png")
@ -484,6 +483,9 @@ func (s *singleton) GetSystemStatus() *models.SystemStatus {
// Shutdown gracefully stops the manager
func (s *singleton) Shutdown(code int) {
// stop any profiling at exit
pprof.StopCPUProfile()
// TODO: Each part of the manager needs to gracefully stop at some point
// for now, we just close the database.
err := database.Close()
@ -493,5 +495,6 @@ func (s *singleton) Shutdown(code int) {
os.Exit(1)
}
}
os.Exit(code)
}