Skip to content

Commit

Permalink
Merge pull request #9 from eva-org/next
Browse files Browse the repository at this point in the history
feat: update electron version
  • Loading branch information
gucovip authored Jan 9, 2024
2 parents 2645e41 + 21aa60a commit 730c0a2
Show file tree
Hide file tree
Showing 46 changed files with 12,033 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sync
.uglify
.cache-loader
.cache
app/extend_plugin/Youdao/config.json
eva-app/extend_plugin/Youdao/config.json

build
package
Expand Down
Binary file added bun.lockb
Binary file not shown.
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"name": "eva-package",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"scripts": {
"pa:win": "electron-packager ./app Eva --win --asar --arch=x64 --out=./package --app-version=0.0.1 --overwrite --icon=./icon.ico --ignore=\"(.gitignore|yarn.lock|yarn-error.log|.idea)\"",
"pa:mac": "electron-packager ./app Eva --darwin --arch=x64 --out=./package --app-version=0.0.1 --overwrite --icon=./icon.icns --ignore=\"(.gitignore|yarn.lock|yarn-error.log|.idea)\"",
"pa": "pa:mac && pa:win"
"pa:win": "electron-packager ./packages/eva-app Eva --win --asar --arch=x64 --out=./package --app-version=0.0.1 --overwrite --icon=./icon.ico --ignore=\"(.gitignore|yarn.lock|yarn-error.log|.idea)\"",
"pa:mac": "electron-packager ./packages/eva-app Eva --darwin --arch=x64 --out=./package --app-version=0.0.1 --overwrite --icon=./icon.icns --ignore=\"(.gitignore|yarn.lock|yarn-error.log|.idea)\"",
"pa": "pa:mac && pa:win",
"start": "electron ./packages/eva-app"
},
"author": "",
"workspaces": [
"packages/eva-app"
],
"devDependencies": {
"asar": "^2.0.3",
"asar": "^3.2.0",
"cz-conventional-changelog": "^3.0.2",
"electron": "^9.1.0",
"electron-packager": "^12.2.0"
"electron": "^28.1.1",
"electron-packager": "^17.1.2"
},
"dependencies": {},
"config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ module.exports = {
async query(pluginContext) {
if (!initialized) return initAndGetData(pluginContext)
return getData(pluginContext)
},
action (fileUri) {
try {
cache(fileUri)
} catch (e) {
console.log(e)
}
child_process.exec(`${config.command}"${fileUri}"`)
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions app/config.json → packages/eva-app/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"logLevel": "all",
"width": 600,
"height": 60,
"height": 360,
"opacity": 0.9
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 31 additions & 22 deletions app/index.js → packages/eva-app/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const PluginLoader = require('./loaders/PluginLoader/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')
const { ipcRenderer } = require('electron')

logger.trace('开始初始化App')
initEva()
Expand Down Expand Up @@ -44,15 +45,12 @@ function registerGlobalShortcut () {
}

app.on('ready', () => {
logger.trace('App已经就绪')
try {
logger.trace('创建隐藏的主窗口')
mainWindow = createMainWindow()
} catch (e) {
logger.error(e)
}
logger.trace('创建Eva窗口')
evaWindow = createEvaWindow(evaSpace.config.width, evaSpace.config.height, evaSpace.config.opacity)
logger.trace('App已经就绪,创建Eva窗口')
logger.trace('')
evaWindow = createEvaWindow(evaSpace.config.width, evaSpace.config.height, evaSpace.config.opacity, mainWindow)
evaWindow.on('browser-window-focus', (e, w) => {
console.log('browser-window-focus', e)
})
tray = new Tray(PAS(join(evaSpace.ROOT_DIR, './[email protected]'), './icon.ico'))
tray.setToolTip('Eva')

Expand Down Expand Up @@ -83,6 +81,7 @@ function action (event, index) {
if (queryResult.length <= 0) return
new Promise((resolve) => {
queryResult[index].action()

resolve()
}).then(() => {
event.sender.send('action-exec-success')
Expand All @@ -98,9 +97,12 @@ async function executeCommonPlugin (input) {
}))
let queryResult = []
const resultArr = await Promise.all(queryPromises)
for (const result of resultArr) {
resultArr.forEach((result, index) => {
result.forEach(item => {
item.plugin = commonPlugins[index]
})
queryResult = queryResult.concat(result)
}
})
return queryResult
}

Expand All @@ -122,45 +124,52 @@ async function executeExactPlugin (suitablePlugin, pluginQuery) {

let lastedInput

function boxInput (event, input) {
function boxInput (event, { input }) {
logger.info('boxInput', event, input)
lastedInput = input
if (!input) return clearQueryResult(event)
const render = evaWindow.webContents
if (!input) return clearQueryResult(event, render)

// 如果不包含空格则执行通用插件(*插件)
const blankIndex = input.indexOf(' ')
if (blankIndex === -1) {
return returnValue(event, input, executeCommonPlugin(input))
return returnValue(event, input, executeCommonPlugin(input), render)
}

const [quickName, ...values] = input.split(' ')
// 匹配插件
const suitablePlugin = findSuitablePlugin(quickName)
// 未匹配到
if (!suitablePlugin) {
return returnValue(event, input, executeCommonPlugin(input))
return returnValue(event, input, executeCommonPlugin(input), render)
}
// 处理执行匹配的插件
const pluginQuery = values.join(' ')
return returnValue(event, input, executeExactPlugin(suitablePlugin, pluginQuery))
return returnValue(event, input, executeExactPlugin(suitablePlugin, pluginQuery), render)
}

function returnValue (event, input, resultPromise) {
function returnValue (event, input, resultPromise, render) {
resultPromise
.then(result => {
// 如果本次回调对应的input不是最新输入,则忽略
if (input !== lastedInput) return clearQueryResult(event)
if (input !== lastedInput) return clearQueryResult(event, render)

if (result.length) clearQueryResult(event)
if (result.length) clearQueryResult(event, render)
changeBoxNum(result.length)
event.sender.send('query-result', result)
logger.log(result)
render.send('query-result', {
result: result.map(item => ({ ...item, plugin: undefined, action: undefined })),
})
// event.sender.send('query-result', result)
// 在主线程保存插件结果,用于执行action,因为基于json的ipc通讯不可序列化function
queryResult = result
})
.catch(reason => logger.error(reason))
}

function clearQueryResult (event) {
event.sender.send('clear-query-result')
function clearQueryResult (event, render) {
render.send('clear-query-result')
// event.sender.send('clear-query-result')
changeBoxNum(0)
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ if (process.platform === 'darwin') {
}

function createMainWindow() {
return new BrowserWindow({
x: 0, y: 0, width: 0, height: 0, show: false, focusable: false, frame: false,
const bounds = electron.screen.getPrimaryDisplay().workArea
const mainWindow = new BrowserWindow({
x: 0, y: 0, width: bounds.width, height: bounds.height, show: false, focusable: false, frame: false,
titleBarStyle: 'customButtonsOnHover',
transparent: true
visibleOnAllWorkspaces: true,
transparent: true,
skipTaskbar: true
})
mainWindow.setAlwaysOnTop(true, 'screen-saver')
mainWindow.setVisibleOnAllWorkspaces(true)
return mainWindow
}

function createEvaWindow(width = 500, height = 60, opacity = 1) {
Expand All @@ -93,21 +99,21 @@ function createEvaWindow(width = 500, height = 60, opacity = 1) {
frame: false,
skipTaskbar: true,
resizable: false,
setVisibleOnAllWorkspaces: true,
// movable: false,
backgroundColor: '#232323',
show: false,
webPreferences: {
nodeIntegration: true,
devTools: true,
nodeIntegrationInWorker: true
nodeIntegrationInWorker: true,
preload: path.join(__dirname, 'preload.js')
}
// parent: mainWindow
})

// 全屏代码
if (process.platform === 'darwin') electron.app.dock.hide()
evaWindow.setAlwaysOnTop(true, "floating")
evaWindow.setVisibleOnAllWorkspaces(true)
evaWindow.setAlwaysOnTop(true, 'floating')
evaWindow.fullScreenable = false

// and load the index.html of the app.
Expand Down
22 changes: 22 additions & 0 deletions packages/eva-app/loaders/WindowLoader/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { ipcRenderer, contextBridge } = require('electron')

contextBridge.exposeInMainWorld('electronAPI', {
evaAction: (index) => ipcRenderer.send('action', index),
evaEsc: (input) => ipcRenderer.send('box-input-esc', input),
evaInput: (input) => {
console.log(input)
ipcRenderer.send('box-input', { input: input })
},
evaOn: (channel, fn) => ipcRenderer.on(channel, fn),
evaSend: (channel, fn) => ipcRenderer.send(channel, fn)
})
contextBridge.exposeInMainWorld('eva', {
action: (index) => ipcRenderer.send('action', index),
esc: (input) => ipcRenderer.send('box-input-esc', input),
input: (input) => {
console.log(input)
ipcRenderer.send('box-input', { input: input })
},
on: (channel, fn) => ipcRenderer.on(channel, fn),
send: (channel, fn) => ipcRenderer.send(channel, fn)
})
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="../../../node_modules/vue/dist/vue.js"></script>
<script type="text/javascript" src="vue.js"></script>
</head>
<body>
<div id="app">
Expand All @@ -26,8 +26,6 @@
</template>
</div>
<script>
const {ipcRenderer} = require('electron')

const vue = new Vue({
el: '#app',
data() {
Expand All @@ -42,10 +40,10 @@
this.currIndex = index
},
enter() {
ipcRenderer.send('action', this.currIndex)
window.electronAPI.evaAction(this.currIndex)
},
esc() {
ipcRenderer.send('box-input-esc', this.input)
window.electronAPI.evaEsc(this.input)
},
up() {
if (this.currIndex > 0) this.currIndex--
Expand All @@ -71,21 +69,21 @@
}
},
watch: {
input() {
ipcRenderer.send('box-input', this.input)
input(val) {
window.eva.input(val)
this.currIndex = 0
}
}
})

ipcRenderer.on('action-exec-success', () => {
window.eva.on('action-exec-success', () => {
vue.$refs.boxInput.select()
ipcRenderer.send('hide-main-window')
window.eva.send('hide-main-window')
})
ipcRenderer.on('clear-query-result', () => vue.$data.queryResult = [])
ipcRenderer.on('query-result', (event, queryResult) => {
window.electronAPI.evaOn('clear-query-result', () => vue.$data.queryResult = [])
window.electronAPI.evaOn('query-result', (event, {result: queryResult}) => {
vue.$data.queryResult = queryResult
if (queryResult.length <= 0) ipcRenderer.send('restore-box-height')
if (queryResult.length <= 0) window.electronAPI.evaSend('restore-box-height')
})
</script>
</body>
Expand Down
File renamed without changes.
Loading

0 comments on commit 730c0a2

Please sign in to comment.