Skip to content

Commit f3d8b2b

Browse files
author
Deep-sea-school
committed
修复白屏问题
1 parent 235e31e commit f3d8b2b

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/components/github-oauth-modal/github-oauth-modal.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const GitHubOAuthModal = props => {
202202
const isElectron = typeof window.EditorPreload !== 'undefined';
203203

204204
if (isElectron) {
205-
// 在 Electron 环境中,使用轮询的方式处理 OAuth
205+
// 在 Electron 环境中,启动 OAuth 并等待结果
206206
const result = await githubOAuth.startOAuth(CLIENT_ID);
207207
setUserInfo({
208208
...result.user,
@@ -211,8 +211,8 @@ const GitHubOAuthModal = props => {
211211

212212
onSuccess && onSuccess(result);
213213
} else {
214+
// 在浏览器环境中,启动 OAuth(这将重定向页面)
214215
await githubOAuth.startOAuth(CLIENT_ID);
215-
// 如果 startOAuth 成功,页面会重定向到 GitHub
216216
}
217217
} catch (err) {
218218
console.error('OAuth start failed:', err);

src/lib/github-oauth.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ class GitHubOAuthService {
6868
try {
6969
// 检查是否在 Electron 环境中
7070
if (this.isElectron) {
71-
// 在 Electron 中,打开远程 oauth-proxy 页面而不是直接重定向到 GitHub
72-
// 远程 oauth-proxy 会处理回调并将结果传递回桌面应用
73-
const proxyUrl = 'https://idyllic-kangaroo-a50663.netlify.app/';
74-
window.open(proxyUrl, '_blank', 'width=600,height=800');
71+
// 在 Electron 中,使用 window.open 打开 oauth-proxy 页面
72+
// 它会被 handleWindowOpen 捕获并正确配置
73+
window.open('https://idyllic-kangaroo-a50663.netlify.app/', '_blank', 'width=600,height=800');
7574

7675
// 启动轮询检查是否收到 token,并返回结果
7776
return await this.pollForToken();
@@ -111,14 +110,14 @@ class GitHubOAuthService {
111110
*/
112111
async pollForToken() {
113112
return new Promise((resolve, reject) => {
114-
const maxAttempts = 60; // 最多等待 30 秒 (60 次 * 500ms)
113+
const maxAttempts = 180; // 最多等待 90 秒 (180 次 * 500ms)
115114
let attempts = 0;
116115

117116
const poll = async () => {
118117
attempts++;
119118

120119
if (attempts > maxAttempts) {
121-
reject(new Error('OAuth timeout: No token received within 30 seconds'));
120+
reject(new Error('OAuth timeout: No token received within 90 seconds'));
122121
return;
123122
}
124123

@@ -149,6 +148,7 @@ class GitHubOAuthService {
149148
setTimeout(poll, 500); // 每 500ms 检查一次
150149
};
151150

151+
// 立即开始轮询,然后定期检查
152152
poll();
153153
});
154154
}

0 commit comments

Comments
 (0)