Skip to content

Commit c9bb8e4

Browse files
committed
feat: add login logout listener
1 parent 8ba2a28 commit c9bb8e4

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/init/initCredentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function initCredentials(context: IContext) {
3131
toast.info(`logged in as CODING user: ${userData.name} @ ${userData.team}`);
3232
}
3333
} catch (err) {
34-
if (err === 1) {
34+
if (Number(err) === 1) {
3535
toast.warn(`请先登录 DCloud`);
3636
}
3737
} finally {

src/init/initLoginLogout.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import hx from 'hbuilderx';
2+
import { refreshTree } from './registerCommands';
3+
4+
const { onUserLogin, onUserLogout } = hx.authorize;
5+
6+
export default function initLoginLogout(context: IContext) {
7+
onUserLogin(() => {
8+
console.warn('login');
9+
refreshTree();
10+
});
11+
12+
onUserLogout(() => {
13+
console.warn('logout');
14+
});
15+
}

src/init/registerCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { showQuickPick, showInputBox } = hx.window;
1111
export const refreshTree = () => executeCommand('codingPlugin.refreshTree');
1212

1313
export default function registerCommands(context: IContext) {
14-
const { codingServer, token } = context;
14+
const { codingServer } = context;
1515

1616
context.subscriptions.push(
1717
registerCommand('codingPlugin.pickDepot', async function () {
@@ -48,7 +48,7 @@ export default function registerCommands(context: IContext) {
4848
if (matchRes) {
4949
const [, project, repo, mergeRequestIId] = matchRes;
5050
context.webviewProvider.update({
51-
token,
51+
token: context.token,
5252
userInfo,
5353
mergeRequestIId,
5454
repoInfo: {

src/initialize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import createTreeViews from './init/createTreeViews';
22
import initWorkspace from './init/initWorkspace';
33
import { initCredentials } from './init/initCredentials';
44
import registerCommands from './init/registerCommands';
5+
import initLoginLogout from './init/initLoginLogout';
56

67
export function clear(context: IContext) {
78
context.subscriptions.forEach(({ dispose }) => dispose());
89
}
910

1011
export default function initialize(context: IContext) {
12+
initLoginLogout(context);
1113
initCredentials(context);
1214
registerCommands(context);
1315
createTreeViews(context);

src/utils/axios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const createInstance = (): Instance => {
3434
return instance;
3535
};
3636

37-
const isProd = false;
37+
const isProd = true;
3838

3939
export const getApiPrefix = (team = 'e') => {
4040
return isProd ? `https://${team}.coding.net` : `http://${team}.staging-corp.coding.io`;

0 commit comments

Comments
 (0)