(signal: AbortSignal)
| 122 | } |
| 123 | |
| 124 | async function startLocalCallbackSession(signal: AbortSignal) { |
| 125 | await invoke("plugin:oauth|stop").catch(() => {}); |
| 126 | |
| 127 | const port: string = await invoke("plugin:oauth|start", { |
| 128 | config: { |
| 129 | response: callbackTemplate, |
| 130 | headers: { |
| 131 | "Content-Type": "text/html; charset=utf-8", |
| 132 | "Cache-Control": "no-store, no-cache, must-revalidate", |
| 133 | Pragma: "no-cache", |
| 134 | }, |
| 135 | cleanup: true, |
| 136 | }, |
| 137 | }); |
| 138 | |
| 139 | let settled = false; |
| 140 | let stopListening: (() => void) | undefined; |
| 141 | let resolvePromise: (data: AuthParams | null) => void = () => {}; |
| 142 | |
| 143 | const complete = new Promise<AuthParams | null>((resolve) => { |
| 144 | resolvePromise = resolve; |
| 145 | }); |
| 146 | |
| 147 | const settle = (value: AuthParams | null) => { |
| 148 | if (settled) return; |
| 149 | settled = true; |
| 150 | resolvePromise(value); |
| 151 | }; |
| 152 | |
| 153 | stopListening = await listen("oauth://url", (data: { payload: string }) => { |
| 154 | if (!(data.payload.includes("token") || data.payload.includes("api_key"))) { |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | settle(parseAuthParams(new URL(data.payload))); |
| 159 | }); |
| 160 | |
| 161 | const dispose = async () => { |
| 162 | stopListening?.(); |
| 163 | stopListening = undefined; |
| 164 | settle(null); |
| 165 | await invoke("plugin:oauth|stop").catch(() => {}); |
| 166 | }; |
| 167 | |
| 168 | signal.addEventListener("abort", () => void dispose(), { once: true }); |
| 169 | |
| 170 | return { port, complete, dispose }; |
| 171 | } |
| 172 | |
| 173 | async function startDeepLinkSession(signal: AbortSignal) { |
| 174 | let settled = false; |
no test coverage detected