-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
46 lines (42 loc) · 1.07 KB
/
preload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const cp = require('child_process');
const { getAllOpenedRecentFiles } = require('./open_recent');
let cache;
window.exports = {
"xhistory": {
mode: "list",
args: {
enter: async (action, callbackSetList) => {
if (!cache) {
cache = await getAllOpenedRecentFiles();
callbackSetList(cache);
return;
}
callbackSetList(cache);
},
search: (action, searchWord, callbackSetList) => {
if (!Array.isArray(cache)) {
return;
}
const searchList = cache.filter((item) => {
return item.title.toLowerCase().includes(searchWord);
});
callbackSetList(searchList);
},
select: (action, itemData, callbackSetList) => {
const url = itemData.url;
window.utools.hideMainWindow();
cp.exec(`/usr/local/bin/code ${url}`, (err) => {
if (err) {
callbackSetList({
title: 'error',
description: '打开文件出错,联系开发者',
url: '',
});
}
window.utools.outPlugin();
});
},
placeholder: "搜索项目名称"
}
}
}