|
7 | 7 |
|
8 | 8 |
|
9 | 9 | export const commands = { |
10 | | -async startOauthServer() : Promise<number> { |
11 | | - return await TAURI_INVOKE("plugin:auth|start_oauth_server"); |
| 10 | +async startOauthServer() : Promise<Result<number, string>> { |
| 11 | + try { |
| 12 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|start_oauth_server") }; |
| 13 | +} catch (e) { |
| 14 | + if(e instanceof Error) throw e; |
| 15 | + else return { status: "error", error: e as any }; |
| 16 | +} |
12 | 17 | }, |
13 | | -async stopOauthServer(port: number) : Promise<null> { |
14 | | - return await TAURI_INVOKE("plugin:auth|stop_oauth_server", { port }); |
| 18 | +async stopOauthServer(port: number) : Promise<Result<null, string>> { |
| 19 | + try { |
| 20 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|stop_oauth_server", { port }) }; |
| 21 | +} catch (e) { |
| 22 | + if(e instanceof Error) throw e; |
| 23 | + else return { status: "error", error: e as any }; |
| 24 | +} |
15 | 25 | }, |
16 | | -async initVault(userId: string) : Promise<null> { |
17 | | - return await TAURI_INVOKE("plugin:auth|init_vault", { userId }); |
| 26 | +async initVault(userId: string) : Promise<Result<null, string>> { |
| 27 | + try { |
| 28 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|init_vault", { userId }) }; |
| 29 | +} catch (e) { |
| 30 | + if(e instanceof Error) throw e; |
| 31 | + else return { status: "error", error: e as any }; |
| 32 | +} |
18 | 33 | }, |
19 | | -async resetVault() : Promise<null> { |
20 | | - return await TAURI_INVOKE("plugin:auth|reset_vault"); |
| 34 | +async resetVault() : Promise<Result<null, string>> { |
| 35 | + try { |
| 36 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|reset_vault") }; |
| 37 | +} catch (e) { |
| 38 | + if(e instanceof Error) throw e; |
| 39 | + else return { status: "error", error: e as any }; |
| 40 | +} |
21 | 41 | }, |
22 | | -async getFromVault(key: VaultKey) : Promise<string | null> { |
23 | | - return await TAURI_INVOKE("plugin:auth|get_from_vault", { key }); |
| 42 | +async getFromVault(key: VaultKey) : Promise<Result<string | null, string>> { |
| 43 | + try { |
| 44 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|get_from_vault", { key }) }; |
| 45 | +} catch (e) { |
| 46 | + if(e instanceof Error) throw e; |
| 47 | + else return { status: "error", error: e as any }; |
| 48 | +} |
24 | 49 | }, |
25 | | -async getFromStore(key: StoreKey) : Promise<string | null> { |
26 | | - return await TAURI_INVOKE("plugin:auth|get_from_store", { key }); |
| 50 | +async getFromStore(key: StoreKey) : Promise<Result<string | null, string>> { |
| 51 | + try { |
| 52 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|get_from_store", { key }) }; |
| 53 | +} catch (e) { |
| 54 | + if(e instanceof Error) throw e; |
| 55 | + else return { status: "error", error: e as any }; |
| 56 | +} |
27 | 57 | }, |
28 | | -async setInVault(key: VaultKey, value: string) : Promise<null> { |
29 | | - return await TAURI_INVOKE("plugin:auth|set_in_vault", { key, value }); |
| 58 | +async setInVault(key: VaultKey, value: string) : Promise<Result<null, string>> { |
| 59 | + try { |
| 60 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|set_in_vault", { key, value }) }; |
| 61 | +} catch (e) { |
| 62 | + if(e instanceof Error) throw e; |
| 63 | + else return { status: "error", error: e as any }; |
| 64 | +} |
30 | 65 | }, |
31 | | -async setInStore(key: StoreKey, value: string) : Promise<null> { |
32 | | - return await TAURI_INVOKE("plugin:auth|set_in_store", { key, value }); |
| 66 | +async setInStore(key: StoreKey, value: string) : Promise<Result<null, string>> { |
| 67 | + try { |
| 68 | + return { status: "ok", data: await TAURI_INVOKE("plugin:auth|set_in_store", { key, value }) }; |
| 69 | +} catch (e) { |
| 70 | + if(e instanceof Error) throw e; |
| 71 | + else return { status: "error", error: e as any }; |
| 72 | +} |
33 | 73 | } |
34 | 74 | } |
35 | 75 |
|
|
0 commit comments