1 // Load settings before everything
3 const fs = require("fs-extra");
4 const path = require('path');
5 const {app, BrowserWindow, ipcMain, Menu, Tray, Notification} = require('electron');
6 const os = require('os');
9 const theApp = require('./app');
10 const WindowStateManager = require('electron-window-state-manager');
11 const url = require('url');
15 let trayIcon = __dirname + "/icon.png";
17 // Create a new instance of the WindowStateManager
18 const mainWindowState = new WindowStateManager('mainWindow', {
23 var shouldQuit = !app.requestSingleInstanceLock()
24 app.on('second-instance', function (argv, cwd) {
26 if (mainWindow.isMinimized()) mainWindow.restore();
27 if (!mainWindow.isVisible()) mainWindow.show();
37 app.isQuiting = false;
39 app.serverMode = (process.argv.indexOf("-s")>-1 || process.argv.indexOf("--server")>-1);
41 require('electron-context-menu')({
42 showInspectElement: false
45 function loadSettings(){
47 if(process.platform == "android"){
48 userdata = os.homedir() + "/storage/shared/Deezloader Remix/";
50 userdata = app.getPath("appData")+path.sep+"Deezloader Remix"+path.sep;
53 if(!fs.existsSync(userdata+"config.json")){
54 fs.outputFileSync(userdata+"config.json",fs.readFileSync(__dirname+path.sep+"default.json",'utf8'));
57 appConfig = require(userdata+path.sep+"config.json");
59 if( typeof appConfig.userDefined.numplaylistbyalbum != "boolean" ||
60 typeof appConfig.userDefined.syncedlyrics != "boolean" ||
61 typeof appConfig.userDefined.padtrck != "boolean" ||
62 typeof appConfig.userDefined.albumNameTemplate != "string"
64 fs.outputFileSync(userdata+"config.json",fs.readFileSync(__dirname+path.sep+"default.json",'utf8'));
65 appConfig = require(userdata+path.sep+"config.json");
72 { label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
76 { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
77 { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
78 { type: "separator" },
79 { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
80 { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
81 { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
82 { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
86 Menu.setApplicationMenu(Menu.buildFromTemplate(template))
88 function createTray(){
89 tray = new Tray(trayIcon);
90 const contextMenu = Menu.buildFromTemplate([
94 if (mainWindow) mainWindow.show();
100 app.isQuiting = true;
101 if (mainWindow){mainWindow.close()}else{app.quit()};
105 tray.setToolTip('Deezloader Remix');
106 tray.setContextMenu(contextMenu);
108 tray.on('click', function(e){
110 if (mainWindow.isVisible()) {
119 function createWindow () {
120 // Create the browser window.
121 mainWindow = new BrowserWindow({
122 width: mainWindowState.width,
123 height: mainWindowState.height,
124 x: mainWindowState.x,
125 y: mainWindowState.y,
128 icon: __dirname + "/icon.png",
131 backgroundColor: "#23232c"
134 mainWindow.setMenu(null);
136 // and load the index.html of the app.
137 mainWindow.loadURL('http://localhost:' + appConfig.serverPort);
139 mainWindow.on('closed', function () {
143 // Check if window was closed maximized and restore it
144 if (mainWindowState.maximized) {
145 mainWindow.maximize();
148 // Save current window state
149 mainWindow.on('close', (event) => {
150 if(appConfig.userDefined.minimizeToTray && !app.isQuiting){
151 event.preventDefault()
154 mainWindowState.saveState(mainWindow);
159 app.on('ready', function(){
160 if (!app.serverMode){
166 // Quit when all windows are closed.
167 app.on('window-all-closed', function () {
168 if (!appConfig.userDefined.minimizeToTray || app.isQuiting){
173 app.on('activate', function () {
174 if (!app.serverMode && mainWindow === null) {