(options = {})
| 161 | } |
| 162 | |
| 163 | async function fetchDuckEmail(options = {}) { |
| 164 | throwIfStopped(); |
| 165 | const { generateNew = true } = options; |
| 166 | |
| 167 | await addLog(`Duck 邮箱:正在打开自动填充设置(${generateNew ? '生成新地址' : '复用当前地址'})...`); |
| 168 | await reuseOrCreateTab('duck-mail', DUCK_AUTOFILL_URL); |
| 169 | |
| 170 | const result = await sendToContentScript('duck-mail', { |
| 171 | type: 'FETCH_DUCK_EMAIL', |
| 172 | source: 'background', |
| 173 | payload: { generateNew }, |
| 174 | }); |
| 175 | |
| 176 | if (result?.error) { |
| 177 | throw new Error(result.error); |
| 178 | } |
| 179 | if (!result?.email) { |
| 180 | throw new Error('未返回 Duck 邮箱地址。'); |
| 181 | } |
| 182 | |
| 183 | await setEmailState(result.email); |
| 184 | await addLog(`Duck 邮箱:${result.generated ? '已生成' : '已读取'} ${result.email}`, 'ok'); |
| 185 | return result.email; |
| 186 | } |
| 187 | |
| 188 | async function fetchGeneratedEmail(state, options = {}) { |
| 189 | const currentState = state || await getState(); |
no test coverage detected