This commit is contained in:
Troplo 2022-08-03 19:49:15 +10:00
parent 4599162060
commit d4be83f6d2
2 changed files with 18 additions and 16 deletions

View file

@ -31,7 +31,6 @@
"postuninstall": "electron-builder install-app-deps" "postuninstall": "electron-builder install-app-deps"
}, },
"main": "./src/background.js", "main": "./src/background.js",
"type": "module",
"repository": "https://github.com/Troplo/Colubrina", "repository": "https://github.com/Troplo/Colubrina",
"dependencies": { "dependencies": {
"@babel/preset-env": "^7.17.10", "@babel/preset-env": "^7.17.10",

View file

@ -1,25 +1,28 @@
"use strict" "use strict"
import { app, protocol, BrowserWindow, screen } from "electron" const electron = require("electron")
import { createProtocol } from "vue-cli-plugin-electron-builder/lib" const VueCLI = require("vue-cli-plugin-electron-builder/lib")
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer" const {
default: installExtension,
VUEJS_DEVTOOLS
} = require("electron-devtools-installer")
const isDevelopment = process.env.NODE_ENV !== "production" const isDevelopment = process.env.NODE_ENV !== "production"
// Scheme must be registered before the app is ready // Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([ electron.protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } } { scheme: "app", privileges: { secure: true, standard: true } }
]) ])
async function createWindow() { async function createWindow() {
// Create the browser window. // Create the browser window.
const { bounds } = screen.getDisplayNearestPoint( const { bounds } = electron.screen.getDisplayNearestPoint(
screen.getCursorScreenPoint() electron.screen.getCursorScreenPoint()
) )
const height = Math.floor(bounds.height * (2 / 3)) const height = Math.floor(bounds.height * (2 / 3))
const width = Math.floor(bounds.width * (2 / 3)) const width = Math.floor(bounds.width * (2 / 3))
const y = Math.floor(bounds.y + (bounds.height - height) / 2) const y = Math.floor(bounds.y + (bounds.height - height) / 2)
const x = Math.floor(bounds.x + (bounds.width - width) / 2) const x = Math.floor(bounds.x + (bounds.width - width) / 2)
const win = new BrowserWindow({ const win = new electron.BrowserWindow({
width, width,
height, height,
x, x,
@ -40,31 +43,31 @@ async function createWindow() {
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL) await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools() if (!process.env.IS_TEST) win.webContents.openDevTools()
} else { } else {
createProtocol("app") VueCLI.createProtocol("app")
// Load the index.html when not in development // Load the index.html when not in development
win.loadURL("app://./index.html") win.loadURL("app://./index.html")
} }
} }
// Quit when all windows are closed. // Quit when all windows are closed.
app.on("window-all-closed", () => { electron.app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar // On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q // to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
app.quit() electron.app.quit()
} }
}) })
app.on("activate", () => { electron.app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the // On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow() if (electron.BrowserWindow.getAllWindows().length === 0) createWindow()
}) })
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on("ready", async () => { electron.app.on("ready", async () => {
if (isDevelopment && !process.env.IS_TEST) { if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools // Install Vue Devtools
try { try {
@ -81,12 +84,12 @@ if (isDevelopment) {
if (process.platform === "win32") { if (process.platform === "win32") {
process.on("message", (data) => { process.on("message", (data) => {
if (data === "graceful-exit") { if (data === "graceful-exit") {
app.quit() electron.app.quit()
} }
}) })
} else { } else {
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
app.quit() electron.app.quit()
}) })
} }
} }