Skip to content

Commit

Permalink
Merge pull request #7 from eva-org/feature
Browse files Browse the repository at this point in the history
Feature
  • Loading branch information
gucovip authored Dec 26, 2019
2 parents 4e90de4 + a4c7196 commit fa1a7bc
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/base_plugin/FindApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ const cache = (filePath) => {
const times = searchCache[filePath] || 0
searchCache[filePath] = times + 1
fs.writeFileSync(cachePath, JSON.stringify(searchCache))
}
}
2 changes: 1 addition & 1 deletion app/extend_plugin/Clock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:',
Expand Down
48 changes: 26 additions & 22 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require('os')
const {sep, join} = require('path')
const { sep, join } = require('path')

global.evaSpace = {
config: {
Expand All @@ -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()
Expand All @@ -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失败')
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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不是最新输入,则忽略
Expand All @@ -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)
}

Expand All @@ -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
}
}
7 changes: 4 additions & 3 deletions app/loaders/WindowLoader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const template = [

if (process.platform === 'darwin') {
template.unshift({
label: app.getName(),
label: app.name,
submenu: [
{role: 'about'},
{type: 'separator'},
Expand Down Expand Up @@ -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
}
Expand All @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions app/loaders/WindowLoader/views/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ input {
position: fixed;
right: 14px;
top: 8px;
-webkit-user-select: none;
-webkit-app-region: drag;
}

.result {
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "eva-app",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "./index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"devDependencies": {
"electron": "^3.0.0-beta.2"
"electron": "^7.1.7"
},
"dependencies": {
"axios": "^0.19.0",
Expand Down
6 changes: 3 additions & 3 deletions app/utils/initialize.js
Original file line number Diff line number Diff line change
@@ -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())
}
Expand All @@ -24,4 +24,4 @@ const initEva = () => {
module.exports = {
initEva,
evaWorkHome
}
}

0 comments on commit fa1a7bc

Please sign in to comment.