chore(wailsv3): migrate Go backend from Wails v2 to v3

Minimal-structure migration to Wails v3.0.0-beta.20 (CLI-matching pin). Single App service preserved; no domain logic touched.

- main.go: wails.Run(options.App) -> application.New + RegisterService + Window.NewWithOptions. Window keeps title-with-version, 1024x768, RGBA background, Linux icon/translucency/GpuPolicyNever, ProgramName. SingleInstanceLock -> SingleInstanceOptions (same UniqueID); callback closes over the service variable set right after New.
- app.go: App holds *application.App instead of a context. startup(ctx) is gone; the version title moves into the window options via appTitle(). onSecondInstanceLaunch takes v3 SecondInstanceData (Args/WorkingDir) and uses Window.Current() Restore+Focus plus Event.Emit for launchArgs. ShowVersion uses Dialog.Info.
- AniList/MAL/Simkl *UserFunctions.go: runtime.BrowserOpenURL -> app.Browser.OpenURL (errors logged), runtime.MessageDialog -> app.Dialog.Info chains. OAuth callback servers, token flows, and key names unchanged.
- Secrets: 99designs/keyring replaced with zalando/go-keyring (what v3 itself depends on) under the same AniTrack service name, so existing stored tokens keep working. Per-file Set helpers kept; Open/Ready boilerplate deleted (zalando needs no handle).
- go.mod: v2 + 99designs dropped (stale v2 replace directive removed), v3 beta.20 + zalando v0.2.8 added.
This commit is contained in:
John O'Keefe
2026-09-13 17:10:09 -04:00
parent 2bf8d3887e
commit 850c1c6aee
13 changed files with 184 additions and 2191 deletions
+31 -67
View File
@@ -11,41 +11,17 @@ import (
"net/http"
"sync"
"github.com/99designs/keyring"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/zalando/go-keyring"
)
var simklJwt SimklJWT
var simklRing keyring.Keyring
func init() {
var err error
simklRing, err = keyring.Open(keyring.Config{
ServiceName: "AniTrack",
KeychainName: "AniTrack",
KeychainSynchronizable: false,
KeychainTrustApplication: true,
KeychainAccessibleWhenUnlocked: true,
})
if err != nil {
log.Printf("simkl: secure storage unavailable: %s", err)
}
}
func simklRingReady() bool {
if simklRing == nil {
log.Println("simkl: secure storage unavailable")
return false
}
return true
}
// simklKeyringService is the OS keyring service name all AniTrack secrets
// live under (same wallet the 99designs/keyring build used).
const simklKeyringService = "AniTrack"
func simklRingSet(key string, data []byte) error {
if !simklRingReady() {
return errors.New("simkl: secure storage unavailable")
}
if err := simklRing.Set(keyring.Item{Key: key, Data: data}); err != nil {
if err := keyring.Set(simklKeyringService, key, string(data)); err != nil {
log.Printf("simkl: save %s failed: %s", key, err)
return err
}
@@ -56,18 +32,15 @@ var simklCtxShutdown, simklCancel = context.WithCancel(context.Background())
func (a *App) CheckIfSimklLoggedIn() bool {
if (SimklJWT{} == simklJwt) {
if !simklRingReady() {
return false
}
tokenType, tokenTypeErr := simklRing.Get("SimklTokenType")
accessToken, accessTokenErr := simklRing.Get("SimklAccessToken")
scope, scopeErr := simklRing.Get("SimklScope")
if (tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil) || len(accessToken.Data) == 0 {
tokenType, tokenTypeErr := keyring.Get(simklKeyringService, "SimklTokenType")
accessToken, accessTokenErr := keyring.Get(simklKeyringService, "SimklAccessToken")
scope, scopeErr := keyring.Get(simklKeyringService, "SimklScope")
if (tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil) || len(accessToken) == 0 {
return false
} else {
simklJwt.TokenType = string(tokenType.Data)
simklJwt.AccessToken = string(accessToken.Data)
simklJwt.Scope = string(scope.Data)
simklJwt.TokenType = tokenType
simklJwt.AccessToken = accessToken
simklJwt.Scope = scope
return true
}
} else {
@@ -77,25 +50,24 @@ func (a *App) CheckIfSimklLoggedIn() bool {
func (a *App) SimklLogin() {
if !a.CheckIfSimklLoggedIn() {
if !simklRingReady() {
log.Println("simkl: cannot check login, secure storage unavailable")
return
}
tokenType, tokenTypeErr := simklRing.Get("SimklTokenType")
accessToken, accessTokenErr := simklRing.Get("SimklAccessToken")
scope, scopeErr := simklRing.Get("SimklScope")
if (tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil) || len(accessToken.Data) == 0 {
tokenType, tokenTypeErr := keyring.Get(simklKeyringService, "SimklTokenType")
accessToken, accessTokenErr := keyring.Get(simklKeyringService, "SimklAccessToken")
scope, scopeErr := keyring.Get(simklKeyringService, "SimklScope")
if (tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil) || len(accessToken) == 0 {
getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + Environment.SIMKL_CLIENT_ID + "&redirect_uri=" + Environment.SIMKL_CALLBACK_URI
runtime.BrowserOpenURL(*wailsContext, getSimklCodeUrl)
if err := a.app.Browser.OpenURL(getSimklCodeUrl); err != nil {
log.Printf("simkl: failed to open browser: %s", err)
return
}
serverDone := &sync.WaitGroup{}
serverDone.Add(1)
a.handleSimklCallback(serverDone)
serverDone.Wait()
} else {
simklJwt.TokenType = string(tokenType.Data)
simklJwt.AccessToken = string(accessToken.Data)
simklJwt.Scope = string(scope.Data)
simklJwt.TokenType = tokenType
simklJwt.AccessToken = accessToken
simklJwt.Scope = scope
}
}
}
@@ -117,17 +89,13 @@ func (a *App) handleSimklCallback(wg *sync.WaitGroup) {
_ = simklRingSet("SimklTokenType", []byte(simklJwt.TokenType))
_ = simklRingSet("SimklAccessToken", []byte(simklJwt.AccessToken))
_ = simklRingSet("SimklScope", []byte(simklJwt.Scope))
_, err := runtime.MessageDialog(*wailsContext, runtime.MessageDialogOptions{
Title: "Simkl Authorization",
Message: "It is now safe to close your browser tab",
})
if err != nil {
log.Println(err)
}
a.app.Dialog.Info().
SetTitle("Simkl Authorization").
SetMessage("It is now safe to close your browser tab").
Show()
fmt.Println("Shutting down...")
simklCancel()
err = srv.Shutdown(context.Background())
if err != nil {
if err := srv.Shutdown(context.Background()); err != nil {
log.Println("server.Shutdown:", err)
}
} else {
@@ -243,13 +211,9 @@ func (a *App) GetSimklLoggedInUser() SimklUser {
func (a *App) LogoutSimkl() string {
if (SimklJWT{} != simklJwt) {
if !simklRingReady() {
simklJwt = SimklJWT{}
return "Simkl Logged Out Successfully"
}
tokenTypeErr := simklRing.Remove("SimklTokenType")
accessTokenErr := simklRing.Remove("SimklAccessToken")
scopeErr := simklRing.Remove("SimklScope")
tokenTypeErr := keyring.Delete(simklKeyringService, "SimklTokenType")
accessTokenErr := keyring.Delete(simklKeyringService, "SimklAccessToken")
scopeErr := keyring.Delete(simklKeyringService, "SimklScope")
if tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil {
log.Printf("simkl: logout cleanup failed (type=%v access=%v scope=%v)", tokenTypeErr, accessTokenErr, scopeErr)