Skip to content

Commit

Permalink
feat: vscode 支持多设备使用
Browse files Browse the repository at this point in the history
  • Loading branch information
mohuishou committed Apr 5, 2021
1 parent 682c8d8 commit 6e2a443
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion helper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "utools-helper",
"version": "1.4.6",
"version": "1.5.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
20 changes: 14 additions & 6 deletions helper/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Option } from "./selectConfig";
export interface IConfig {
// 配置项的名字. 存储到DB的key
name: string;
key: string;
// 配置项的title,仅用于显示,默认值等于 name
label?: string;
// 配置项说明
Expand Down Expand Up @@ -41,7 +42,7 @@ export interface IConfigItem {
}

export abstract class Config implements IConfig {
// 配置项的名字. 存储到DB的key
// 配置项的名字
name: string;
// 配置项的title,仅用于显示,默认值等于 name
label?: string;
Expand All @@ -53,14 +54,23 @@ export abstract class Config implements IConfig {
required?: boolean;
// 输入提示项,展示在输入框下面
tips?: string;
// 每个机器上都保持不同配置
only_current_machine?: boolean;

get key(): string {
if (this.only_current_machine) {
return utools.getLocalId() + "." + this.name;
}
return this.name;
}

get value(): any {
let data = utools.db.get("config");
if (data && this.name in data.data) return data.data[this.name];
if (data && this.key in data.data) return data.data[this.key];

// 值不存在,初始化,并且保存
if (!data) data = { _id: "config", data: {} };
data.data[this.name] = this.default;
data.data[this.key] = this.default;
let res = utools.db.put(data);
if (!res.ok) throw new Error(res.error);

Expand All @@ -86,9 +96,7 @@ export abstract class Config implements IConfig {

constructor(item: IConfigItem) {
this.name = item.name;
if (item.only_current_machine) {
this.name = utools.getLocalId() + "." + item.name;
}
this.only_current_machine = item.only_current_machine;
this.label = item.label ? item.label : item.name;
this.placeholder = item.placeholder ? item.placeholder : "请输入" + item.name;
this.default = item.default;
Expand Down
2 changes: 1 addition & 1 deletion helper/src/config/inputConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class InputConfig extends Config {
<input type="text" autocomplete="off" class="layui-input"
${this.required ? 'lay-verify="required" required' : ""}
placeholder="${this.placeholder}"
name="${this.name}"
name="${this.key}"
value="${this.value}"
/>
`;
Expand Down
2 changes: 1 addition & 1 deletion helper/src/config/selectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SelectConfig extends Config {
<select
${this.required ? 'lay-verify="required" required' : ""}
placeholder="${this.placeholder}"
name="${this.name}"
name="${this.key}"
value="${this.value}"
>
${this.options
Expand Down
15 changes: 7 additions & 8 deletions helper/src/config/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ function stopKeyDown(event: any) {
export class Setting implements Plugin {
code: string;
configs: IConfig[] = [];
configMap: Map<string, IConfig> = new Map<string, IConfig>();

private static _instance: Setting;

static Get(key: string): any {
let config = utools.db.get("config");
if (config && key in config.data) return config.data[key];
for (let i = 0; i < this._instance.configs.length; i++) {
const conf = this._instance.configs[i];
if (conf.name === key) return conf.default;
}
return;
return this._instance.configMap.get(key).value;
}

static Set(key: string, val: any) {
let c = this._instance.configMap.get(key);
let config = utools.db.get("config");
if (!config) config = { _id: "config", data: {} };
config.data[key] = val;
config.data[c.key] = val;
let res = utools.db.put(config);
if (!res.ok) throw new Error("数据查询失败" + res.error);
}
Expand Down Expand Up @@ -55,6 +51,9 @@ export class Setting implements Plugin {
textarea: (item: IConfigItem) => new TextareaConfig(item),
}[item.type](item);
});
this.configs.forEach((c) => {
this.configMap.set(c.name, c);
});
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion helper/src/config/textareaConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class TextareaConfig extends Config {
<textarea autocomplete="off" class="layui-textarea"
${this.required ? 'lay-verify="required" required' : ""}
placeholder="${this.placeholder}"
name="${this.name}"
name="${this.key}"
/>${this.value}</textarea>
`;
}
Expand Down
7 changes: 7 additions & 0 deletions plugins/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ utools 插件,搜索 vscode 历史项目,点击回车打开

### 更新

#### v3.1.0

- 支持 vscode 1.55.0
- 全新配置页面
- 支持多设备多操作系统使用


#### v2.0.4

fix(vsc): 修复 code 命令无法打开项目 #15 #16
Expand Down
8 changes: 4 additions & 4 deletions plugins/vscode/package-lock.json

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

2 changes: 1 addition & 1 deletion plugins/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"@types/node": "^13.1.0"
},
"dependencies": {
"utools-helper": "^1.3.5"
"utools-helper": "^1.5.0"
}
}
2 changes: 1 addition & 1 deletion plugins/vscode/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "830ef6d0",
"pluginName": "vscode",
"description": "快速搜索vscode历史项目并且在vscode中打开",
"version": "v3.0.3",
"version": "v3.1.0",
"preload": "dist/preload.js",
"author": "莫回首",
"homepage": "https://github.com/mohuishou/utools",
Expand Down
3 changes: 3 additions & 0 deletions plugins/vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const config: IConfigItem[] = [
required: false,
placeholder: "一般情况下无需修改,windows 请保持为空值",
default: defaultShell,
only_current_machine: true,
},
{
name: "code",
Expand All @@ -28,12 +29,14 @@ export const config: IConfigItem[] = [
placeholder: "vscode 命令",
required: true,
default: "code",
only_current_machine: true,
},
{
name: "storage",
label: "storage",
type: "input",
required: true,
only_current_machine: true,
default: join(utools.getPath("appData"), "Code", "storage.json"),
},
];

0 comments on commit 6e2a443

Please sign in to comment.