diff --git a/build/icons/256x256.png b/build/icons/256x256.png index 2e54efa..65efaa3 100644 Binary files a/build/icons/256x256.png and b/build/icons/256x256.png differ diff --git a/build/icons/icon.icns b/build/icons/icon.icns index 3634089..84b688d 100644 Binary files a/build/icons/icon.icns and b/build/icons/icon.icns differ diff --git a/build/icons/icon.ico b/build/icons/icon.ico index be44e8d..b7d05bd 100644 Binary files a/build/icons/icon.ico and b/build/icons/icon.ico differ diff --git a/docs/docs/dev/README.md b/docs/docs/dev/README.md index 1f335d4..c13acac 100644 --- a/docs/docs/dev/README.md +++ b/docs/docs/dev/README.md @@ -75,7 +75,7 @@ rubick 更多支持 API 能力参考:[rubick 全局API](https://github.com/clo 复制 `plugin.json` 文件,在 `rubick` 主窗口执行 `ctrl/command + v` 即可唤起安装插件的功能,选择`新建rubick插件`,进入插件主界面, 开启插件后,在插件主窗口即可通过命令打开插件: - + 本小节所有代码:[rubcik-plugin-demo](https://github.com/clouDr-f2e/rubick-plugin-demo) diff --git a/docs/docs/guide/README.md b/docs/docs/guide/README.md index fc4bd77..563a973 100644 --- a/docs/docs/guide/README.md +++ b/docs/docs/guide/README.md @@ -3,7 +3,7 @@ 安装完成后打开 rubick 即可看到主搜索界面: - + 目前支持 windows 和 macos。linux 小伙伴正在开发中 @@ -21,7 +21,7 @@ ``` 也就是说只要当前系统软件安装到这些目录才会被检索到。支持中文搜索和拼音、拼音首字母搜索: - + `Windows` 内由于安装目录太多不确定,有的在 C盘,有的在D盘,还有的在自定义其他位置,所以该功能还在设计中,如果您有好的方案也欢迎提供:[issues](https://github.com/clouDr-f2e/rubick/issues) @@ -42,13 +42,13 @@ 点击搜索框右侧 rubick 图标,进入插件市场,选择所需插件,点击下载按钮即可下载,下载完成后在已安装 tab 下可以找到安装插件。 安装完成后,输入插件呼起命令即可使用对应插件: - + ### 4. 右击增强 通常我们需要使用鼠标右击来对桌面属性进行拓展,`Rubick` 支持对右击属性进行增强功能,长按鼠标右键即可呼起。如果安装的插件支持 特殊类型的文件操作,还可以在右键中唤起插件: - + ### 更多功能 如果您还需要更多功能,欢迎来这里给我们提建议:[issues](https://github.com/clouDr-f2e/rubick/issues/20) diff --git a/package.json b/package.json index 185d0b0..0c25c74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubick2", - "version": "0.0.3-beta.1", + "version": "0.0.3-beta.2", "author": "muwoo <2424880409@qq.com>", "description": "An electron-vue project", "license": null, @@ -68,6 +68,7 @@ "bplist-parser": "^0.3.0", "download": "^8.0.0", "download-git-repo": "^3.0.2", + "electron-is-dev": "^2.0.0", "electron-store": "^8.0.0", "iohook": "^0.9.3", "is-chinese": "^1.4.2", @@ -117,7 +118,7 @@ "file-loader": "^1.1.11", "html-webpack-plugin": "^3.2.0", "iconv-lite": "^0.6.3", - "less": "^4.1.1", + "less": "^2.7.3", "less-loader": "^5.0.0", "listr": "^0.14.3", "mini-css-extract-plugin": "0.4.0", diff --git a/src/main/browsers/main.js b/src/main/browsers/main.js index 71d928d..752cf38 100644 --- a/src/main/browsers/main.js +++ b/src/main/browsers/main.js @@ -18,6 +18,7 @@ module.exports = () => { frame: false, title: '拉比克', show: false, + skipTaskbar: true, webPreferences: { webSecurity: false, enableRemoteModule: true, diff --git a/src/main/common/common.js b/src/main/common/common.js index db1c747..9a96fd2 100644 --- a/src/main/common/common.js +++ b/src/main/common/common.js @@ -9,13 +9,6 @@ export default function init(mainWindow) { listener.registerShortCut(mainWindow); listener.init(mainWindow); - // 设置开机启动 - const config = global.opConfig.get(); - app.setLoginItemSettings({ - openAtLogin: config.perf.common.start, - openAsHidden: true, - }); - mainWindow.once("ready-to-show", () => { // 非隐藏式启动需要显示主窗口 if (!app.getLoginItemSettings().wasOpenedAsHidden) { diff --git a/src/main/common/listener.js b/src/main/common/listener.js index dfdbaea..e1df01d 100644 --- a/src/main/common/listener.js +++ b/src/main/common/listener.js @@ -1,9 +1,9 @@ -import {BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen} from "electron"; +import {app, BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen} from "electron"; import {exec, spawn} from "child_process"; import robot from "robotjs"; import Api from "./api"; import ioHook from 'iohook'; -import {throttle} from './utils'; +import {throttle, commonConst} from './utils'; const browsers = require("../browsers")(); const {picker, separator, superPanel} = browsers; @@ -21,8 +21,7 @@ class Listener { clipboard.clear(); // 复制选中文案 - const platform = process.platform; - if (platform === 'darwin') { + if (commonConst.macOS()) { robot.keyTap('c', 'command'); } else { robot.keyTap('c', 'control'); @@ -55,9 +54,11 @@ class Listener { const currentDisplay = screen.getDisplayNearestPoint({ x, y }); const wx = parseInt(currentDisplay.workArea.x + currentDisplay.workArea.width / 2 - 400); const wy = parseInt(currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200); - mainWindow.setVisibleOnAllWorkspaces(true); + + mainWindow.setAlwaysOnTop(true) + mainWindow.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true}); mainWindow.focus(); - mainWindow.setVisibleOnAllWorkspaces(false); + mainWindow.setVisibleOnAllWorkspaces(false, {visibleOnFullScreen: true}); mainWindow.setPosition(wx, wy); mainWindow.show(); }); @@ -95,6 +96,7 @@ class Listener { picker.getWindow().webContents.send("updatePicker", colors); }, 100); + this.setAutoLogin(); this.colorPicker(); this.initPlugin(); this.lockScreen(); @@ -231,10 +233,21 @@ class Listener { reRegisterShortCut(mainWindow) { ipcMain.on('re-register', (event, arg) => { + this.setAutoLogin(); this.registerShortCut(mainWindow); }); } + setAutoLogin() { + // 设置开机启动 + const config = global.opConfig.get(); + app.setLoginItemSettings({ + openAtLogin: config.perf.common.start, + openAsHidden: true, + }); + } + + changeSize(mainWindow) { // 修改窗口尺寸 ipcMain.on('changeWindowSize-rubick', (event, arg) => { diff --git a/src/main/common/utils.js b/src/main/common/utils.js index 6528a41..ce85484 100644 --- a/src/main/common/utils.js +++ b/src/main/common/utils.js @@ -53,3 +53,22 @@ export function throttle (func, wait, options) { }; } +export const commonConst = { + linux: function () { + return process.platform === 'linux' + }, + macOS () { + return process.platform === 'darwin'; + }, + windows () { + return process.platform === 'win32' + }, + production: function () { + return process.env.NODE_ENV !== 'development'; + }, + dev: function () { + return process.env.NODE_ENV === 'development'; + }, +} + + diff --git a/src/main/index.js b/src/main/index.js index d2ab83f..fec30f9 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,40 +1,105 @@ -import { app } from 'electron' +import { app, globalShortcut } from 'electron' import '../renderer/store' import init from './common/common'; import {autoUpdate} from './common/autoUpdate'; import createTray from './tray'; +import {commonConst} from './common/utils'; + const {main} = require("./browsers")(); -/** - * Set `__static` path to static files in production - * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html - */ -if (process.env.NODE_ENV !== 'development') { + +if (commonConst.production()) { global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') } // to fix https://github.com/electron/electron/issues/18397 app.allowRendererProcessReuse = false; -if (process.platform === 'darwin') { - app.dock.hide(); -} -function createWindow() { - main.init(); - init(main.getWindow()); -} - -app.on('ready', () => { - createWindow() - createTray(main.getWindow()); - autoUpdate(); -}) - -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() +class initApp { + launchApp() { + const gotTheLock = app.requestSingleInstanceLock() + if (!gotTheLock) { + app.quit() + } else { + this.beforeReady() + this.onReady() + this.onRunning() + this.onQuit() + } } -}) -app.on('activate', () => { - createWindow() -}); + createWindow() { + main.init(); + init(main.getWindow()); + } + beforeReady() { + // 系统托盘 + if (commonConst.macOS()) { + if (commonConst.production() && !app.isInApplicationsFolder()) { + app.moveToApplicationsFolder(); + } else { + app.dock.hide(); + } + }else { + app.disableHardwareAcceleration(); + } + } + + onReady() { + const readyFunction = () => { + this.createWindow(); + createTray(main.getWindow()); + autoUpdate(); + } + if (!app.isReady()) { + app.on('ready', readyFunction) + } else { + readyFunction() + } + } + + onRunning() { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // 当运行第二个实例时,将会聚焦到myWindow这个窗口 + const win = main.getWindow(); + if (win) { + if (win.isMinimized()) { + win.restore(); + } + win.focus(); + } + }); + app.on('activate', () => { + if (!main.getWindow()) { + this.createWindow(); + } + }); + } + + onQuit () { + app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit() + } + }) + + app.on('will-quit', () => { + globalShortcut.unregisterAll() + }) + // Exit cleanly on request from parent process in development mode. + if (commonConst.dev()) { + if (process.platform === 'win32') { + process.on('message', data => { + if (data === 'graceful-exit') { + app.quit() + } + }) + } else { + process.on('SIGTERM', () => { + app.quit() + }) + } + } + } +} + +(new initApp()).launchApp(); diff --git a/src/main/tray.js b/src/main/tray.js index 04f2517..c2e27a0 100644 --- a/src/main/tray.js +++ b/src/main/tray.js @@ -1,10 +1,20 @@ -import { dialog, Menu, Tray, app, shell, ipcMain } from 'electron'; +import { dialog, Menu, Tray, app, shell } from 'electron'; import path from 'path'; import pkg from '../../package.json'; +import os from 'os'; +import {commonConst} from './common/utils'; function createTray(window) { return new Promise((resolve, reject) => { - const appIcon = new Tray(path.join(__static, './rocket.png')); + let icon; + if (commonConst.macOS()) { + icon = './icon@3x.png' + }else if (commonConst.windows()) { + icon = parseInt(os.release()) < 10 ? './icon@2x.png' : './icon.ico'; + }else { + icon = 'icon@2x.png' + } + const appIcon = new Tray(path.join(__static, icon)); const contextMenu = Menu.buildFromTemplate([ { label: "帮助文档", click: () => { diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 42ff63c..e32b4ff 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -44,7 +44,7 @@ :src="selected.icon" />