1 Star 7 Fork 1

Gitee 极速下载/Readest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/readest/readest
克隆/下载
nativeAuth.ts 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
import { invoke } from '@tauri-apps/api/core';
import { listen } from '@tauri-apps/api/event';
import { type as osType } from '@tauri-apps/plugin-os';
export interface AuthRequest {
authUrl: string;
}
export interface AuthResponse {
redirectUrl: string;
}
export async function authWithSafari(request: AuthRequest): Promise<AuthResponse> {
const OS_TYPE = osType();
if (OS_TYPE === 'ios') {
const result = await invoke<AuthResponse>('plugin:native-bridge|auth_with_safari', {
payload: request,
});
return result;
} else if (OS_TYPE === 'macos') {
return new Promise<AuthResponse>(async (resolve, reject) => {
const unlistenComplete = await listen<AuthResponse>('safari-auth-complete', ({ payload }) => {
cleanup();
resolve(payload);
});
function cleanup() {
unlistenComplete();
}
try {
await invoke<AuthResponse>('auth_with_safari', { payload: request });
} catch (err) {
cleanup();
reject(err);
}
});
} else {
throw new Error('Unsupported OS type');
}
}
export async function authWithCustomTab(request: AuthRequest): Promise<AuthResponse> {
const result = await invoke<AuthResponse>('plugin:native-bridge|auth_with_custom_tab', {
payload: request,
});
return result;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/mirrors/Readest.git
git@gitee.com:mirrors/Readest.git
mirrors
Readest
Readest
main

搜索帮助