Skip to content

Commit

Permalink
feat: 优化vscode插件
Browse files Browse the repository at this point in the history
Merge pull request #102 from xyeluo/master
  • Loading branch information
mohuishou authored Sep 6, 2024
2 parents 8a4eb8a + 34a35ac commit d4ce5f2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 46 deletions.
2 changes: 1 addition & 1 deletion helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"dev": "cp -r src/layui dist/ && tsc -w",
"build": "rm -r dist && tsc && cp -r src/layui dist/",
"build": "rm -rf dist && tsc && cp -r src/layui dist/",
"prepare": "npm run build"
},
"publishConfig": {
Expand Down
12 changes: 10 additions & 2 deletions helper/src/config/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Setting implements Plugin {
return {
input: (item: IConfigItem) => new InputConfig(item),
select: (item: IConfigItem) => new SelectConfig(item),
textarea: (item: IConfigItem) => new TextareaConfig(item),
textarea: (item: IConfigItem) => new TextareaConfig(item)
}[item.type](item);
});
this.configs.forEach((c) => {
Expand Down Expand Up @@ -79,8 +79,16 @@ export class Setting implements Plugin {
text-align: center;
margin-top: 10px;
}
.dark-theme, .dark-theme a {
color: white;
}
.dark-theme a:hover {
color: #777;
}
</style>
<form id="config" class="layui-form" action="">
<form id="config" class='layui-form ${
utools.isDarkColors() ? "dark-theme" : ""
}' action="">
${this.configs.map((c) => c.html()).join("\n")}
<footer> <a href="https://github.com/mohuishou/utools"> power by ⭐ utools-helper </a> </footer>
<button id="save" type="submit" class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="config">保存</button>
Expand Down
23 changes: 19 additions & 4 deletions helper/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@
# yarn lockfile v1


"@types/node@^15.0.1":
version "15.0.1"
resolved "https://registry.nlark.com/@types/node/download/@types/node-15.0.1.tgz?cache=0&sync_timestamp=1619534647758&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-15.0.1.tgz#ef34dea0881028d11398be5bf4e856743e3dc35a"
integrity sha1-7zTeoIgQKNETmL5b9OhWdD49w1o=
"@types/node@^15.12.4":
version "15.14.9"
resolved "https://registry.npmmirror.com/@types/node/-/node-15.14.9.tgz#bc43c990c3c9be7281868bbc7b8fdd6e2b57adfa"
integrity sha512-qjd88DrCxupx/kJD5yQgZdcYKZKSIGBVDIBE1/LTGcNm3d2Np/jxojkdePDdfnBHJc5W7vSMpbJ1aB7p/Py69A==

"@types/throttle-debounce@^2.1.0":
version "2.1.0"
resolved "https://registry.npmmirror.com/@types/throttle-debounce/-/throttle-debounce-2.1.0.tgz#1c3df624bfc4b62f992d3012b84c56d41eab3776"
integrity sha512-5eQEtSCoESnh2FsiLTxE121IiE60hnMqcb435fShf4bpLRjEu1Eoekht23y6zXS9Ts3l+Szu3TARnTsA0GkOkQ==

throttle-debounce@^3.0.1:
version "3.0.1"
resolved "https://registry.npmmirror.com/throttle-debounce/-/throttle-debounce-3.0.1.tgz#32f94d84dfa894f786c9a1f290e7a645b6a19abb"
integrity sha512-dTEWWNu6JmeVXY0ZYoPuH5cRIwc0MeGbJwah9KUNYSJwommQpCzTySTpEe8Gs1J23aeWEuAobe4Ag7EHVt/LOg==

typescript@^4.2.4:
version "4.2.4"
resolved "https://registry.nlark.com/typescript/download/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha1-hhC1l0feAo/aiYqK7w4QPxVtCWE=

utools-api-types@^2.0.3:
version "2.6.4"
resolved "https://registry.npmmirror.com/utools-api-types/-/utools-api-types-2.6.4.tgz#56c08e94e4af85f179a2eb95f9cb42f029e6c33f"
integrity sha512-pJuGvjSScwePuc6F/PVtL6DSCm+XzF78CBKxFUU82FON4vB8MGDXPCp6Y/25T/ndKyiyFj1zCR8ObyxtdikzPg==
52 changes: 31 additions & 21 deletions plugins/vscode/src/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin, ListItem, Setting } from "utools-helper";
import { basename, join, extname } from "path";
import { readdirSync, readFileSync } from "fs";
import { execSync } from "child_process";
import { ExecOptions, exec } from "child_process";
import { GetFiles } from "./files";

