This commit is contained in:
muwoo
2021-06-02 17:17:09 +08:00
commit ce490acb6a
52 changed files with 16764 additions and 0 deletions

17
src/main/common.js Normal file
View File

@@ -0,0 +1,17 @@
import {BrowserWindow, globalShortcut, ipcMain} from 'electron';
export default function init(mainWindow) {
ipcMain.on('changeWindowSize', (event, arg) => {
mainWindow.setSize(arg.width || 788, arg.height);
});
mainWindow.on('blur', () => {
// mainWindow.hide();
});
globalShortcut.register('Alt+R', () => {
mainWindow.show();
});
}

24
src/main/index.dev.js Normal file
View File

@@ -0,0 +1,24 @@
/**
* This file is used specifically and only for development. It installs
* `electron-debug` & `vue-devtools`. There shouldn't be any need to
* modify this file, but it can be used to extend your development
* environment.
*/
/* eslint-disable */
// Install `electron-debug` with `devtron`
require('electron-debug')({ showDevTools: true })
// Install `vue-devtools`
require('electron').app.on('ready', () => {
let installExtension = require('electron-devtools-installer')
installExtension.default(installExtension.VUEJS_DEVTOOLS)
.then(() => {})
.catch(err => {
console.log('Unable to install `vue-devtools`: \n', err)
})
})
// Require `main` process to boot app
require('./index')

81
src/main/index.js Normal file
View File

@@ -0,0 +1,81 @@
import { app, BrowserWindow } from 'electron'
import '../renderer/store'
import eventTracker from '../common/event-tracker';
import init from './common';
import createTray from './tray';
/**
* 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') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}
let mainWindow
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
: `file://${__dirname}/index.html`
function createWindow () {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 60,
useContentSize: true,
width: 788,
frame: false,
title: '拉比克',
webPreferences: {
enableRemoteModule: true,
backgroundThrottling: false,
webviewTag: true,
nodeIntegration: true // 在网页中集成Node
}
})
mainWindow.loadURL(winURL)
mainWindow.on('closed', () => {
mainWindow = null
});
init(mainWindow);
eventTracker();
}
app.on('ready', () => {
createWindow()
createTray(mainWindow);
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
/**
* Auto Updater
*
* Uncomment the following code below and install `electron-updater` to
* support auto updating. Code Signing with a valid certificate is required.
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
*/
/*
import { autoUpdater } from 'electron-updater'
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall()
})
app.on('ready', () => {
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
})
*/

59
src/main/tray.js Normal file
View File

@@ -0,0 +1,59 @@
import { dialog, Menu, Tray, app, shell, ipcMain } from 'electron';
import path from 'path';
import pkg from '../../package.json';
function createTray(window) {
return new Promise((resolve, reject) => {
const appIcon = new Tray(path.join(__static, './rocket-t.png'));
const contextMenu = Menu.buildFromTemplate([
{
id: 3,
label: '显示窗口',
accelerator: "Alt+R",
click() {
window.show();
}
},
{
id: 4,
label: '文档',
click() {
shell.openExternal('https://muwoo.github.io/rubick-doc/');
}
},
{
id: 5,
label: '显示窗口',
click() {
window.show();
}
},
{
id: 6,
label: '关于',
click() {
dialog.showMessageBox({
title: '拉比克',
message: '一站式前端开发工具箱',
detail: `Version: ${pkg.version}\nAuthor: muwoo`
});
}
},
{
id: 7,
role: 'quit',
label: '退出'
}
]);
appIcon.on('click', () => {
appIcon.popUpContextMenu(contextMenu);
});
appIcon.setContextMenu(contextMenu);
resolve(appIcon);
});
}
export default createTray;