Skip to content

Commit 966ec2a

Browse files
committed
add workshop button
1 parent 4f36360 commit 966ec2a

File tree

6 files changed

+77
-5
lines changed

6 files changed

+77
-5
lines changed

dbux-code/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@
8787
"commands": [
8888
{
8989
"command": "dbux.doActivate",
90-
"title": "Dbux: Start Dbux"
90+
"title": "Dbux: Start Dbux (no workshop)"
91+
},
92+
{
93+
"command": "dbux.doWorkshopActivate",
94+
"title": "Dbux: Start Workshop Session"
9195
},
9296
{
9397
"command": "dbux.diagnostics",
@@ -1063,6 +1067,10 @@
10631067
"command": "dbux.doActivate",
10641068
"when": "!dbux.context.activated"
10651069
},
1070+
{
1071+
"command": "dbux.doWorkshopActivate",
1072+
"when": "!dbux.context.activated"
1073+
},
10661074
{
10671075
"command": "dbux.backendLogin",
10681076
"when": "dbux.context.activated"

dbux-code/src/preActivate.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { workspace, commands } from 'vscode';
1+
import { workspace, commands, window } from 'vscode';
22
import { newLogger } from '@dbux/common/src/log/logger';
33
import { initMemento, get as mementoGet, set as mementoSet } from './memento';
44
import { initInstallId } from './installId';
@@ -9,6 +9,8 @@ import { initPreActivateView } from './preActivateView/preActivateNodeProvider';
99
import { registerCommand } from './commands/commandUtil';
1010
import initLang from './lang';
1111
import { getCurrentResearch } from './research/Research';
12+
import { activateWorkshopSession, isValidCode } from './workshop/Workshop';
13+
import { showInformationMessage } from './codeUtil/codeModals';
1214

1315
/** @typedef {import('./dialogs/dialogController').DialogController} DialogController */
1416

@@ -107,6 +109,20 @@ async function ensureActivate(context) {
107109
*/
108110
function initPreActivateCommand(context) {
109111
registerCommand(context, 'dbux.doActivate', async () => ensureActivate(context));
112+
113+
registerCommand(context, 'dbux.doWorkshopActivate', async () => {
114+
const code = await window.showInputBox({
115+
ignoreFocusOut: true,
116+
placeHolder: 'Enter Workshop Code'
117+
});
118+
if (isValidCode(code)) {
119+
activateWorkshopSession(code);
120+
await ensureActivate(context);
121+
}
122+
else {
123+
await showInformationMessage(`Workshop code ${code} is invalid`);
124+
}
125+
});
110126
}
111127

112128
function registerErrorHandler() {

dbux-code/src/preActivateView/ActivateNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
22

3-
export class ActivateNode extends TreeItem {
3+
export default class ActivateNode extends TreeItem {
44
constructor() {
55
super('Start Dbux', TreeItemCollapsibleState.None);
66

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
2+
3+
export default class WorkshopNode extends TreeItem {
4+
constructor() {
5+
super('Start Dbux', TreeItemCollapsibleState.None);
6+
7+
this.command = {
8+
command: 'dbux.doWorkshopActivate'
9+
};
10+
}
11+
12+
makeIconPath() {
13+
return 'play.svg';
14+
}
15+
16+
// singleton
17+
static get instance() {
18+
return WorkshopNode._instance = (WorkshopNode._instance || new WorkshopNode());
19+
}
20+
}

dbux-code/src/preActivateView/preActivateNodeProvider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import BaseTreeViewNodeProvider from '../codeUtil/treeView/BaseTreeViewNodeProvider';
2-
import { ActivateNode } from './ActivateNode';
2+
import ActivateNode from './ActivateNode';
3+
import WorkshopNode from './WorkshopNode';
34

45
class PreActivateNodeProvider extends BaseTreeViewNodeProvider {
56
/**
@@ -10,7 +11,7 @@ class PreActivateNodeProvider extends BaseTreeViewNodeProvider {
1011
}
1112

1213
buildRoots() {
13-
return [ActivateNode.instance];
14+
return [ActivateNode.instance, WorkshopNode.instance];
1415
}
1516
}
1617

dbux-code/src/workshop/Workshop.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const ValidCodes = new Set([]);
2+
let currentCode = '';
3+
4+
/**
5+
* @param {string} code
6+
* @returns {boolean}
7+
*/
8+
export function isValidCode(code) {
9+
return ValidCodes.has(code);
10+
}
11+
12+
export function activateWorkshopSession(code) {
13+
if (isValidCode(code)) {
14+
currentCode = code;
15+
}
16+
else {
17+
throw new Error('Invalid workshop code');
18+
}
19+
}
20+
21+
export function isWorkshopSessionActive() {
22+
return !!currentCode;
23+
}
24+
25+
export function getCurrentWorkshopCode() {
26+
return currentCode;
27+
}

0 commit comments

Comments
 (0)