2021-06-29 13:58:25 +00:00
|
|
|
const { app, BrowserWindow, ipcMain, shell, dialog, Menu, MenuItem } = require('electron')
|
2021-05-29 10:33:20 +00:00
|
|
|
const contextMenu = require('electron-context-menu')
|
|
|
|
const WindowStateManager = require('electron-window-state-manager')
|
2021-05-23 20:42:16 +00:00
|
|
|
const path = require('path')
|
2021-05-29 11:58:10 +00:00
|
|
|
const os = require('os')
|
2021-06-29 13:58:25 +00:00
|
|
|
const yargs = require('yargs/yargs')
|
|
|
|
const { hideBin } = require('yargs/helpers')
|
|
|
|
const argv = yargs(hideBin(process.argv)).options({
|
|
|
|
port: { type: 'string', default: '6595' },
|
|
|
|
host: { type: 'string', default: '127.0.0.1' },
|
|
|
|
dev: { type: 'boolean', default: false}
|
|
|
|
}).argv
|
2021-07-02 17:57:06 +00:00
|
|
|
const server = require('./server/dist/app.js')
|
2021-05-23 20:42:16 +00:00
|
|
|
|
2021-07-17 12:57:20 +00:00
|
|
|
const PORT = process.env.DEEMIX_SERVER_PORT || argv.port
|
2021-05-23 20:42:16 +00:00
|
|
|
|
2021-07-17 12:57:20 +00:00
|
|
|
process.env.DEEMIX_SERVER_PORT = PORT
|
2021-06-29 13:58:25 +00:00
|
|
|
process.env.DEEMIX_HOST = argv.host
|
2021-05-23 20:42:16 +00:00
|
|
|
|
2021-05-28 10:40:06 +00:00
|
|
|
let win
|
2021-05-29 10:33:20 +00:00
|
|
|
const windowState = new WindowStateManager('mainWindow', {
|
|
|
|
defaultWidth: 800,
|
|
|
|
defaultHeight: 600
|
|
|
|
})
|
2021-05-28 10:40:06 +00:00
|
|
|
|
2021-05-23 20:42:16 +00:00
|
|
|
function createWindow () {
|
2021-05-28 10:40:06 +00:00
|
|
|
win = new BrowserWindow({
|
2021-05-29 10:33:20 +00:00
|
|
|
width: windowState.width,
|
|
|
|
height: windowState.height,
|
|
|
|
x: windowState.x,
|
|
|
|
y: windowState.y,
|
2021-05-23 20:42:16 +00:00
|
|
|
useContentSize: true,
|
|
|
|
autoHideMenuBar: true,
|
2021-05-29 11:58:10 +00:00
|
|
|
icon: path.join(__dirname, os.platform() === 'win32' ? 'build/icon.ico' : 'build/64x64.png'),
|
2021-05-23 20:42:16 +00:00
|
|
|
webPreferences: {
|
|
|
|
preload: path.join(__dirname, 'preload.js')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
win.setMenu(null)
|
|
|
|
|
2021-06-29 13:58:25 +00:00
|
|
|
if (argv.dev){
|
|
|
|
const menu = new Menu()
|
|
|
|
menu.append(new MenuItem({
|
|
|
|
label: 'DevTools',
|
|
|
|
submenu: [
|
|
|
|
{ role: 'reload', accelerator: 'f5', click: () => { win.reload() } },
|
|
|
|
{ role: 'devtools', accelerator: 'f12', click: () => { win.webContents.toggleDevTools() } }
|
|
|
|
]
|
|
|
|
}))
|
|
|
|
Menu.setApplicationMenu(menu)
|
2021-05-23 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open links in external browser
|
|
|
|
win.webContents.on('new-window', function(e, url) {
|
|
|
|
e.preventDefault()
|
|
|
|
shell.openExternal(url)
|
|
|
|
})
|
|
|
|
|
2021-06-29 13:58:25 +00:00
|
|
|
win.loadURL(`http://${argv.host}:${PORT}`)
|
2021-05-29 10:33:20 +00:00
|
|
|
|
|
|
|
if (windowState.maximized) {
|
|
|
|
win.maximize();
|
|
|
|
}
|
|
|
|
|
|
|
|
win.on('close', (event)=>{
|
|
|
|
windowState.saveState(win);
|
|
|
|
})
|
2021-05-23 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
createWindow()
|
2021-05-29 10:33:20 +00:00
|
|
|
contextMenu({
|
|
|
|
showLookUpSelection: false,
|
|
|
|
showSearchWithGoogle: false,
|
|
|
|
showInspectElement: false
|
|
|
|
})
|
2021-05-23 20:42:16 +00:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
}
|
|
|
|
})
|
2021-05-28 10:40:06 +00:00
|
|
|
|
|
|
|
ipcMain.on('openDownloadsFolder', (event)=>{
|
2021-07-02 17:57:06 +00:00
|
|
|
const { downloadLocation } = server.getSettings().settings
|
2021-05-28 10:40:06 +00:00
|
|
|
shell.openPath(downloadLocation)
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('selectDownloadFolder', async (event, downloadLocation)=>{
|
|
|
|
let path = await dialog.showOpenDialog(win, {
|
|
|
|
defaultPath: downloadLocation,
|
|
|
|
properties: ["openDirectory", "createDirectory"]
|
|
|
|
})
|
|
|
|
if (path.filePaths[0]) win.webContents.send("downloadFolderSelected", path.filePaths[0])
|
|
|
|
})
|