Skip to content

Commit

Permalink
feat: support open setup
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 22, 2024
1 parent cd39828 commit 987a95a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 22 deletions.
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"publisher": "oeyoews",
"name": "usewiki2",
"displayName": "usewiki2",
"version": "0.3.1",
"version": "0.4.0",
"private": true,
"packageManager": "[email protected]",
"description": "",
Expand Down Expand Up @@ -80,6 +80,11 @@
"group": "navigation",
"when": "view == usewiki2"
},
{
"command": "usewiki2.opensettings",
"group": "navigation",
"when": "view == usewiki2"
},
{
"command": "usewiki2.wikiinfo",
"group": "navigation",
Expand Down Expand Up @@ -129,6 +134,11 @@
"command": "usewiki2.refreshwiki",
"title": "Refresh",
"icon": "$(refresh)"
},
{
"command": "usewiki2.opensettings",
"title": "设置",
"icon": "$(gear)"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions src/commands/openSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as vscode from 'vscode';

export async function cli() {
const searchQuery = '@ext:oeyoews.usewiki2';
vscode.commands.executeCommand('workbench.action.openSettings', searchQuery);
}

export const name = 'usewiki2.opensettings';
7 changes: 7 additions & 0 deletions src/commands/refreshWiki.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { notify } from '../notify';

export async function cli() {
notify('开发中', 'info');
}

export const name = 'usewiki2.refreshwiki';
4 changes: 2 additions & 2 deletions src/commands/wikiInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';

export default async function wikiInfoCmd() {
export async function cli() {
// 居中弹窗显示详情
vscode.window
.showInformationMessage('wikiinfo', 'version', 'username')
Expand All @@ -11,4 +11,4 @@ export default async function wikiInfoCmd() {
});
}

export const wikiInfoCli = 'usewiki2.wikiinfo';
export const name = 'usewiki2.wikiinfo';
25 changes: 12 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import * as vscode from 'vscode';
import { usewikiViewProvider } from './webviews';

import usewikiCmd, { usewikiCli } from './usewikiCmd';
import openWikiCmd, { openWikiCli } from './openWikiCmd';
import wikiInfoCmd, { wikiInfoCli } from './commands/wikiInfo';
import * as usewikiCmd from './usewikiCmd';
import * as openWiki from './openWikiCmd';
import * as wikiInfo from './commands/wikiInfo';
import * as opensetting from './commands/openSettings';
import * as refreshWiki from './commands/refreshWiki';

export async function activate(context: vscode.ExtensionContext) {
const provider = new usewikiViewProvider(context);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider('usewiki2', provider)
);
const disposable = vscode.commands.registerCommand(usewikiCli, usewikiCmd);
const openDisposable = vscode.commands.registerCommand(
openWikiCli,
openWikiCmd
);
const wikiInfoDisposable = vscode.commands.registerCommand(
wikiInfoCli,
wikiInfoCmd
);

context.subscriptions.push(disposable, openDisposable);
const cmds = [opensetting, wikiInfo, openWiki, usewikiCmd, refreshWiki];

// 注册命令
cmds.forEach((cmd: { name: string; cli: any }) => {
const disposable = vscode.commands.registerCommand(cmd.name, cmd.cli);
context.subscriptions.push(disposable);
});
}
4 changes: 2 additions & 2 deletions src/openWikiCmd.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as vscode from 'vscode';
import { getIp, getPort, enableHttps } from './config';

export default async function openWikiCmd() {
export function cli() {
const protocal = enableHttps() ? 'https' : 'http';
const url = `${protocal}://${getIp()}:${getPort()}`;

vscode.env.openExternal(vscode.Uri.parse(url));
}

export const openWikiCli = 'usewiki2.openwiki';
export const name = 'usewiki2.openwiki';
4 changes: 2 additions & 2 deletions src/usewikiCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as vscode from 'vscode';
import sendTiddler from './sendTiddler';
import { getType } from './config';

export const usewikiCli = 'usewiki2.tiddlywiki';
export default async function usewikiCmd() {
export const name = 'usewiki2.tiddlywiki';
export async function cli() {
const newdata = await fetchData();
const random = Math.random().toString(36).slice(2);
let title = new Date().toLocaleString().split(' ').shift() + '-' + random;
Expand Down
4 changes: 2 additions & 2 deletions src/webviews/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import fetchData from '../featchData';
import sendTiddler from '../sendTiddler';
import openWikiCmd from '../openWikiCmd';
import * as openWikiCmd from '../openWikiCmd';
import { getType } from '../config';

export class usewikiViewProvider implements vscode.WebviewViewProvider {
Expand Down Expand Up @@ -30,7 +30,7 @@ export class usewikiViewProvider implements vscode.WebviewViewProvider {
webviewView.webview.onDidReceiveMessage(async (message) => {
switch (message.type) {
case 'openWiki':
openWikiCmd();
openWikiCmd.cli();
break;
case 'sendWiki':
const random = Math.random().toString(36).slice(2);
Expand Down

0 comments on commit 987a95a

Please sign in to comment.