1 Star 7 Fork 1

Gitee 极速下载/Readest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/readest/readest
克隆/下载
appleIdAuth.ts 1.78 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 type Scope = 'fullName' | 'email';
export interface AppleIDAuthorizationRequest {
scope: Scope[];
nonce?: string;
state?: string;
}
export interface AppleIDAuthorizationResponse {
// usually not null
userIdentifier: string | null;
givenName: string | null;
familyName: string | null;
email: string | null;
authorizationCode: string;
identityToken: string | null;
state: string | null;
}
export async function getAppleIdAuth(
request: AppleIDAuthorizationRequest,
): Promise<AppleIDAuthorizationResponse> {
const OS_TYPE = osType();
if (OS_TYPE === 'ios') {
const result = await invoke<AppleIDAuthorizationResponse>(
'plugin:sign-in-with-apple|get_apple_id_credential',
{
payload: request,
},
);
return result;
} else if (OS_TYPE === 'macos') {
return new Promise<AppleIDAuthorizationResponse>(async (resolve, reject) => {
const unlistenComplete = await listen<AppleIDAuthorizationResponse>(
'apple-sign-in-complete',
({ payload }) => {
cleanup();
resolve(payload);
},
);
const unlistenError = await listen<string>('apple-sign-in-error', ({ payload }) => {
cleanup();
reject(
typeof payload === 'string' ? new Error(payload) : new Error('Apple sign‑in failed'),
);
});
function cleanup() {
unlistenComplete();
unlistenError();
}
try {
await invoke('start_apple_sign_in', { payload: request });
} catch (err) {
cleanup();
reject(err);
}
});
} else {
throw new Error('Unsupported platform');
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/mirrors/Readest.git
git@gitee.com:mirrors/Readest.git
mirrors
Readest
Readest
main

搜索帮助