Added simple electron wrapper

This commit is contained in:
RemixDev 2021-05-23 22:42:16 +02:00
parent f33cbcb7d0
commit 86aa075c8d
4 changed files with 2027 additions and 0 deletions

57
index.js Normal file
View file

@ -0,0 +1,57 @@
const { app, BrowserWindow, globalShortcut, ipcMain, shell} = require('electron')
const path = require('path')
const PORT = process.env.PORT || '6595'
function isDev() {
return process.argv[2] == '--dev';
}
function createWindow () {
require('./server/dist/app.js')
const win = new BrowserWindow({
width: 800,
height: 600,
useContentSize: true,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
win.setMenu(null)
if (isDev()){
globalShortcut.register('f5', function() {
win.reload()
})
globalShortcut.register('f12', function() {
win.webContents.openDevTools()
})
}
// Open links in external browser
win.webContents.on('new-window', function(e, url) {
e.preventDefault()
shell.openExternal(url)
})
win.loadURL(`http://localhost:${PORT}`)
}
app.whenReady().then(() => {
createWindow()
// Only one istance per time
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

17
package.json Normal file
View file

@ -0,0 +1,17 @@
{
"name": "deemix-gui",
"version": "1.0.0",
"main": "index.js",
"repository": "https://gitlab.com/RemixDev/deemix-gui.git",
"author": "RemixDev <RemixDev64@gmail.com>",
"license": "GPL-3.0-only",
"scripts": {
"start": "electron . --dev",
"pack": "electron-builder --dir",
"dist": "electron-builder"
},
"devDependencies": {
"electron": "^12.0.9",
"electron-builder": "^22.10.5"
}
}

25
preload.js Normal file
View file

@ -0,0 +1,25 @@
const {
contextBridge,
ipcRenderer
} = require("electron");
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
"api", {
send: (channel, data) => {
// whitelist channels
let validChannels = [];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = [];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);

1928
yarn.lock Normal file

File diff suppressed because it is too large Load diff