app now only allows a single instance
This commit is contained in:
		@@ -52,7 +52,7 @@ func (a *App) AniListLogin() {
 | 
				
			|||||||
		refreshToken, err := aniRing.Get("anilistRefreshToken")
 | 
							refreshToken, err := aniRing.Get("anilistRefreshToken")
 | 
				
			||||||
		if err != nil || len(accessToken.Data) == 0 {
 | 
							if err != nil || len(accessToken.Data) == 0 {
 | 
				
			||||||
			getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + Environment.ANILIST_APP_ID + "&redirect_uri=" + Environment.ANILIST_CALLBACK_URI + "&response_type=code"
 | 
								getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + Environment.ANILIST_APP_ID + "&redirect_uri=" + Environment.ANILIST_CALLBACK_URI + "&response_type=code"
 | 
				
			||||||
			runtime.BrowserOpenURL(a.ctx, getAniListCodeUrl)
 | 
								runtime.BrowserOpenURL(*wailsContext, getAniListCodeUrl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			serverDone := &sync.WaitGroup{}
 | 
								serverDone := &sync.WaitGroup{}
 | 
				
			||||||
			serverDone.Add(1)
 | 
								serverDone.Add(1)
 | 
				
			||||||
@@ -97,7 +97,7 @@ func (a *App) handleAniListCallback(wg *sync.WaitGroup) {
 | 
				
			|||||||
				Key:  "anilistRefreshToken",
 | 
									Key:  "anilistRefreshToken",
 | 
				
			||||||
				Data: []byte(aniListJwt.RefreshToken),
 | 
									Data: []byte(aniListJwt.RefreshToken),
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			_, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
 | 
								_, err := runtime.MessageDialog(*wailsContext, runtime.MessageDialogOptions{
 | 
				
			||||||
				Title:   "AniList Authorization",
 | 
									Title:   "AniList Authorization",
 | 
				
			||||||
				Message: "It is now safe to close your browser tab",
 | 
									Message: "It is now safe to close your browser tab",
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,7 +97,7 @@ func (a *App) MyAnimeListLogin() {
 | 
				
			|||||||
		if err != nil || len(accessToken.Data) == 0 {
 | 
							if err != nil || len(accessToken.Data) == 0 {
 | 
				
			||||||
			verifier, _ := verifier()
 | 
								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"
 | 
								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(a.ctx, getMyAnimeListCodeUrl)
 | 
								runtime.BrowserOpenURL(*wailsContext, getMyAnimeListCodeUrl)
 | 
				
			||||||
			serverDone := &sync.WaitGroup{}
 | 
								serverDone := &sync.WaitGroup{}
 | 
				
			||||||
			serverDone.Add(1)
 | 
								serverDone.Add(1)
 | 
				
			||||||
			a.handleMyAnimeListCallback(serverDone, verifier)
 | 
								a.handleMyAnimeListCallback(serverDone, verifier)
 | 
				
			||||||
@@ -144,7 +144,7 @@ func (a *App) handleMyAnimeListCallback(wg *sync.WaitGroup, verifier *CodeVerifi
 | 
				
			|||||||
				Key:  "MyAnimeListRefreshToken",
 | 
									Key:  "MyAnimeListRefreshToken",
 | 
				
			||||||
				Data: []byte(myAnimeListJwt.RefreshToken),
 | 
									Data: []byte(myAnimeListJwt.RefreshToken),
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			_, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
 | 
								_, err := runtime.MessageDialog(*wailsContext, runtime.MessageDialogOptions{
 | 
				
			||||||
				Title:   "MyAnimeList Authorization",
 | 
									Title:   "MyAnimeList Authorization",
 | 
				
			||||||
				Message: "It is now safe to close your browser tab",
 | 
									Message: "It is now safe to close your browser tab",
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ func (a *App) SimklLogin() {
 | 
				
			|||||||
		scope, err := simklRing.Get("SimklScope")
 | 
							scope, err := simklRing.Get("SimklScope")
 | 
				
			||||||
		if err != nil || len(accessToken.Data) == 0 {
 | 
							if err != nil || len(accessToken.Data) == 0 {
 | 
				
			||||||
			getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + Environment.SIMKL_CLIENT_ID + "&redirect_uri=" + Environment.SIMKL_CALLBACK_URI
 | 
								getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + Environment.SIMKL_CLIENT_ID + "&redirect_uri=" + Environment.SIMKL_CALLBACK_URI
 | 
				
			||||||
			runtime.BrowserOpenURL(a.ctx, getSimklCodeUrl)
 | 
								runtime.BrowserOpenURL(*wailsContext, getSimklCodeUrl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			serverDone := &sync.WaitGroup{}
 | 
								serverDone := &sync.WaitGroup{}
 | 
				
			||||||
			serverDone.Add(1)
 | 
								serverDone.Add(1)
 | 
				
			||||||
@@ -87,7 +87,7 @@ func (a *App) handleSimklCallback(wg *sync.WaitGroup) {
 | 
				
			|||||||
				Key:  "SimklScope",
 | 
									Key:  "SimklScope",
 | 
				
			||||||
				Data: []byte(simklJwt.Scope),
 | 
									Data: []byte(simklJwt.Scope),
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			_, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
 | 
								_, err := runtime.MessageDialog(*wailsContext, runtime.MessageDialogOptions{
 | 
				
			||||||
				Title:   "Simkl Authorization",
 | 
									Title:   "Simkl Authorization",
 | 
				
			||||||
				Message: "It is now safe to close your browser tab",
 | 
									Message: "It is now safe to close your browser tab",
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								app.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								app.go
									
									
									
									
									
								
							@@ -2,8 +2,13 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
						"github.com/wailsapp/wails/v2/pkg/options"
 | 
				
			||||||
 | 
						"github.com/wailsapp/wails/v2/pkg/runtime"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var wailsContext *context.Context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// App struct
 | 
					// App struct
 | 
				
			||||||
type App struct {
 | 
					type App struct {
 | 
				
			||||||
	ctx context.Context
 | 
						ctx context.Context
 | 
				
			||||||
@@ -17,6 +22,16 @@ func NewApp() *App {
 | 
				
			|||||||
// startup is called when the app starts. The context is saved
 | 
					// startup is called when the app starts. The context is saved
 | 
				
			||||||
// so we can call the runtime methods
 | 
					// so we can call the runtime methods
 | 
				
			||||||
func (a *App) startup(ctx context.Context) {
 | 
					func (a *App) startup(ctx context.Context) {
 | 
				
			||||||
	a.ctx = ctx
 | 
						wailsContext = &ctx
 | 
				
			||||||
	//runtime.WindowMaximise(ctx)
 | 
						//runtime.WindowMaximise(ctx)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (a *App) onSecondInstanceLaunch(secondInstanceData options.SecondInstanceData) {
 | 
				
			||||||
 | 
						var secondInstanceArgs = secondInstanceData.Args
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						println("user opened second instance", strings.Join(secondInstanceData.Args, ","))
 | 
				
			||||||
 | 
						println("user opened second from", secondInstanceData.WorkingDirectory)
 | 
				
			||||||
 | 
						runtime.WindowUnminimise(*wailsContext)
 | 
				
			||||||
 | 
						runtime.Show(*wailsContext)
 | 
				
			||||||
 | 
						go runtime.EventsEmit(*wailsContext, "launchArgs", secondInstanceArgs)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.go
									
									
									
									
									
								
							@@ -26,6 +26,10 @@ func main() {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
 | 
							BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
 | 
				
			||||||
		OnStartup:        app.startup,
 | 
							OnStartup:        app.startup,
 | 
				
			||||||
 | 
							SingleInstanceLock: &options.SingleInstanceLock{
 | 
				
			||||||
 | 
								UniqueId:               "49c93b6d-663d-4b7a-9cb0-8a469ea9182b",
 | 
				
			||||||
 | 
								OnSecondInstanceLaunch: app.onSecondInstanceLaunch,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		Bind: []interface{}{
 | 
							Bind: []interface{}{
 | 
				
			||||||
			app,
 | 
								app,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user