UPDATE: Add self update

This commit is contained in:
2025-07-26 20:59:35 +07:00
parent 95f8ed357d
commit 461dfd93ba
28 changed files with 597 additions and 173 deletions

40
main.go
View File

@@ -13,11 +13,6 @@ import (
"github.com/wailsapp/wails/v3/pkg/application"
)
// Wails uses Go's `embed` package to embed the frontend files into the binary.
// Any files in the frontend/dist folder will be embedded into the binary and
// made available to the frontend.
// See https://pkg.go.dev/embed for more information.
//go:embed all:frontend/dist
var assets embed.FS
@@ -42,10 +37,8 @@ func extractFile(embedPath, outPath string) error {
return os.WriteFile(outPath, data, 0755)
}
// main function serves as the application's entry point. It initializes the application, creates a window,
// and starts a goroutine that emits a time-based event every second. It subsequently runs the application and
// logs any error that might occur.
func main() {
// Extract required files
for outPath, embedPath := range constant.RequiredFiles {
if !fileExists(outPath.String()) {
err := extractFile(embedPath, outPath.String())
@@ -54,11 +47,18 @@ func main() {
}
}
}
// Create a new Wails application by providing the necessary options.
// Variables 'Name' and 'Description' are for application metadata.
// 'Assets' configures the asset server with the 'FS' variable pointing to the frontend files.
// 'Bind' is a list of Go struct instances. The frontend has access to the methods of these instances.
// 'Mac' options tailor the application when running an macOS.
// Remove old executable
exePath, err := os.Executable()
if err == nil {
dir := filepath.Dir(exePath)
base := filepath.Base(exePath)
oldPath := filepath.Join(dir, "."+base+".old")
fmt.Println("Old executable path:", oldPath)
os.Remove(oldPath)
}
// Create application
app := application.New(application.Options{
Name: "firefly-launcher",
Description: "Firefly Launcher - Kain",
@@ -67,31 +67,24 @@ func main() {
application.NewService(&internal.LanguageService{}),
application.NewService(&internal.GitService{}),
application.NewService(&internal.HdiffzService{}),
application.NewService(&internal.AppService{}),
},
Assets: application.AssetOptions{
Handler: application.AssetFileServerFS(assets),
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
// Create a new window with the necessary options.
// 'Title' is the title of the window.
// 'Mac' options tailor the window when running on macOS.
// 'BackgroundColour' is the background colour of the window.
// 'URL' is the URL that will be loaded into the webview.
// Create window
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "Firefly Launcher - Kain",
Mac: application.MacWindow{
InvisibleTitleBarHeight: 50,
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(27, 38, 54),
Width: 1200,
Height: 600,
@@ -99,7 +92,8 @@ func main() {
DevToolsEnabled: true,
})
err := app.Run()
err = app.Run()
if err != nil {
log.Fatal(err)
}