Skip to content

Commit

Permalink
feat: enable, disable mode
Browse files Browse the repository at this point in the history
  • Loading branch information
changchanghwang committed Jan 24, 2024
1 parent bd2225e commit 932a5c5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ CONTRIBUTORS.md
tsconfig.json
tsconfig.build.json
package-lock.json
dist/*.map
dist/**/*.map

node_modules/
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "junbae-mode",
"displayName": "Junbae Mode",
"version": "0.0.1",
"version": "0.0.2",
"description": "Junbae is caique parrot!",
"main": "./dist/extension.js",
"publisher": "JunbaeJs",
Expand Down Expand Up @@ -54,10 +54,34 @@
},
"contributes": {
"commands": [
{
"command": "junbae-mode.enable",
"title": "Enable Junbae Mode",
"when": "!config.junbae-mode.enabled",
"enablement": "!config.junbae-mode.enabled"
},
{
"command": "junbae-mode.disable",
"title": "Disable Junbae Mode",
"when": "config.junbae-mode.enabled",
"enablement": "config.junbae-mode.enabled"
},
{
"command": "junbae-mode.helloWorld",
"title": "Hello World"
}
]
],
"configuration": {
"title": "General",
"order": 0,
"properties": {
"junbae-mode.enabled": {
"order": 0,
"default": true,
"type": "boolean",
"description": "Enable Junbae Mode"
}
}
}
}
}
Binary file added package/junbae-mode-0.0.2.vsix
Binary file not shown.
37 changes: 37 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as vscode from 'vscode';

const configurationSection = ['enabled'] as const;
type ConfigurationSection = (typeof configurationSection)[number];

export class JunbaeMode {
// configurations
enabled: boolean = true;

/**
* Enables or disables Junbae Mode
* @param enabled
*/
setEnabled(enabled: boolean) {
this.enabled = enabled;
this.updateConfig('enabled', this.enabled);
vscode.window.showInformationMessage(`Junbae Mode is ${this.enabled ? 'enabled' : 'disabled'}!🦜`);
}

/**
* Initializes Junbae Mode Configuration
*/
init() {
this.setEnabled(true);
this.updateConfig('enabled', this.enabled);
}

/**
* Updates the configuration
* @param section
* @param value
*/
private updateConfig(section: ConfigurationSection, value: any) {
const config = vscode.workspace.getConfiguration('junbae-mode');
config.update(section, value, vscode.ConfigurationTarget.Global);
}
}
14 changes: 10 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { JunbaeMode } from './core';

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "junbae-mode" is now active!🦜');
const mode = new JunbaeMode();
mode.init();

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposable = vscode.commands.registerCommand('junbae-mode.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from Junbae Mode!🦜');
if (mode.enabled) {
vscode.window.showInformationMessage('Hello World from Junbae Mode!🦜');
}
});
const enable = vscode.commands.registerCommand('junbae-mode.enable', () => mode.setEnabled(true));
const disable = vscode.commands.registerCommand('junbae-mode.disable', () => mode.setEnabled(false));

context.subscriptions.push(disposable);
context.subscriptions.push(enable);
context.subscriptions.push(disable);
}

// This method is called when your extension is deactivated
Expand Down

0 comments on commit 932a5c5

Please sign in to comment.