export class VSCode implements Plugin {
Expand All @@ -21,7 +21,7 @@ export class VSCode implements Plugin {
* 在 1.64 版本之前获取文件列表
*/
before164Files() {
let data = JSON.parse(readFileSync(Setting.Get("storage")).toString())
let data = JSON.parse(readFileSync(Setting.Get("storage")).toString());
let files: Array<any> = [];
for (const key in data.openedPathsList) {
if (
Expand Down Expand Up @@ -50,7 +50,7 @@ export class VSCode implements Plugin {
try {
return await GetFiles(this.storage);
} catch (error) {
return this.before164Files()
return this.before164Files();
}
}

Expand All @@ -74,14 +74,12 @@ export class VSCode implements Plugin {
});
});

let items = files.map(
(file: any): ListItem => {
let item = new ListItem(basename(file), file);
let ext = file.includes("remote") ? ".remote" : extname(file);
item.icon = this.getIcon(ext);
return item;
}
);
let items = files.map((file: any): ListItem => {
let item = new ListItem(basename(file), file);
let ext = file.includes("remote") ? ".remote" : extname(file);
item.icon = this.getIcon(ext);
return item;
});

if (!word.trim()) {
let collects = this.getCollect();
Expand Down Expand Up @@ -122,6 +120,19 @@ export class VSCode implements Plugin {
utools.showNotification(`${item.title} 置顶已移除`);
}

private execCmd(
command: string,
options: { encoding: BufferEncoding } & ExecOptions
): Promise<string> {
return new Promise((resolve, reject) => {
exec(command, options, (_, stdout, stderr) => {
if (stderr) return reject(stderr);

resolve(stdout);
});
});
}

async select(item: ListItem) {
if (this.isCtrl) {
let items = this.getCollect();
Expand All @@ -147,20 +158,19 @@ export class VSCode implements Plugin {
console.log(cmd);

let timeout = parseInt(Setting.Get("timeout"));
if (!timeout || timeout < 3000) timeout = 3000
if (!timeout || timeout < 3000) timeout = 3000;

let res = execSync(cmd, {
this.execCmd(cmd, {
timeout: timeout,
windowsHide: true,
encoding: "utf-8",
encoding: "utf-8"
})
.toString()
.trim()
.toLowerCase();
if (res !== "" && !res.toLowerCase().includes("timeout"))
throw res.toString();

utools.hideMainWindow();
.then(() => {
utools.hideMainWindow();
})
.catch((reason) => {
throw reason.toString();
});
}

getIcon(ext: string): string {
Expand Down
41 changes: 23 additions & 18 deletions plugins/vscode/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@


"@types/emscripten@*":
"integrity" "sha512-H90aoynNhhkQP6DRweEjJp5vfUVdIj7tdPLsu7pq89vODD/lcugKfZOsfgwpvM6XUewEp2N5dCg1Uf3Qe55Dcg=="
"resolved" "https://registry.npmmirror.com/@types/emscripten/-/emscripten-1.39.6.tgz"
"version" "1.39.6"
version "1.39.6"
resolved "https://registry.npmmirror.com/@types/emscripten/-/emscripten-1.39.6.tgz"
integrity sha512-H90aoynNhhkQP6DRweEjJp5vfUVdIj7tdPLsu7pq89vODD/lcugKfZOsfgwpvM6XUewEp2N5dCg1Uf3Qe55Dcg==

"@types/node@*", "@types/node@^15.12.4":
"integrity" "sha1-4c+BfXCh4RjoGSLE/2aDzp1CLiY="
"resolved" "https://registry.nlark.com/@types/node/download/@types/node-15.12.4.tgz"
"version" "15.12.4"
"@types/node@*":
version "15.12.4"
resolved "https://registry.nlark.com/@types/node/download/@types/node-15.12.4.tgz"
integrity sha1-4c+BfXCh4RjoGSLE/2aDzp1CLiY=

"@types/node@^20.6.0":
version "20.6.0"
resolved "https://registry.npmmirror.com/@types/node/-/node-20.6.0.tgz#9d7daa855d33d4efec8aea88cd66db1c2f0ebe16"
integrity sha512-najjVq5KN2vsH2U/xyh2opaSEz6cZMR2SetLIlxlj08nOcmPOemJmUK2o4kUzfLqfrWE0PIrNeE16XhYDd3nqg==

"@types/sql.js@^1.4.3":
"integrity" "sha512-3bz1LJIiJtKMEL8tYf7c9Nrb1lYcFeWQkE8vhWvobE29ZzizW79DtoTjqx1bR82DS2Ch2K30nOwNhuLclZ1vYg=="
"resolved" "https://registry.npmmirror.com/@types/sql.js/-/sql.js-1.4.3.tgz"
"version" "1.4.3"
version "1.4.3"
resolved "https://registry.npmmirror.com/@types/sql.js/-/sql.js-1.4.3.tgz"
integrity sha512-3bz1LJIiJtKMEL8tYf7c9Nrb1lYcFeWQkE8vhWvobE29ZzizW79DtoTjqx1bR82DS2Ch2K30nOwNhuLclZ1vYg==
dependencies:
"@types/emscripten" "*"
"@types/node" "*"

"utools-api-types@^2.0.3":
"integrity" "sha1-SxJ+Mn7r1G/4U8Nyt8KAe69c4WE="
"resolved" "https://registry.nlark.com/utools-api-types/download/utools-api-types-2.0.3.tgz"
"version" "2.0.3"
utools-api-types@^2.0.3:
version "2.0.3"
resolved "https://registry.nlark.com/utools-api-types/download/utools-api-types-2.0.3.tgz"
integrity sha1-SxJ+Mn7r1G/4U8Nyt8KAe69c4WE=

"utools-helper@^2.0.0":
"integrity" "sha1-bRSwLIMaySWhxqepTxkGrxHlV1o="
"resolved" "https://registry.nlark.com/utools-helper/download/utools-helper-2.0.0.tgz?cache=0&sync_timestamp=1624256839035&other_urls=https%3A%2F%2Fregistry.nlark.com%2Futools-helper%2Fdownload%2Futools-helper-2.0.0.tgz"
"version" "2.0.0"
utools-helper@^2.0.0:
version "2.0.0"
resolved "https://registry.nlark.com/utools-helper/download/utools-helper-2.0.0.tgz?cache=0&sync_timestamp=1624256839035&other_urls=https%3A%2F%2Fregistry.nlark.com%2Futools-helper%2Fdownload%2Futools-helper-2.0.0.tgz"
integrity sha1-bRSwLIMaySWhxqepTxkGrxHlV1o=

0 comments on commit d4ce5f2

Please sign in to comment.