Skip to content

Commit 3746442

Browse files
committed
fix: 调整 atomgit oauth 授权交互
1 parent c6d71c9 commit 3746442

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

packages/code-api/src/atomgit/atomgit.service.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,32 @@ export class AtomGitAPIService implements ICodeAPIService {
3939
this._PRIVATE_TOKEN = this.config.token || this.helper.ATOMGIT_TOKEN || '';
4040
}
4141

42+
private sleep(t: number) {
43+
return new Promise(res => {
44+
setTimeout(() => {
45+
res(undefined)
46+
}, t)
47+
})
48+
}
49+
4250
private async checkAccessToken(): Promise<boolean> {
43-
const popupWindow = window.open(`${this.config.origin}login/oauth/authorize?client_id=9d8b531661f441d1`, '_blank', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=520,top=150,left=150');
44-
return new Promise<boolean>((resolve, reject) => {
51+
return new Promise<boolean>(async (resolve, reject) => {
52+
resolve(true);
53+
// 一开始就弹出弹窗会有颜色闪烁问题,先临时 sleep 处理,后面再优化
54+
await this.sleep(300);
55+
56+
const btn = await this.helper.showDialog({
57+
message: '检测到 OAuth 未授权',
58+
type: MessageType.Info,
59+
closable: false,
60+
buttons: ['去授权']
61+
});
62+
63+
let popupWindow;
64+
if (btn === '去授权') {
65+
popupWindow = window.open(`${this.config.origin}login/oauth/authorize?client_id=9d8b531661f441d1`, '_blank', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=520,top=150,left=150');
66+
}
67+
4568
const handleMessage = async (event: MessageEvent) => {
4669
try {
4770
const { data } = event;

packages/code-api/src/common/service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
localize,
1111
} from '@opensumi/ide-core-common';
1212
import { ClientAppStateService } from '@opensumi/ide-core-browser';
13-
import { IMessageService } from '@opensumi/ide-overlay';
13+
import { IMessageService, IDialogService } from '@opensumi/ide-overlay';
14+
import { DialogService } from '@opensumi/ide-overlay/lib/browser/dialog.service';
1415
import { ATOMGIT_PRIVATE_TOKEN, GITHUB_OAUTH_TOKEN, GITLAB_PRIVATE_TOKEN } from './constant';
1516
import { ICodePlatform } from './types';
1617
import { CODE_PLATFORM_CONFIG } from './config';
@@ -31,6 +32,9 @@ export class HelperService {
3132
@Autowired(IMessageService)
3233
messageService: IMessageService;
3334

35+
@Autowired(IDialogService)
36+
public dialogService: DialogService;
37+
3438
@Autowired(ClientAppStateService)
3539
stateService: ClientAppStateService;
3640

@@ -120,4 +124,16 @@ export class HelperService {
120124
CODE_PLATFORM_CONFIG[platform].brand
121125
);
122126
}
127+
128+
async showDialog(
129+
msg: {
130+
message: string | React.ReactNode,
131+
type: MessageType,
132+
buttons?: any[],
133+
closable?: boolean,
134+
}
135+
) {
136+
const { message, type, buttons = [], closable = true } = msg;
137+
return this.dialogService.open(message, type, buttons, closable);
138+
}
123139
}

packages/toolkit/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@
6565
"webpack-dev-server": "^3.11.0",
6666
"webpack-manifest-plugin": "^3.0.0",
6767
"webpack-merge": "^5.4.0"
68-
}
69-
}
68+
},
69+
"repository": "git@gitlab.alipay-inc.com:cloud-ide/crew-dragon.git"
70+
}

0 commit comments

Comments
 (0)