diff --git a/.electron-vue/dev-runner.js b/.electron-vue/dev-runner.js index 4eb5909d9120e753e2eb5cdbe04613df2b6f64d5..2787e8cf7df2b3b065add1b3a6f92baffa4ea194 100644 --- a/.electron-vue/dev-runner.js +++ b/.electron-vue/dev-runner.js @@ -64,7 +64,7 @@ function startRenderer () { { contentBase: path.join(__dirname, '../'), disableHostCheck: true, - host: 'quicker.csdn.net', + host: '127.0.0.1', quiet: true, hot: true, before (app, ctx) { diff --git a/package.json b/package.json index fec52b5afebaf10948475ea313f77077ec2f6c3c..3361dce3eeb29b7dddeeb1c1bf20d58f1fbb63c5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "rubick2", - "version": "0.0.12", - "author": "muwoo <2424880409@qq.com>", + "name": "Quicker", + "version": "0.0.1", + "author": "libai", "description": "An electron-vue project", "license": null, "main": "./dist/electron/main.js", diff --git a/src/main/browsers/main.js b/src/main/browsers/main.js index f8a8e842353f447d4180ef9acb9367e866a0807b..6dcd24aec7725516a3b9168c46928c33c70a37fd 100644 --- a/src/main/browsers/main.js +++ b/src/main/browsers/main.js @@ -11,7 +11,7 @@ module.exports = () => { let createWindow = opts => { const winURL = process.env.NODE_ENV === "development" - ? `http://quicker.csdn.net:5501` + ? `http://127.0.0.1:5501` : `file://${__dirname}/index.html`; win = new BrowserWindow({ @@ -55,7 +55,7 @@ module.exports = () => { win = undefined; }); win.on("blur", () => { - win.hide(); + // win.hide(); }); }; diff --git a/src/main/dock.js b/src/main/dock.js new file mode 100644 index 0000000000000000000000000000000000000000..25197a6817f468a6dd06827e080374a9c5a8170d --- /dev/null +++ b/src/main/dock.js @@ -0,0 +1,94 @@ +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 createDock(window) { + return new Promise((resolve, reject) => { + let icon; + if (commonConst.macOS()) { + icon = "./rocket.png"; + } else if (commonConst.windows()) { + icon = parseInt(os.release()) < 10 ? "./icon@2x.png" : "./icon.ico"; + } else { + icon = "icon@2x.png"; + } + const appIcon = path.join(__static, icon); + const dockMenu = Menu.buildFromTemplate([ + { + label: "注册", + click() { + shell.openExternal("https://passport.csdn.net/newlogin?code=mobile"); + } + }, + { + label: "帮助文档", + click: () => { + process.nextTick(() => { + shell.openExternal( + "https://yre5673znb.feishu.cn/docs/doccnMnLv3iZ3epFvjXprnPum3b" + ); + }); + } + }, + { + label: "意见反馈", + click: () => { + process.nextTick(() => { + shell.openExternal("https://www.wenjuan.com/s/UZBZJvmzhg/"); + }); + } + }, + { type: "separator" }, + { + label: "显示窗口", + accelerator: "Alt+R", + click() { + window.show(); + } + }, + { + label: "偏好设置", + click() { + window.show(); + window.webContents.send("tray-setting"); + } + }, + { + label: "关于", + click() { + dialog.showMessageBox({ + title: "Quicker", + message: "即刻", + detail: `Version: ${pkg.version}\nAuthor: libai` + }); + } + }, + { type: "separator" }, + { + label: "重启", + click() { + app.relaunch(); + app.quit(); + } + }, + { + role: "quit", + label: "退出" + } + ]); + // appIcon.on("click", () => { + // appIcon.popUpContextMenu(contextMenu); + // }); + // appIcon.setContextMenu(contextMenu); + + // resolve(appIcon); + app.dock.setMenu(dockMenu); + app.dock.setIcon(appIcon); + + resolve(app); + }); +} + +export default createDock; diff --git a/src/main/index.js b/src/main/index.js index 670709fcb63a33de776248a2eeeb97c0dc1813f1..a697d3bc05f1f3c3c231e14a1284bc86a6ed01ea 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,111 +1,116 @@ -import { app, globalShortcut } from 'electron' -import init from './common/common' -import { autoUpdate } from './common/autoUpdate' -import createTray from './tray' -import { commonConst } from './common/utils' -import pkg from '../../package.json' -import Store from 'electron-store'; +import { app, globalShortcut } from "electron"; +import init from "./common/common"; +import { autoUpdate } from "./common/autoUpdate"; +import createTray from "./tray"; +import createDock from "./dock"; +import { commonConst } from "./common/utils"; +import pkg from "../../package.json"; +import Store from "electron-store"; -Store.initRenderer() +Store.initRenderer(); -const { main } = require("./browsers")() +const { main } = require("./browsers")(); if (commonConst.production()) { - global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') + global.__static = require("path") + .join(__dirname, "/static") + .replace(/\\/g, "\\\\"); } // to fix https://github.com/electron/electron/issues/18397 -app.allowRendererProcessReuse = false +app.allowRendererProcessReuse = false; class initApp { launchApp() { - const gotTheLock = app.requestSingleInstanceLock() + const gotTheLock = app.requestSingleInstanceLock(); if (!gotTheLock) { - app.quit() + app.quit(); } else { - this.beforeReady() - this.onReady() - this.onRunning() - this.onQuit() + this.beforeReady(); + this.onReady(); + this.onRunning(); + this.onQuit(); } } createWindow() { - main.init() - init(main.getWindow()) + main.init(); + init(main.getWindow()); } beforeReady() { // 系统托盘 if (commonConst.macOS()) { if (commonConst.production() && !app.isInApplicationsFolder()) { - app.moveToApplicationsFolder() + app.moveToApplicationsFolder(); } else { - app.dock.hide() + // app.dock.hide() } } else { - app.disableHardwareAcceleration() + app.moveToApplicationsFolder(); + app.disableHardwareAcceleration(); } } onReady() { const readyFunction = () => { - this.createWindow() - createTray(main.getWindow()) - autoUpdate() - } + this.createWindow(); + createTray(main.getWindow()); + createDock(); + autoUpdate(); + }; if (!app.isReady()) { - app.on('ready', readyFunction) + app.on("ready", readyFunction); } else { - readyFunction() + readyFunction(); } } onRunning() { - app.on('second-instance', (event, commandLine, workingDirectory) => { + app.on("second-instance", (event, commandLine, workingDirectory) => { // 当运行第二个实例时,将会聚焦到myWindow这个窗口 - const win = main.getWindow() + const win = main.getWindow(); if (win) { if (win.isMinimized()) { - win.restore() + win.restore(); } - win.focus() + win.focus(); } - }) - app.on('activate', () => { + }); + app.on("activate", () => { if (!main.getWindow()) { - this.createWindow() + this.createWindow(); } - }) + }); if (commonConst.windows()) { - app.setAppUserModelId(pkg.build.appId) + app.setAppUserModelId(pkg.build.appId); } } onQuit() { - app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() + app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + app.quit(); } - }) + }); - app.on('will-quit', () => { - globalShortcut.unregisterAll() - }) + 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() + if (process.platform === "win32") { + process.on("message", data => { + if (data === "graceful-exit") { + app.quit(); } - }) + }); } else { - process.on('SIGTERM', () => { - app.quit() - }) + process.on("SIGTERM", () => { + app.quit(); + }); } } } } -(new initApp()).launchApp() +new initApp().launchApp();