diff --git a/build/electron.js b/build/electron.js new file mode 100644 index 0000000..dfeb60f --- /dev/null +++ b/build/electron.js @@ -0,0 +1,86 @@ +const { app, Tray, Menu, shell } = require('electron'); +const fs = require('fs'); +const path = require('path'); +const mkdirp = require('make-dir'); +const server = require('../src/server'); + +let appIcon; +let trayTemplate; + +const configFile = path.join(app.getPath('userData'), 'save/server-config-v3.json'); + +if (!fs.existsSync(path.join(app.getPath('userData'), 'image-cache'))) { + mkdirp(path.join(app.getPath('userData'), 'image-cache')); +} + +if (!fs.existsSync(path.join(app.getPath('userData'), 'save'))) { + mkdirp(path.join(app.getPath('userData'), 'save')); +} + +if (!fs.existsSync(path.join(app.getPath('userData'), 'logs'))) { + mkdirp(path.join(app.getPath('userData'), 'logs')); +} + +if (!fs.existsSync(path.join(app.getPath('userData'), 'sync'))) { + mkdirp(path.join(app.getPath('userData'), 'sync')); +} + +if (!fs.existsSync(path.join(app.getPath('userData'), 'ffmpeg'))) { + mkdirp(path.join(app.getPath('userData'), 'ffmpeg')); +} + +app.whenReady().then(bootServer); + +function bootServer() { + let program; + try { + program = JSON.parse(fs.readFileSync(configFile)); + } catch (err) { + fs.writeFileSync(configFile, JSON.stringify({}), 'utf8'); + program = JSON.parse(fs.readFileSync(configFile)); + } + + const protocol = program.ssl && program.ssl.cert && program.ssl.key ? 'https' : 'http'; + trayTemplate = [ + { + label: `mStream Server v${app.getVersion()}`, click: () => { + shell.openExternal('http://mstream.io/'); + } + }, + // { + // label: 'Check For Updates', click: function () { + // autoUpdater.checkForUpdatesAndNotify(); + // } + // }, + { label: 'Links', submenu: [ + { + label: `${protocol}://localhost:${program.port}`, click: () => { + shell.openExternal(protocol + '://localhost:' + program.port) + } + }, + { + label: `${protocol}://localhost:${program.port}/admin`, click: () => { + shell.openExternal(`${protocol}://localhost:${program.port}/admin`) + } + }, + ] }, + { type: 'separator' }, + { + label: 'Restart Server', click: function () { + app.isQuiting = true; + app.quit(); + } + }, + { + label: 'Quit', click: function () { + app.isQuiting = true; + app.quit(); + } + } + ]; + + appIcon = new Tray(process.platform === 'darwin' ? path.join(__dirname, 'tray-icon.png') : path.join(__dirname, 'tray-icon-osx.png')); + appIcon.setContextMenu(Menu.buildFromTemplate(trayTemplate)); // Call this again if you modify the tray menu + + server.serveIt(configFile); +} \ No newline at end of file diff --git a/cli-boot-wrapper.js b/cli-boot-wrapper.js index d85f611..d9f6f8b 100755 --- a/cli-boot-wrapper.js +++ b/cli-boot-wrapper.js @@ -4,7 +4,7 @@ // Check if we are in an electron environment if (process.versions["electron"]) { // off to a separate electron boot environment - return require("./mstream-electron.js"); + return require("./build/electron"); } const program = require('commander'); @@ -21,21 +21,16 @@ console.log(` | | | | | |___) | |_| | | __/ (_| | | | | | | |_| |_| |_|____/ \\__|_| \\___|\\__,_|_| |_| |_|`); console.log(); -console.log('v5.0-alpha'); +console.log('v5.0-beta'); console.log(); -console.log('mStream Server is undergoing some changes. Some things may break. Please expect the following:') -console.log('-- CLI Wizard will be removed and replaced with a UI tool'); -console.log('-- Config files changes. Your old config files WILL become invalid. There will be new UI and CLI tools to assist in the setup of new config files'); -console.log('-- DB Structure Changes. Your DB might be re-scanned at some point'); +console.log('Breaking Changes'); +console.log('-- Config files from v4 will not work'); +console.log('-- The Android App does not work with v5 (for now)'); +console.log('-- You can no longer boot mStream with CLI flags'); console.log(); -console.log('v5 Updates:') -console.log('-- A New Admin Panel where you can set update server configurations'); -console.log('-- Fog Machine integration (https://fog.fm). FM is an optional feature to make mStream even easier to deploy'); -console.log('-- A lot of code cleanup'); -console.log(); -console.log('Have questions about v5? Chat with me on Discord to find out more:'); +console.log('Check out our Discord server:'); console.log('https://discord.gg/AM896Rr'); console.log(); // Boot the server -require("./mstream.js").serveIt(program.json); +require("./src/server").serveIt(program.json); diff --git a/package.json b/package.json index 4e7b738..c536168 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ }, "scripts": { "start": "node cli-boot-wrapper.js", - "wizard": "node cli-boot-wrapper.js --wizard", "pack": "electron-builder --dir", "dist": "electron-builder" }, @@ -28,7 +27,7 @@ "build": { "appId": "io.mstream.server", "productName": "mStream Server", - "electronVersion": "6.1.3", + "electronVersion": "12.0.0", "asar": false, "files": [ "**/*", diff --git a/mstream.js b/src/server.js old mode 100755 new mode 100644 similarity index 81% rename from mstream.js rename to src/server.js index 85ec5c8..560de1b --- a/mstream.js +++ b/src/server.js @@ -3,20 +3,19 @@ const express = require('express'); const fs = require('fs'); const bodyParser = require('body-parser'); -const dbApi = require('./src/api/db'); -const playlistApi = require('./src/api/playlist'); -const authApi = require('./src/api/auth'); -const fileExplorerApi = require('./src/api/file-explorer'); -const downloadApi = require('./src/api/download'); -const adminApi = require('./src/api/admin') -const remoteApi = require('./src/api/remote'); -const sharedApi = require('./src/api/shared'); -const scrobblerApi = require('./src/api/scrobbler'); -const ddns = require('./modules/ddns'); -const config = require('./src/state/config'); -const logger = require('./src/logger'); -const transode = require('./src/api/transcode'); -const dbManager = require('./src/db/manager'); +const dbApi = require('./api/db'); +const playlistApi = require('./api/playlist'); +const authApi = require('./api/auth'); +const fileExplorerApi = require('./api/file-explorer'); +const downloadApi = require('./api/download'); +const adminApi = require('./api/admin') +const remoteApi = require('./api/remote'); +const sharedApi = require('./api/shared'); +const scrobblerApi = require('./api/scrobbler'); +const config = require('./state/config'); +const logger = require('./logger'); +const transode = require('./api/transcode'); +const dbManager = require('./db/manager'); let mstream; let server; @@ -102,8 +101,7 @@ exports.serveIt = async configFile => { const protocol = config.program.ssl && config.program.ssl.cert && config.program.ssl.key ? 'https' : 'http'; winston.info(`Access mStream locally: ${protocol}://${config.program.address}:${config.program.port}`); - require('./src/db/task-queue').runAfterBoot(); - ddns.setup(config.program); + require('./db/task-queue').runAfterBoot(); }); }; diff --git a/src/util/admin.js b/src/util/admin.js index a15bd0d..795fc91 100644 --- a/src/util/admin.js +++ b/src/util/admin.js @@ -2,7 +2,7 @@ const fs = require("fs").promises; const express = require('express'); const auth = require('./auth'); const config = require('../state/config'); -const mStreamServer = require('../../mstream'); +const mStreamServer = require('../server'); const dbQueue = require('../db/task-queue'); const logger = require('../logger'); const db = require('../db/manager');