node build fixed
This commit is contained in:
112
seanime-2.9.10/internal/server/server.go
Normal file
112
seanime-2.9.10/internal/server/server.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
golog "log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"seanime/internal/core"
|
||||
"seanime/internal/cron"
|
||||
"seanime/internal/handlers"
|
||||
"seanime/internal/updater"
|
||||
"seanime/internal/util"
|
||||
"seanime/internal/util/crashlog"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func startApp(embeddedLogo []byte) (*core.App, core.SeanimeFlags, *updater.SelfUpdater) {
|
||||
// Print the header
|
||||
core.PrintHeader()
|
||||
|
||||
// Get the flags
|
||||
flags := core.GetSeanimeFlags()
|
||||
|
||||
selfupdater := updater.NewSelfUpdater()
|
||||
|
||||
// Create the app instance
|
||||
app := core.NewApp(&core.ConfigOptions{
|
||||
DataDir: flags.DataDir,
|
||||
EmbeddedLogo: embeddedLogo,
|
||||
IsDesktopSidecar: flags.IsDesktopSidecar,
|
||||
}, selfupdater)
|
||||
|
||||
// Create log file
|
||||
logFilePath := filepath.Join(app.Config.Logs.Dir, fmt.Sprintf("seanime-%s.log", time.Now().Format("2006-01-02_15-04-05")))
|
||||
// Open the log file
|
||||
logFile, _ := os.OpenFile(
|
||||
logFilePath,
|
||||
os.O_APPEND|os.O_CREATE|os.O_WRONLY,
|
||||
0664,
|
||||
)
|
||||
|
||||
log.Logger = *app.Logger
|
||||
golog.SetOutput(app.Logger)
|
||||
util.SetupLoggerSignalHandling(logFile)
|
||||
crashlog.GlobalCrashLogger.SetLogDir(app.Config.Logs.Dir)
|
||||
|
||||
app.OnFlushLogs = func() {
|
||||
util.WriteGlobalLogBufferToFile(logFile)
|
||||
logFile.Sync()
|
||||
}
|
||||
|
||||
if !flags.Update {
|
||||
go func() {
|
||||
for {
|
||||
util.WriteGlobalLogBufferToFile(logFile)
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return app, flags, selfupdater
|
||||
}
|
||||
|
||||
func startAppLoop(webFS *embed.FS, app *core.App, flags core.SeanimeFlags, selfupdater *updater.SelfUpdater) {
|
||||
updateMode := flags.Update
|
||||
|
||||
appLoop:
|
||||
for {
|
||||
switch updateMode {
|
||||
case true:
|
||||
|
||||
log.Log().Msg("Running in update mode")
|
||||
|
||||
// Print the header
|
||||
core.PrintHeader()
|
||||
|
||||
// Run the self-updater
|
||||
err := selfupdater.Run()
|
||||
if err != nil {
|
||||
}
|
||||
|
||||
log.Log().Msg("Shutting down in 10 seconds...")
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
break appLoop
|
||||
case false:
|
||||
|
||||
// Create the echo app instance
|
||||
echoApp := core.NewEchoApp(app, webFS)
|
||||
|
||||
// Initialize the routes
|
||||
handlers.InitRoutes(app, echoApp)
|
||||
|
||||
// Run the server
|
||||
core.RunEchoServer(app, echoApp)
|
||||
|
||||
// Run the jobs in the background
|
||||
cron.RunJobs(app)
|
||||
|
||||
select {
|
||||
case <-selfupdater.Started():
|
||||
app.Cleanup()
|
||||
updateMode = true
|
||||
break
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
14
seanime-2.9.10/internal/server/server_unix.go
Normal file
14
seanime-2.9.10/internal/server/server_unix.go
Normal file
@@ -0,0 +1,14 @@
|
||||
//go:build (linux || darwin) && !windows
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
)
|
||||
|
||||
func StartServer(webFS embed.FS, embeddedLogo []byte) {
|
||||
|
||||
app, flags, selfupdater := startApp(embeddedLogo)
|
||||
|
||||
startAppLoop(&webFS, app, flags, selfupdater)
|
||||
}
|
||||
98
seanime-2.9.10/internal/server/server_windows.go
Normal file
98
seanime-2.9.10/internal/server/server_windows.go
Normal file
@@ -0,0 +1,98 @@
|
||||
//go:build windows && !nosystray
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"fyne.io/systray"
|
||||
"github.com/cli/browser"
|
||||
"github.com/gonutz/w32/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
"seanime/internal/constants"
|
||||
"seanime/internal/core"
|
||||
"seanime/internal/handlers"
|
||||
"seanime/internal/icon"
|
||||
"seanime/internal/updater"
|
||||
)
|
||||
|
||||
func StartServer(webFS embed.FS, embeddedLogo []byte) {
|
||||
onExit := func() {}
|
||||
hideConsole()
|
||||
|
||||
app, flags, selfupdater := startApp(embeddedLogo)
|
||||
|
||||
// Blocks until systray.Quit() is called
|
||||
systray.Run(onReady(&webFS, app, flags, selfupdater), onExit)
|
||||
}
|
||||
|
||||
func addQuitItem() {
|
||||
systray.AddSeparator()
|
||||
mQuit := systray.AddMenuItem("Quit Seanime", "Quit the whole app")
|
||||
mQuit.Enable()
|
||||
go func() {
|
||||
<-mQuit.ClickedCh
|
||||
log.Trace().Msg("systray: Quitting system tray")
|
||||
systray.Quit()
|
||||
log.Trace().Msg("systray: Quit system tray")
|
||||
}()
|
||||
}
|
||||
|
||||
func onReady(webFS *embed.FS, app *core.App, flags core.SeanimeFlags, selfupdater *updater.SelfUpdater) func() {
|
||||
return func() {
|
||||
systray.SetTemplateIcon(icon.Data, icon.Data)
|
||||
systray.SetTitle(fmt.Sprintf("Seanime v%s", constants.Version))
|
||||
systray.SetTooltip(fmt.Sprintf("Seanime v%s", constants.Version))
|
||||
log.Trace().Msg("systray: App is ready")
|
||||
|
||||
// Menu items
|
||||
systray.AddMenuItem("Seanime v"+constants.Version, "Seanime version")
|
||||
mWeb := systray.AddMenuItem(app.Config.GetServerURI("127.0.0.1"), "Open web interface")
|
||||
mOpenLibrary := systray.AddMenuItem("Open Anime Library", "Open anime library")
|
||||
mOpenDataDir := systray.AddMenuItem("Open Data Directory", "Open data directory")
|
||||
mOpenLogsDir := systray.AddMenuItem("Open Log Directory", "Open log directory")
|
||||
|
||||
addQuitItem()
|
||||
|
||||
go func() {
|
||||
// Close the systray when the app exits
|
||||
defer systray.Quit()
|
||||
|
||||
startAppLoop(webFS, app, flags, selfupdater)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-mWeb.ClickedCh:
|
||||
_ = browser.OpenURL(app.Config.GetServerURI("127.0.0.1"))
|
||||
case <-mOpenLibrary.ClickedCh:
|
||||
handlers.OpenDirInExplorer(app.LibraryDir)
|
||||
case <-mOpenDataDir.ClickedCh:
|
||||
handlers.OpenDirInExplorer(app.Config.Data.AppDataDir)
|
||||
case <-mOpenLogsDir.ClickedCh:
|
||||
handlers.OpenDirInExplorer(app.Config.Logs.Dir)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// hideConsole will hide the terminal window if the app was not started with the -H=windowsgui flag.
|
||||
// NOTE: This will only minimize the terminal window on Windows 11 if the 'default terminal app' is set to 'Windows Terminal' or 'Let Windows choose' instead of 'Windows Console Host'
|
||||
func hideConsole() {
|
||||
console := w32.GetConsoleWindow()
|
||||
if console == 0 {
|
||||
return // no console attached
|
||||
}
|
||||
// If this application is the process that created the console window, then
|
||||
// this program was not compiled with the -H=windowsgui flag and on start-up
|
||||
// it created a console along with the main application window. In this case
|
||||
// hide the console window.
|
||||
// See
|
||||
// http://stackoverflow.com/questions/9009333/how-to-check-if-the-program-is-run-from-a-console
|
||||
_, consoleProcID := w32.GetWindowThreadProcessId(console)
|
||||
if w32.GetCurrentProcessId() == consoleProcID {
|
||||
w32.ShowWindow(console, w32.SW_HIDE)
|
||||
}
|
||||
}
|
||||
14
seanime-2.9.10/internal/server/server_windows_nosystray.go
Normal file
14
seanime-2.9.10/internal/server/server_windows_nosystray.go
Normal file
@@ -0,0 +1,14 @@
|
||||
//go:build windows && nosystray
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
)
|
||||
|
||||
func StartServer(webFS embed.FS, embeddedLogo []byte) {
|
||||
|
||||
app, flags, selfupdater := startApp(embeddedLogo)
|
||||
|
||||
startAppLoop(&webFS, app, flags, selfupdater)
|
||||
}
|
||||
Reference in New Issue
Block a user