@@ -5,12 +5,15 @@ import (
55 "fmt"
66 "io"
77 "net/http"
8+ "strings"
9+ "sync"
810 "time"
911
1012 "github.com/linhay/gettokens/internal/codexbinary"
1113 "github.com/linhay/gettokens/internal/sidecar"
1214 "github.com/linhay/gettokens/internal/updater"
1315 wailsapp "github.com/linhay/gettokens/internal/wailsapp"
16+ wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime"
1417)
1518
1619// Version is injected at build time via -ldflags
@@ -23,7 +26,10 @@ var ReleaseLabel = ""
2326const GitHubRepo = "AxApp/GetTokens"
2427
2528type App struct {
26- core * wailsapp.App
29+ core * wailsapp.App
30+ ctx context.Context
31+ pendingDeepLinkMu sync.Mutex
32+ pendingDeepLinkURL []string
2733}
2834
2935func mapCodexConfigChangeInputs (inputs []CodexConfigChangeInput ) []wailsapp.CodexConfigChangeInput {
@@ -51,8 +57,10 @@ func NewApp() *App {
5157}
5258
5359func (a * App ) startup (ctx context.Context ) {
60+ a .ctx = ctx
5461 a .core .Startup (ctx )
5562 installNativeApplicationMenuUpdateItem (a )
63+ a .emitQueuedDeepLinks ()
5664}
5765
5866func (a * App ) shutdown (ctx context.Context ) {
@@ -119,6 +127,48 @@ func (a *App) FetchVendorStatusRSS(url string) (string, error) {
119127 return string (body ), nil
120128}
121129
130+ func (a * App ) queueDeepLinks (urls []string ) {
131+ links := filterDeepLinkURLs (urls )
132+ if len (links ) == 0 {
133+ return
134+ }
135+ a .pendingDeepLinkMu .Lock ()
136+ a .pendingDeepLinkURL = append (a .pendingDeepLinkURL , links ... )
137+ a .pendingDeepLinkMu .Unlock ()
138+ a .emitQueuedDeepLinks ()
139+ }
140+
141+ func (a * App ) ConsumePendingDeepLinks () []string {
142+ a .pendingDeepLinkMu .Lock ()
143+ defer a .pendingDeepLinkMu .Unlock ()
144+ links := append ([]string (nil ), a .pendingDeepLinkURL ... )
145+ a .pendingDeepLinkURL = nil
146+ return links
147+ }
148+
149+ func (a * App ) emitQueuedDeepLinks () {
150+ if a .ctx == nil {
151+ return
152+ }
153+ a .pendingDeepLinkMu .Lock ()
154+ links := append ([]string (nil ), a .pendingDeepLinkURL ... )
155+ a .pendingDeepLinkMu .Unlock ()
156+ for _ , link := range links {
157+ wailsruntime .EventsEmit (a .ctx , "deeplink:import" , link )
158+ }
159+ }
160+
161+ func filterDeepLinkURLs (values []string ) []string {
162+ links := make ([]string , 0 , len (values ))
163+ for _ , value := range values {
164+ trimmed := strings .TrimSpace (value )
165+ if strings .HasPrefix (strings .ToLower (trimmed ), "gettokens://" ) {
166+ links = append (links , trimmed )
167+ }
168+ }
169+ return links
170+ }
171+
122172func (a * App ) ListAuthFiles () (* AuthFilesResponse , error ) {
123173 result , err := a .core .ListAuthFiles ()
124174 if err != nil {
@@ -1207,16 +1257,29 @@ func (a *App) ApplyRelayServiceConfigToLocal(apiKey string, baseURL string, mode
12071257
12081258func (a * App ) ApplyRelayServiceConfigToLocalV2 (input RelayLocalApplyInput ) (* RelayLocalApplyResult , error ) {
12091259 result , err := a .core .ApplyRelayServiceConfigToLocalV2 (wailsapp.RelayLocalApplyInput {
1210- APIKey : input .APIKey ,
1211- AuthFileContentBase64 : input .AuthFileContentBase64 ,
1212- BaseURL : input .BaseURL ,
1213- Model : input .Model ,
1214- ReasoningEffort : input .ReasoningEffort ,
1215- ProviderID : input .ProviderID ,
1216- ProviderName : input .ProviderName ,
1217- SupportsWebsockets : input .SupportsWebsockets ,
1218- AuthStrategy : input .AuthStrategy ,
1219- SkipRelayKeyMetadata : input .SkipRelayKeyMetadata ,
1260+ PreserveUnspecifiedFields : input .PreserveUnspecifiedFields ,
1261+ APIKey : input .APIKey ,
1262+ APIKeySet : input .APIKeySet ,
1263+ AuthFileContentBase64 : input .AuthFileContentBase64 ,
1264+ AuthFileContentSet : input .AuthFileContentSet ,
1265+ BaseURL : input .BaseURL ,
1266+ BaseURLSet : input .BaseURLSet ,
1267+ Model : input .Model ,
1268+ ModelSet : input .ModelSet ,
1269+ ReasoningEffort : input .ReasoningEffort ,
1270+ ReasoningEffortSet : input .ReasoningEffortSet ,
1271+ ProviderID : input .ProviderID ,
1272+ ProviderIDSet : input .ProviderIDSet ,
1273+ ProviderName : input .ProviderName ,
1274+ ProviderNameSet : input .ProviderNameSet ,
1275+ RequiresOpenAIAuth : input .RequiresOpenAIAuth ,
1276+ RequiresOpenAIAuthSet : input .RequiresOpenAIAuthSet ,
1277+ WireAPI : input .WireAPI ,
1278+ WireAPISet : input .WireAPISet ,
1279+ SupportsWebsockets : input .SupportsWebsockets ,
1280+ SupportsWebsocketsSet : input .SupportsWebsocketsSet ,
1281+ AuthStrategy : input .AuthStrategy ,
1282+ SkipRelayKeyMetadata : input .SkipRelayKeyMetadata ,
12201283 })
12211284 if err != nil {
12221285 return nil , err
@@ -1248,6 +1311,31 @@ func (a *App) GetLocalCodexAuthState() (*LocalCodexAuthState, error) {
12481311 }, nil
12491312}
12501313
1314+ func (a * App ) ParseDeepLink (rawURL string ) (* DeepLinkImportRequest , error ) {
1315+ result , err := a .core .ParseDeepLink (rawURL )
1316+ if err != nil {
1317+ return nil , err
1318+ }
1319+ mapped := mapDeepLinkImportRequest (* result )
1320+ return & mapped , nil
1321+ }
1322+
1323+ func (a * App ) PreviewDeepLinkImport (rawURL string ) (* DeepLinkImportPreview , error ) {
1324+ result , err := a .core .PreviewDeepLinkImport (rawURL )
1325+ if err != nil {
1326+ return nil , err
1327+ }
1328+ return mapDeepLinkImportPreview (result ), nil
1329+ }
1330+
1331+ func (a * App ) ApplyDeepLinkImport (rawURL string ) (* DeepLinkApplyResult , error ) {
1332+ result , err := a .core .ApplyDeepLinkImportURL (rawURL )
1333+ if err != nil {
1334+ return nil , err
1335+ }
1336+ return mapDeepLinkApplyResult (result ), nil
1337+ }
1338+
12511339func (a * App ) ApplyClaudeCodeAPIKeyConfigToLocal (apiKey string , baseURL string , options ClaudeCodeLocalApplyOptions ) (* ClaudeCodeLocalApplyResult , error ) {
12521340 result , err := a .core .ApplyClaudeCodeAPIKeyConfigToLocal (apiKey , baseURL , wailsapp.ClaudeCodeLocalApplyOptions {
12531341 AuthField : options .AuthField ,
0 commit comments