Skip to content

Commit 43e51ea

Browse files
committed
feat: refactor folder
1 parent 13a06e2 commit 43e51ea

File tree

11 files changed

+278
-213
lines changed

11 files changed

+278
-213
lines changed

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import init from './init';
1+
import initialize from './initialize';
22
import CodingServer from './services/codingServer';
33
import WebviewProvider from './webviews';
44
import ACTIONS, { dispatch } from './utils/actions';
@@ -36,7 +36,7 @@ async function activate(context: IContext) {
3636
});
3737

3838
proxyCtx(context);
39-
init(context);
39+
initialize(context);
4040
}
4141

4242
function deactivate() {

src/init.ts

Lines changed: 0 additions & 201 deletions
This file was deleted.

src/init/createTreeViews.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import hx from 'hbuilderx';
2+
import DepotTreeDataProvider from '../trees/depot';
3+
import MRTreeDataProvider from '../trees/mr';
4+
import DepotMRTreeDataProvider from '../trees/depotMR';
5+
6+
const { createTreeView } = hx.window;
7+
8+
const TREE_VIEWS = [
9+
{
10+
id: 'codingPlugin.treeMR',
11+
treeDataProvider: MRTreeDataProvider,
12+
},
13+
{
14+
id: 'codingPlugin.treeDepot',
15+
treeDataProvider: DepotTreeDataProvider,
16+
},
17+
{
18+
id: 'codingPlugin.treeDepotMR',
19+
treeDataProvider: DepotMRTreeDataProvider,
20+
},
21+
];
22+
23+
function createTreeViews(context: IContext) {
24+
TREE_VIEWS.forEach(({ id, treeDataProvider }) => {
25+
context.subscriptions.push(
26+
createTreeView(id, {
27+
showCollapseAll: false,
28+
treeDataProvider: new treeDataProvider(context),
29+
}),
30+
);
31+
});
32+
}
33+
34+
export default createTreeViews;

src/init/initCredentials.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import hx from 'hbuilderx';
2+
import * as DCloudService from '../services/dcloud';
3+
import toast from '../utils/toast';
4+
5+
const { executeCommand } = hx.commands;
6+
7+
export async function initCredentials(context: IContext) {
8+
try {
9+
let hbToken = await DCloudService.readConfig(`hbToken`);
10+
console.log('hbToken => ', hbToken);
11+
12+
if (!hbToken) {
13+
const code = await DCloudService.grantForUserInfo();
14+
console.log('code => ', code);
15+
const tokenResult = await DCloudService.applyForToken(code);
16+
console.log('tokenResult => ', tokenResult);
17+
hbToken = tokenResult.data.access_token;
18+
}
19+
20+
const resp = await DCloudService.fetchUser(hbToken);
21+
console.log('resp => ', resp);
22+
toast.info(`logged in as DCloud user: ${resp.data.nickname} ${resp.data.email}`);
23+
24+
executeCommand('codingPlugin.password');
25+
26+
// const {
27+
// ctx: { codingServer, repoInfo, token },
28+
// } = context;
29+
// const userData = await codingServer.getUserInfo(token);
30+
// console.log('userData => ', userData);
31+
// toast.info(`logged in as coding user: ${userData.name} @ ${userData.team}`);
32+
} catch (err) {
33+
console.error(err);
34+
}
35+
}

src/init/initWorkspace.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 CodingServer from '../services/codingServer';
3+
import ACTIONS, { dispatch } from '../utils/actions';
4+
5+
function initWorkspace(context: IContext) {
6+
hx.workspace.onDidChangeWorkspaceFolders(async function () {
7+
const repoInfo = await CodingServer.getRepoParams();
8+
dispatch(ACTIONS.SET_REPO_INFO, {
9+
context,
10+
value: repoInfo,
11+
});
12+
});
13+
}
14+
15+
export default initWorkspace;

0 commit comments

Comments
 (0)