-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
qwertyyb
committed
Feb 7, 2021
1 parent
df821f7
commit 576f386
Showing
6 changed files
with
121 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require('fs') | ||
|
||
const macosAppPaths = [ | ||
'/System/Applications', // 系统应用 | ||
'/Applications', // 安装的应用 | ||
] | ||
|
||
const getMacosApps = async (paths: String[]) => { | ||
const dirApps = await Promise.all(paths.map(async (path) => { | ||
const dir = await fs.promises.opendir(path); | ||
return fs.readdirSync(path); // @todo 遍历目录 | ||
})); | ||
return dirApps.flat() | ||
}; | ||
|
||
class AppLauncher { | ||
code = 'launcher' | ||
data = { | ||
list: [''] | ||
} | ||
async onCreate () { | ||
this.data.list = await getMacosApps(macosAppPaths) | ||
} | ||
async onActive (setList: Function) { | ||
setList(this.data.list) | ||
} | ||
async onSearch (keyword = '', setList: Function) { | ||
setList(this.data.list.filter(name => name.includes(keyword))) | ||
} | ||
} | ||
export default new AppLauncher() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const candidateList = [ | ||
{ | ||
code: 'lock', | ||
title: '锁屏', | ||
icon: '<span class="material-icons md-36 candidate-icon">lock</span>', | ||
commad: 'lock', | ||
action: () => { | ||
const { exec } = require('child_process'); | ||
|
||
const lock = (cb, customCommands) => { | ||
const lockCommands = customCommands || { | ||
darwin: `open -a ScreenSaverEngine`, | ||
win32: 'rundll32.exe user32.dll, LockWorkStation', | ||
linux: '(hash gnome-screensaver-command 2>/dev/null && gnome-screensaver-command -l) || (hash dm-tool 2>/dev/null && dm-tool lock)' | ||
}; | ||
|
||
if(Object.keys(lockCommands).indexOf(process.platform) === -1) { | ||
throw new Error(`lockscreen doesn't support your platform (${process.platform})`); | ||
} else { | ||
exec(lockCommands[process.platform], (err, stdout) => { | ||
console.log('callback', err, stdout) | ||
}); | ||
} | ||
} | ||
lock() | ||
} | ||
}, | ||
{ | ||
code: 'wx', | ||
title: '微信', | ||
icon: '<span class="material-icons md-36 candidate-icon">message</span>', | ||
command: 'lanch app: wechat' | ||
} | ||
] | ||
|
||
const itemTemplate = (data) => `<li class="candidate-item"> | ||
${data.icon} | ||
<div class="candidate-title">${data.title}</div> | ||
<div class="candidate-subtitle">${data.subtitle || ''}</div> | ||
</li>` | ||
|
||
document.querySelector('.candidate-list').addEventListener('click', e => { | ||
candidateList[0].action() | ||
}) | ||
|
||
document.querySelector('.input').addEventListener('input', (e) => { | ||
const val = e.target.value; | ||
if (!val.length) { | ||
document.querySelector('.candidate-list').style.display = 'none' | ||
} | ||
const html = candidateList.filter(item => item.code.includes(val)).map(itemTemplate).join('') | ||
document.querySelector('.candidate-list').innerHTML = html | ||
return document.querySelector('.candidate-list').style.display = 'block' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = require('fs'); | ||
const macosAppPaths = [ | ||
'/System/Applications', | ||
'/Applications', | ||
]; | ||
const getMacosApps = async (paths) => { | ||
const dirApps = await Promise.all(paths.map(async (path) => { | ||
const dir = await fs.promises.opendir(path); | ||
return fs.readdirSync(path); // @todo 遍历目录 | ||
})); | ||
return dirApps.flat(); | ||
}; | ||
class AppLauncher { | ||
constructor() { | ||
this.code = 'launcher'; | ||
this.data = { | ||
list: [''] | ||
}; | ||
} | ||
async onCreate() { | ||
this.data.list = await getMacosApps(macosAppPaths); | ||
} | ||
async onActive(setList) { | ||
setList(this.data.list); | ||
} | ||
async onSearch(keyword = '', setList) { | ||
setList(this.data.list.filter(name => name.includes(keyword))); | ||
} | ||
} | ||
exports.default = new AppLauncher(); |