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
+38 -74
View File
@@ -17,41 +17,17 @@ import (
"sync"
"time"
"github.com/99designs/keyring"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/zalando/go-keyring"
)
var myAnimeListJwt MyAnimeListJWT
var myAnimeListRing keyring.Keyring
func init() {
var err error
myAnimeListRing, err = keyring.Open(keyring.Config{
ServiceName: "AniTrack",
KeychainName: "AniTrack",
KeychainSynchronizable: false,
KeychainTrustApplication: true,
KeychainAccessibleWhenUnlocked: true,
})
if err != nil {
log.Printf("mal: secure storage unavailable: %s", err)
}
}
func malRingReady() bool {
if myAnimeListRing == nil {
log.Println("mal: secure storage unavailable")
return false
}
return true
}
// malKeyringService is the OS keyring service name all AniTrack secrets
// live under (same wallet the 99designs/keyring build used).
const malKeyringService = "AniTrack"
func malRingSet(key string, data []byte) error {
if !malRingReady() {
return errors.New("mal: secure storage unavailable")
}
if err := myAnimeListRing.Set(keyring.Item{Key: key, Data: data}); err != nil {
if err := keyring.Set(malKeyringService, key, string(data)); err != nil {
log.Printf("mal: save %s failed: %s", key, err)
return err
}
@@ -99,25 +75,22 @@ func (v *CodeVerifier) CodeChallengeS256() string {
func (a *App) CheckIfMyAnimeListLoggedIn() bool {
if (MyAnimeListJWT{} == myAnimeListJwt) {
if !malRingReady() {
return false
}
tokenType, tokenErr := myAnimeListRing.Get("MyAnimeListTokenType")
expiresIn, expiresInErr := myAnimeListRing.Get("MyAnimeListExpiresIn")
accessToken, accessTokenErr := myAnimeListRing.Get("MyAnimeListAccessToken")
refreshToken, refreshTokenErr := myAnimeListRing.Get("MyAnimeListRefreshToken")
if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken.Data) == 0 {
tokenType, tokenErr := keyring.Get(malKeyringService, "MyAnimeListTokenType")
expiresIn, expiresInErr := keyring.Get(malKeyringService, "MyAnimeListExpiresIn")
accessToken, accessTokenErr := keyring.Get(malKeyringService, "MyAnimeListAccessToken")
refreshToken, refreshTokenErr := keyring.Get(malKeyringService, "MyAnimeListRefreshToken")
if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken) == 0 {
return false
} else {
var expiresInConvertErr error
myAnimeListJwt.TokenType = string(tokenType.Data)
myAnimeListJwt.ExpiresIn, expiresInConvertErr = strconv.Atoi(string(expiresIn.Data))
myAnimeListJwt.TokenType = tokenType
myAnimeListJwt.ExpiresIn, expiresInConvertErr = strconv.Atoi(expiresIn)
if expiresInConvertErr != nil {
log.Printf("mal: invalid expiresIn %q: %s", string(expiresIn.Data), expiresInConvertErr)
log.Printf("mal: invalid expiresIn %q: %s", expiresIn, expiresInConvertErr)
return false
}
myAnimeListJwt.AccessToken = string(accessToken.Data)
myAnimeListJwt.RefreshToken = string(refreshToken.Data)
myAnimeListJwt.AccessToken = accessToken
myAnimeListJwt.RefreshToken = refreshToken
return true
}
} else {
@@ -128,31 +101,30 @@ func (a *App) CheckIfMyAnimeListLoggedIn() bool {
func (a *App) MyAnimeListLogin() {
if !a.CheckIfMyAnimeListLoggedIn() {
fmt.Println("check logged in function failed")
if !malRingReady() {
log.Println("mal: cannot check login, secure storage unavailable")
return
}
tokenType, tokenErr := myAnimeListRing.Get("MyAnimeListTokenType")
expiresIn, expiresInErr := myAnimeListRing.Get("MyAnimeListExpiresIn")
accessToken, accessTokenErr := myAnimeListRing.Get("MyAnimeListAccessToken")
refreshToken, refreshTokenErr := myAnimeListRing.Get("MyAnimeListRefreshToken")
if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken.Data) == 0 {
tokenType, tokenErr := keyring.Get(malKeyringService, "MyAnimeListTokenType")
expiresIn, expiresInErr := keyring.Get(malKeyringService, "MyAnimeListExpiresIn")
accessToken, accessTokenErr := keyring.Get(malKeyringService, "MyAnimeListAccessToken")
refreshToken, refreshTokenErr := keyring.Get(malKeyringService, "MyAnimeListRefreshToken")
if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken) == 0 {
verifier, _ := verifier()
getMyAnimeListCodeUrl := "https://myanimelist.net/v1/oauth2/authorize?response_type=code&client_id=" + Environment.MAL_CLIENT_ID + "&redirect_uri=" + Environment.MAL_CALLBACK_URI + "&code_challenge=" + verifier.Value + "&code_challenge_method=plain"
runtime.BrowserOpenURL(*wailsContext, getMyAnimeListCodeUrl)
if err := a.app.Browser.OpenURL(getMyAnimeListCodeUrl); err != nil {
log.Printf("mal: failed to open browser: %s", err)
return
}
serverDone := &sync.WaitGroup{}
serverDone.Add(1)
a.handleMyAnimeListCallback(serverDone, verifier)
serverDone.Wait()
} else {
var expiresInConvertErr error
myAnimeListJwt.TokenType = string(tokenType.Data)
myAnimeListJwt.ExpiresIn, expiresInConvertErr = strconv.Atoi(string(expiresIn.Data))
myAnimeListJwt.TokenType = tokenType
myAnimeListJwt.ExpiresIn, expiresInConvertErr = strconv.Atoi(expiresIn)
if expiresInConvertErr != nil {
log.Printf("mal: invalid expiresIn %q: %s", string(expiresIn.Data), expiresInConvertErr)
log.Printf("mal: invalid expiresIn %q: %s", expiresIn, expiresInConvertErr)
}
myAnimeListJwt.AccessToken = string(accessToken.Data)
myAnimeListJwt.RefreshToken = string(refreshToken.Data)
myAnimeListJwt.AccessToken = accessToken
myAnimeListJwt.RefreshToken = refreshToken
}
}
}
@@ -175,17 +147,13 @@ func (a *App) handleMyAnimeListCallback(wg *sync.WaitGroup, verifier *CodeVerifi
_ = malRingSet("MyAnimeListExpiresIn", []byte(strconv.Itoa(myAnimeListJwt.ExpiresIn)))
_ = malRingSet("MyAnimeListAccessToken", []byte(myAnimeListJwt.AccessToken))
_ = malRingSet("MyAnimeListRefreshToken", []byte(myAnimeListJwt.RefreshToken))
_, err := runtime.MessageDialog(*wailsContext, runtime.MessageDialogOptions{
Title: "MyAnimeList Authorization",
Message: "It is now safe to close your browser tab",
})
if err != nil {
log.Println(err)
}
a.app.Dialog.Info().
SetTitle("MyAnimeList Authorization").
SetMessage("It is now safe to close your browser tab").
Show()
fmt.Println("Shutting down...")
myAnimeListCancel()
err = srv.Shutdown(context.Background())
if err != nil {
if err := srv.Shutdown(context.Background()); err != nil {
log.Println("server.Shutdown:", err)
}
} else {
@@ -378,14 +346,10 @@ func createUser() MyAnimeListUser {
func (a *App) LogoutMyAnimeList() string {
if (MyAnimeListJWT{} != myAnimeListJwt) {
if !malRingReady() {
myAnimeListJwt = MyAnimeListJWT{}
return "MAL Logged Out Successfully"
}
typeErr := myAnimeListRing.Remove("MyAnimeListTokenType")
expiresInErr := myAnimeListRing.Remove("MyAnimeListExpiresIn")
accessTokenErr := myAnimeListRing.Remove("MyAnimeListAccessToken")
refreshTokenErr := myAnimeListRing.Remove("MyAnimeListRefreshToken")
typeErr := keyring.Delete(malKeyringService, "MyAnimeListTokenType")
expiresInErr := keyring.Delete(malKeyringService, "MyAnimeListExpiresIn")
accessTokenErr := keyring.Delete(malKeyringService, "MyAnimeListAccessToken")
refreshTokenErr := keyring.Delete(malKeyringService, "MyAnimeListRefreshToken")
if typeErr != nil || expiresInErr != nil || accessTokenErr != nil || refreshTokenErr != nil {
log.Printf("mal: logout cleanup failed (type=%v expires=%v access=%v refresh=%v)", typeErr, expiresInErr, accessTokenErr, refreshTokenErr)
}