From 94fe929f37f4559360edadf1f11507f2f817d226 Mon Sep 17 00:00:00 2001 From: gucovip Date: Wed, 25 Dec 2019 09:39:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E6=8B=96?= =?UTF-8?q?=E5=8A=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 6 +-- app/base_plugin/FindApp/index.js | 2 +- app/extend_plugin/Clock/index.js | 2 +- app/index.js | 50 +++++++++++++----------- app/loaders/WindowLoader/index.js | 7 ++-- app/loaders/WindowLoader/views/style.css | 2 + app/package.json | 2 +- app/utils/initialize.js | 6 +-- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 456fa6d..4dcb7a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ node_js: - "10" before_install: - - cd app && yarn - - cd .. && yarn + - cd app && npm install + - cd .. && npm install script: - - yarn pa:mac + - npm run pa:mac diff --git a/app/base_plugin/FindApp/index.js b/app/base_plugin/FindApp/index.js index 8fc153d..e81c7fb 100644 --- a/app/base_plugin/FindApp/index.js +++ b/app/base_plugin/FindApp/index.js @@ -110,4 +110,4 @@ const cache = (filePath) => { const times = searchCache[filePath] || 0 searchCache[filePath] = times + 1 fs.writeFileSync(cachePath, JSON.stringify(searchCache)) -} \ No newline at end of file +} diff --git a/app/extend_plugin/Clock/index.js b/app/extend_plugin/Clock/index.js index 1568ac1..0ef437b 100644 --- a/app/extend_plugin/Clock/index.js +++ b/app/extend_plugin/Clock/index.js @@ -27,7 +27,7 @@ function getData({query, utils: {logger, buildLine}}) { }) clockWindow.setAlwaysOnTop(true, "floating") clockWindow.setVisibleOnAllWorkspaces(true) - clockWindow.setFullScreenable(false) + clockWindow.fullScreenable = false clockWindow.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', diff --git a/app/index.js b/app/index.js index 738e7fa..e7d6720 100644 --- a/app/index.js +++ b/app/index.js @@ -1,5 +1,5 @@ const os = require('os') -const {sep, join} = require('path') +const { sep, join } = require('path') global.evaSpace = { config: { @@ -11,11 +11,11 @@ global.evaSpace = { const electron = require('electron') const utils = require('./utils/index.js') -const {initEva} = require('./utils/initialize.js') +const { initEva } = require('./utils/initialize.js') const PluginLoader = require('./loaders/PluginLoader/index.js') -const {isMac, isWindows, PAS, saveFocus, logger, restoreFocus} = require('./utils/index.js') -const {app, globalShortcut, ipcMain, Tray} = electron -const {createEvaWindow, createMainWindow} = require('./loaders/WindowLoader/index.js') +const { isMac, isWindows, PAS, saveFocus, logger, restoreFocus } = require('./utils/index.js') +const { app, globalShortcut, ipcMain, Tray, clipboard } = electron +const { createEvaWindow, createMainWindow } = require('./loaders/WindowLoader/index.js') logger.trace('开始初始化App') initEva() @@ -29,7 +29,7 @@ let mainWindow let tray let queryResult = [] -function registerGlobalShortcut() { +function registerGlobalShortcut () { logger.trace('注册全局快捷键') let registerSuccess = globalShortcut.register('CommandOrControl+Shift+M', () => switchWindowShown()) if (!registerSuccess) logger.error('注册快捷键CommandOrControl+Shift+M失败') @@ -56,7 +56,7 @@ app.on('ready', () => { tray = new Tray(PAS(join(evaSpace.ROOT_DIR, './logo-1024-16x16@3x.png'), './icon.ico')) tray.setToolTip('Eva') - evaWindow.on('blur', () => hideWindow()) + // evaWindow.on('blur', () => hideWindow()) registerGlobalShortcut() ipcMain.on('box-input-esc', () => hideWindow()) @@ -72,13 +72,14 @@ app.on('ready', () => { }) }) -function changeBoxNum(num) { +function changeBoxNum (num) { if (num > 5) num = 5 const h = 50 evaWindow.setSize(evaSpace.config.width, +evaSpace.config.height + h * num) } -function action(event, index) { +function action (event, index) { + logger.info(event) if (queryResult.length <= 0) return new Promise((resolve) => { queryResult[index].action() @@ -90,7 +91,7 @@ function action(event, index) { }) } -async function executeCommonPlugin(input) { +async function executeCommonPlugin (input) { const queryPromises = commonPlugins.map(plugin => plugin.query({ query: input, utils @@ -103,14 +104,15 @@ async function executeCommonPlugin(input) { return queryResult } -function findSuitablePlugin(quickName) { +function findSuitablePlugin (quickName) { return plugins.find(plugin => plugin.quick === quickName) } -async function executeExactPlugin(suitablePlugin, pluginQuery) { +async function executeExactPlugin (suitablePlugin, pluginQuery) { if (!pluginQuery) return [] return await suitablePlugin.query({ query: pluginQuery, + clipboard, utils: { ...utils, notice @@ -120,7 +122,7 @@ async function executeExactPlugin(suitablePlugin, pluginQuery) { let lastedInput -function boxInput(event, input) { +function boxInput (event, input) { lastedInput = input if (!input) return clearQueryResult(event) @@ -131,16 +133,18 @@ function boxInput(event, input) { } const [quickName, ...values] = input.split(' ') + // 匹配插件 const suitablePlugin = findSuitablePlugin(quickName) + // 未匹配到 if (!suitablePlugin) { return returnValue(event, input, executeCommonPlugin(input)) } - + // 处理执行匹配的插件 const pluginQuery = values.join(' ') return returnValue(event, input, executeExactPlugin(suitablePlugin, pluginQuery)) } -function returnValue(event, input, resultPromise) { +function returnValue (event, input, resultPromise) { resultPromise .then(result => { // 如果本次回调对应的input不是最新输入,则忽略 @@ -155,33 +159,33 @@ function returnValue(event, input, resultPromise) { .catch(reason => logger.error(reason)) } -function clearQueryResult(event) { +function clearQueryResult (event) { event.sender.send('clear-query-result') changeBoxNum(0) } let appIsVisible = false -function hideWindow() { +function hideWindow () { evaWindow.hide() if (isWindows) restoreFocus() if (isMac) app.hide() appIsVisible = false } -function showWindow() { +function showWindow () { evaWindow.show() if (isWindows) saveFocus() if (isMac) app.show() appIsVisible = true } -function switchWindowShown() { +function switchWindowShown () { appIsVisible ? hideWindow() : showWindow() } -function restart() { - app.relaunch({args: process.argv.slice(1).concat(['--relaunch'])}) +function restart () { + app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) }) app.exit(0) } @@ -199,8 +203,8 @@ function restart() { * @param option * @returns {Electron.Notification} */ -function notice(option) { +function notice (option) { let notice = new electron.Notification(option) notice.show() return notice -} \ No newline at end of file +} diff --git a/app/loaders/WindowLoader/index.js b/app/loaders/WindowLoader/index.js index c0d9b88..f8c4eee 100644 --- a/app/loaders/WindowLoader/index.js +++ b/app/loaders/WindowLoader/index.js @@ -54,7 +54,7 @@ const template = [ if (process.platform === 'darwin') { template.unshift({ - label: app.getName(), + label: app.name, submenu: [ {role: 'about'}, {type: 'separator'}, @@ -93,10 +93,11 @@ function createEvaWindow(width = 500, height = 60, opacity = 1) { frame: false, skipTaskbar: true, resizable: false, - movable: false, + // movable: false, backgroundColor: '#232323', show: false, webPreferences: { + nodeIntegration: true, devTools: true, nodeIntegrationInWorker: true } @@ -107,7 +108,7 @@ function createEvaWindow(width = 500, height = 60, opacity = 1) { if (process.platform === 'darwin') electron.app.dock.hide() evaWindow.setAlwaysOnTop(true, "floating") evaWindow.setVisibleOnAllWorkspaces(true) - evaWindow.setFullScreenable(false) + evaWindow.fullScreenable = false // and load the index.html of the app. evaWindow.loadURL(url.format({ diff --git a/app/loaders/WindowLoader/views/style.css b/app/loaders/WindowLoader/views/style.css index ce72040..8b54c0c 100644 --- a/app/loaders/WindowLoader/views/style.css +++ b/app/loaders/WindowLoader/views/style.css @@ -61,6 +61,8 @@ input { position: fixed; right: 14px; top: 8px; + -webkit-user-select: none; + -webkit-app-region: drag; } .result { diff --git a/app/package.json b/app/package.json index cee20ca..dbbe422 100644 --- a/app/package.json +++ b/app/package.json @@ -8,7 +8,7 @@ }, "author": "", "devDependencies": { - "electron": "^3.0.0-beta.2" + "electron": "^7.1.7" }, "dependencies": { "axios": "^0.19.0", diff --git a/app/utils/initialize.js b/app/utils/initialize.js index 2693ad1..4d685ed 100644 --- a/app/utils/initialize.js +++ b/app/utils/initialize.js @@ -1,11 +1,11 @@ -const os = require('os') const fs = require('fs') -const evaWorkHome = `${os.homedir()}/.eva` +const evaWorkHome = evaSpace.evaWorkHome let userConfigFilePath = `${evaWorkHome}config.json` function createConfigFile() { const exist = fs.existsSync(userConfigFilePath) + console.log(userConfigFilePath) if (!exist) { fs.writeFileSync(userConfigFilePath, fs.readFileSync(`${evaSpace.ROOT_DIR}/config.json`).toString()) } @@ -24,4 +24,4 @@ const initEva = () => { module.exports = { initEva, evaWorkHome -} \ No newline at end of file +} From a4c7196bf5fdbd36ef196b8ce633a1ff9e6e8721 Mon Sep 17 00:00:00 2001 From: gucovip Date: Thu, 26 Dec 2019 16:54:23 +0800 Subject: [PATCH 2/2] fix: update 1.1.0 --- app/index.js | 2 +- app/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/index.js b/app/index.js index e7d6720..176ba03 100644 --- a/app/index.js +++ b/app/index.js @@ -56,7 +56,7 @@ app.on('ready', () => { tray = new Tray(PAS(join(evaSpace.ROOT_DIR, './logo-1024-16x16@3x.png'), './icon.ico')) tray.setToolTip('Eva') - // evaWindow.on('blur', () => hideWindow()) + evaWindow.on('blur', () => hideWindow()) registerGlobalShortcut() ipcMain.on('box-input-esc', () => hideWindow()) diff --git a/app/package.json b/app/package.json index dbbe422..b9de0c7 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "eva-app", - "version": "1.0.0", + "version": "1.1.0", "description": "", "main": "./index.js", "scripts": {