diff --git a/plugin/preload.js b/plugin/preload.js
index 9c1d14b..cda48c2 100644
--- a/plugin/preload.js
+++ b/plugin/preload.js
@@ -212,22 +212,22 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
}
let getCommandToLaunchTerminal = (cmdline, dir) => {
- let cd = ''
- if (utools.isWindows()) {
- let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
- // 直接 existsSync wt.exe 无效
- if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
- cmdline = cmdline.replace(/"/g, `\\"`)
- if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
- command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
+ let cd = ''
+ if (utools.isWindows()) {
+ let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
+ // 直接 existsSync wt.exe 无效
+ if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
+ cmdline = cmdline.replace(/"/g, `\\"`)
+ if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
+ command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
+ } else {
+ cmdline = cmdline.replace(/"/g, `^"`)
+ if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
+ command = `${cd} start "" cmd /k "${cmdline}"`
+ }
} else {
- cmdline = cmdline.replace(/"/g, `^"`)
- if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
- command = `${cd} start "" cmd /k "${cmdline}"`
- }
- } else {
- cmdline = cmdline.replace(/"/g, `\\"`)
- if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
+ cmdline = cmdline.replace(/"/g, `\\"`)
+ if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
if (fs.existsSync('/Applications/iTerm.app')) {
command = `osascript -e 'tell application "iTerm"
create window with default profile
@@ -476,12 +476,11 @@ let getSandboxFuns = () => {
var sandbox = {
fetch: fetch.bind(window),
utools: getuToolsLite(),
- quickcommand: _.cloneDeep(quickcommand),
electron,
axios,
Audio,
_,
- // 兼容老版本
+ // 兼容老版本
fs,
path,
os,
@@ -503,17 +502,17 @@ let liteErr = e => {
utools.isDev() && (window.godMode = code => eval(code))
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
-window.evalCodeInSandbox = (code, userVars = {}) => {
- let sandboxWithUV = Object.assign(userVars, getSandboxFuns())
+window.evalCodeInSandbox = (code, addVars = {}) => {
+ let sandboxWithAD = Object.assign(addVars, getSandboxFuns())
try {
- return new Compartment(sandboxWithUV).evaluate(code);
+ return new Compartment(sandboxWithAD).evaluate(code);
} catch (error) {
throw liteErr(error)
}
}
let isWatchingError = false
-window.runCodeInSandbox = (code, callback, userVars = {}) => {
+window.runCodeInSandbox = (code, callback, addVars = {}) => {
let sandbox = getSandboxFuns()
sandbox.console = {
log: (...stdout) => {
@@ -524,9 +523,9 @@ window.runCodeInSandbox = (code, callback, userVars = {}) => {
callback(null, parseStdout(stderr))
}
}
- let sandboxWithUV = Object.assign(userVars, sandbox)
+ let sandboxWithAD = Object.assign(addVars, sandbox)
try {
- new Compartment(sandboxWithUV).evaluate(code)
+ new Compartment(sandboxWithAD).evaluate(code)
} catch (e) {
console.log('Error: ', e)
callback(null, liteErr(e))
@@ -629,7 +628,7 @@ window.quickcommandHttpServer = () => {
// 错误返回 500
if (stderr) return httpResponse(res, 500, stderr)
return httpResponse(res, 200, stdout)
- }, userVars)
+ }, Object.assign(userVars, _.cloneDeep(quickcommand)))
}
httpServer = http.createServer()
httpServer.on('request', (req, res) => {
diff --git a/quasar.config.js b/quasar.config.js
index bda48b9..ca7070f 100644
--- a/quasar.config.js
+++ b/quasar.config.js
@@ -117,7 +117,7 @@ module.exports = configure(function(ctx) {
// directives: [],
// Quasar plugins
- plugins: ['Dialog', 'Notify']
+ plugins: ['Notify']
},
// animations: 'all', // --- includes all animations
@@ -258,4 +258,4 @@ module.exports = configure(function(ctx) {
}
}
-});
\ No newline at end of file
+});
diff --git a/src/App.vue b/src/App.vue
index d20e878..12c22da 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -2,6 +2,7 @@
+
diff --git a/src/components/quickFeatures/FavFile.vue b/src/components/quickFeatures/FavFile.vue
index 60eada1..107b665 100644
--- a/src/components/quickFeatures/FavFile.vue
+++ b/src/components/quickFeatures/FavFile.vue
@@ -2,7 +2,7 @@
export default {
mounted() {
utools.setExpendHeight(0);
- quickcommand.enterData.payload.forEach((file) => {
+ this.$root.payload.forEach((file) => {
let uid = this.getUid();
let fileInfo = window.getFileInfo({
type: "file",
diff --git a/src/components/quickFeatures/FavUrl.vue b/src/components/quickFeatures/FavUrl.vue
index 3d1ffb3..d189903 100644
--- a/src/components/quickFeatures/FavUrl.vue
+++ b/src/components/quickFeatures/FavUrl.vue
@@ -24,7 +24,7 @@ export default {
);
url = choise.text + "://" + url;
}
- let title = quickcommand.enterData.payload.title
+ let title = this.$root.payload.title
.replace(/和另外 \d+ 个页面.*/, "")
.replace(/[-|—] .*?[Edge|Firefox|Chrome].*/, "")
.trim();
diff --git a/src/components/quickcommandUI/ButtonBox.vue b/src/components/quickcommandUI/ButtonBox.vue
index 1fad269..e20c357 100644
--- a/src/components/quickcommandUI/ButtonBox.vue
+++ b/src/components/quickcommandUI/ButtonBox.vue
@@ -1,21 +1,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/quickcommandUI/InputBox.vue b/src/components/quickcommandUI/InputBox.vue
index 02624d7..d203286 100644
--- a/src/components/quickcommandUI/InputBox.vue
+++ b/src/components/quickcommandUI/InputBox.vue
@@ -1,63 +1,41 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/quickcommandUI/SelectList.vue b/src/components/quickcommandUI/SelectList.vue
index 6b051e9..4826394 100644
--- a/src/components/quickcommandUI/SelectList.vue
+++ b/src/components/quickcommandUI/SelectList.vue
@@ -1,66 +1,54 @@
-
-
-
-
-
-
- {{ item }}
-
-
-
-
-
- {{ item.title }}
- {{
- item.description
- }}
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+ {{ item }}
+
+
+
+
+
+ {{ item.title }}
+ {{
+ item.description
+ }}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/quickcommandUI/TextArea.vue b/src/components/quickcommandUI/TextArea.vue
index 664f239..52375c2 100644
--- a/src/components/quickcommandUI/TextArea.vue
+++ b/src/components/quickcommandUI/TextArea.vue
@@ -1,65 +1,43 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/src/js/options/specialVars.js b/src/js/options/specialVars.js
index e2433e2..303b29d 100644
--- a/src/js/options/specialVars.js
+++ b/src/js/options/specialVars.js
@@ -8,10 +8,10 @@ let escapeItem = item => {
return item.replace('$', '$$$')
}
-let handlingJsonVar = (jsonVar, name) => {
+let handlingJsonVar = (jsonVar, name, payload) => {
try {
return escapeItem(window.evalCodeInSandbox(jsonVar.slice(2, -2), {
- [name]: quickcommand.enterData.payload
+ [name]: payload
}))
} catch (e) {
return utools.showNotification(e)
@@ -73,7 +73,7 @@ const specialVars = {
label: "{{input}}",
desc: "主输入框的文本",
match: /{{input}}/mg,
- repl: () => quickcommand.enterData.payload
+ repl: (text, enterData) => enterData.payload
},
pwd: {
name: "pwd",
@@ -88,21 +88,21 @@ const specialVars = {
desc: "当前窗口信息,JSON格式,可以指定键值,如{{WindowInfo.id}}",
type: "json",
match: /{{WindowInfo(.*?)}}/mg,
- repl: jsonVar => handlingJsonVar(jsonVar, "WindowInfo")
+ repl: (jsonVar, enterData) => handlingJsonVar(jsonVar, "WindowInfo", enterData.payload)
},
MatchImage: {
name: "MatchImage",
label: "{{MatchImage}}",
desc: "匹配到图片的 DataUrl",
match: /{{MatchImage}}/mg,
- repl: () => quickcommand.enterData.payload
+ repl: (text, enterData) => enterData.payload
},
SelectFile: {
name: "SelectFile",
label: "{{SelectFile}}",
desc: "文件管理器选中的文件,不支持Linux",
match: /{{SelectFile}}/mg,
- repl: () => window.getSelectFile(quickcommand.enterData.payload.id)
+ repl: (text, enterData) => window.getSelectFile(enterData.payload.id)
},
MatchedFiles: {
name: "MatchedFiles",
@@ -110,14 +110,14 @@ const specialVars = {
desc: "匹配的文件,JSON格式,可以指定键值,如{{MatchedFiles[0].path}}",
type: "json",
match: /{{MatchedFiles(.*?)}}/mg,
- repl: jsonVar => handlingJsonVar(jsonVar, "MatchedFiles")
+ repl: (jsonVar, enterData) => handlingJsonVar(jsonVar, "MatchedFiles", enterData.payload)
},
type: {
name: "type",
label: "{{type}}",
desc: "onPluginEnter的type,匹配的类型",
match: /{{type}}/mg,
- repl: () => quickcommand.enterData.type
+ repl: (text, enterData) => enterData.type
},
payload: {
name: "payload",
@@ -125,7 +125,7 @@ const specialVars = {
desc: "onPluginEnter的payload,当为JSON时可以指定键值,如{{payload.id}}",
type: "json",
match: /{{payload(.*?)}}/mg,
- repl: jsonVar => handlingJsonVar(jsonVar, "payload")
+ repl: (jsonVar, enterData) => handlingJsonVar(jsonVar, "payload", enterData.payload)
},
js: {
name: "js",
diff --git a/src/js/quickcommand.js b/src/js/quickcommand.js
deleted file mode 100644
index dd2290d..0000000
--- a/src/js/quickcommand.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- * 通过quickcommand的api,快速生成可交互的UI界面
- * UI界面基于quasar
- */
-
-import {
- Dialog,
- Notify
-} from 'quasar'
-import inputBox from "../components/quickcommandUI/InputBox"
-import buttonBox from "../components/quickcommandUI/ButtonBox"
-import TextArea from "../components/quickcommandUI/TextArea"
-import SelectList from "../components/quickcommandUI/SelectList"
-import WaitButton from "../components/quickcommandUI/waitButton"
-
-const quickcommand = {
- showInputBox: (options = ["请输入"], title = "") => new Promise((reslove, reject) => {
- let props = {
- labels: [],
- values: [],
- hints: [],
- title: title
- }
- if (!_.isObject(options)) return reject(new TypeError(`应为 Object, 而非 ${typeof options}`))
- if (_.isArray(options)) props.labels = options
- else Object.assign(props, options)
- Dialog.create({
- component: inputBox,
- componentProps: props
- }).onOk(results => {
- reslove(Array.from(results))
- }).onCancel(() => {
- console.log('取消')
- })
- }),
-
- showButtonBox: (labels = ["确定"], title = "") => new Promise((reslove, reject) => {
- if (!_.isArray(labels)) return reject(new TypeError(`应为 Array, 而非 ${typeof labels}`))
- let props = {
- labels: labels,
- title: title
- }
- Dialog.create({
- component: buttonBox,
- componentProps: props
- }).onOk(results => {
- reslove(results)
- }).onCancel(() => {
- console.log('取消')
- })
- }),
-
-
- showConfirmBox: (message = "", title = "提示") => new Promise((reslove, reject) => {
- Dialog.create({
- title: title,
- message: message,
- cancel: true,
- persistent: true
- }).onOk(() => {
- reslove(true)
- }).onCancel(() => {
- reslove(false)
- })
- }),
-
- showMessageBox: (message, icon = 'success', time = 3000) => {
- if (icon === 'success') icon = 'positive'
- if (icon === 'error') icon = 'negative'
- Notify.create({
- type: icon,
- message: message,
- timeout: time,
- position: 'top',
- })
- },
-
- showTextArea: (placeholder = "", value = "") => new Promise((reslove, reject) => {
- let props = {
- placeholder: placeholder,
- value: value
- }
- Dialog.create({
- component: TextArea,
- componentProps: props
- }).onOk(results => {
- reslove(results)
- }).onCancel(() => {
- console.log('取消')
- })
- }),
-
- showSelectList: (selects, options = {}) => new Promise((reslove, reject) => {
- if (!_.isArray(selects)) return reject(new TypeError(`应为 Array, 而非 ${typeof selects}`))
- let defaultOptions = {
- placeholder: "输入进行筛选,支持拼音",
- optionType: "plaintext",
- enableSearch: true,
- showCancelButton: false,
- closeOnSelect: true
- }
- Object.assign(defaultOptions, options)
- let props = {
- initItems: selects,
- options: defaultOptions
- }
- Dialog.create({
- component: SelectList,
- componentProps: props
- }).onOk(results => {
- reslove(results)
- }).onCancel(() => {
- console.log('取消')
- })
- }),
-
- showWaitButton: (callback, label = "确定") => {
- Dialog.create({
- component: WaitButton,
- componentProps: {
- label
- }
- }).onOk(() => {
- callback()
- }).onCancel(() => {
- console.log('取消')
- })
- }
-}
-
-export default quickcommand
\ No newline at end of file
diff --git a/src/pages/ConfigurationPage.vue b/src/pages/ConfigurationPage.vue
index 2a4c285..b26ead5 100644
--- a/src/pages/ConfigurationPage.vue
+++ b/src/pages/ConfigurationPage.vue
@@ -315,8 +315,8 @@ export default {
initPage() {
// 如果从 newcommand 进入则直接新建命令
if (this.newCommandDirect) {
- if (quickcommand.enterData.type === "text") this.addNewCommand();
- else this.editCommand(JSON.parse(quickcommand.enterData.payload));
+ if (this.$root.enterData.type === "text") this.addNewCommand();
+ else this.editCommand(JSON.parse(this.$root.enterData.payload));
this.$router.push("/configuration");
}
// 已启用的 features
diff --git a/src/plugins/monaco/types/quickcommand.api.d.ts b/src/plugins/monaco/types/quickcommand.api.d.ts
index c669db7..3c37eb6 100644
--- a/src/plugins/monaco/types/quickcommand.api.d.ts
+++ b/src/plugins/monaco/types/quickcommand.api.d.ts
@@ -174,8 +174,10 @@ interface quickcommandApi {
/**
* 关掉现有等待操作按钮
+ *
+ * 正常会在退出运行结果界面后自动关闭,也可手动关闭
*/
- closeWaitBtn(): void;
+ closeWaitButton(): void;
/**
* 监听用户按键,并执行回调函数
@@ -192,6 +194,13 @@ interface quickcommandApi {
*/
listenKeydown(callback: (event) => void): void;
+ /**
+ * 移除所有按键监听
+ *
+ * 正常会在退出运行结果界面后自动移除,也可手动移除
+ */
+ removeListener(): void;
+
/**
* 同步等待,会阻塞进程
* @param ms 等待的毫秒数
diff --git a/src/router/index.js b/src/router/index.js
index eb90998..ee8c0c3 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,9 +1,6 @@
import { route } from 'quasar/wrappers'
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
import routes from './routes'
-import quickcommandUI from '../js/quickcommand'
-
-Object.assign(window.quickcommand, quickcommandUI)
/*
* If not building with SSR mode, you can
@@ -14,20 +11,20 @@ Object.assign(window.quickcommand, quickcommandUI)
* with the Router instance.
*/
-export default route(function (/* { store, ssrContext } */) {
- const createHistory = process.env.SERVER
- ? createMemoryHistory
- : (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory)
+export default route(function( /* { store, ssrContext } */ ) {
+ const createHistory = process.env.SERVER ?
+ createMemoryHistory :
+ (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory)
- const Router = createRouter({
- scrollBehavior: () => ({ left: 0, top: 0 }),
- routes,
+ const Router = createRouter({
+ scrollBehavior: () => ({ left: 0, top: 0 }),
+ routes,
- // Leave this as is and make changes in quasar.conf.js instead!
- // quasar.conf.js -> build -> vueRouterMode
- // quasar.conf.js -> build -> publicPath
- history: createHistory(process.env.MODE === 'ssr' ? void 0 : process.env.VUE_ROUTER_BASE)
- })
+ // Leave this as is and make changes in quasar.conf.js instead!
+ // quasar.conf.js -> build -> vueRouterMode
+ // quasar.conf.js -> build -> publicPath
+ history: createHistory(process.env.MODE === 'ssr' ? void 0 : process.env.VUE_ROUTER_BASE)
+ })
- return Router
+ return Router
})