(error, actionLabel = 'iCloud 操作')
| 2885 | } |
| 2886 | |
| 2887 | async function promptIcloudLogin(error, actionLabel = 'iCloud 操作') { |
| 2888 | const now = Date.now(); |
| 2889 | const preferredUrl = await getPreferredIcloudLoginUrl(error); |
| 2890 | const originalError = getErrorMessage(error); |
| 2891 | |
| 2892 | chrome.runtime.sendMessage({ |
| 2893 | type: 'ICLOUD_LOGIN_REQUIRED', |
| 2894 | payload: { |
| 2895 | actionLabel, |
| 2896 | loginUrl: preferredUrl, |
| 2897 | message: '需要先登录 iCloud,我已经为你打开登录页。', |
| 2898 | detail: originalError, |
| 2899 | }, |
| 2900 | }).catch(() => { }); |
| 2901 | |
| 2902 | if (now - lastIcloudLoginPromptAt < 15000) { |
| 2903 | return; |
| 2904 | } |
| 2905 | lastIcloudLoginPromptAt = now; |
| 2906 | |
| 2907 | await addLog(`iCloud:${actionLabel}时需要登录,正在打开 ${new URL(preferredUrl).host} ...`, 'warn'); |
| 2908 | |
| 2909 | try { |
| 2910 | await openIcloudLoginPage(preferredUrl); |
| 2911 | } catch (tabErr) { |
| 2912 | await addLog(`iCloud:自动打开登录页失败:${getErrorMessage(tabErr)}`, 'warn'); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | async function withIcloudLoginHelp(actionLabel, action) { |
| 2917 | try { |
no test coverage detected