diff --git a/package-lock.json b/package-lock.json index 01f8e97..a9010ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "lotr-desktop", "version": "1.0.0", "license": "MIT", "dependencies": { diff --git a/src/index.html b/src/index.html index f767433..55c07d7 100644 --- a/src/index.html +++ b/src/index.html @@ -1,11 +1,14 @@ - - - Land of the Rair - - - - - - + + + + Land of the Rair + + + + + + + + \ No newline at end of file diff --git a/src/index.js b/src/index.js index 1de157c..657f7eb 100644 --- a/src/index.js +++ b/src/index.js @@ -1,29 +1,29 @@ -const { app, BrowserWindow, shell } = require('electron'); -const DiscordRPC = require('discord-rpc'); -const startCase = require('lodash.startcase'); -const path = require('path'); +const { app, BrowserWindow, shell } = require("electron"); +const DiscordRPC = require("discord-rpc"); +const startCase = require("lodash.startcase"); +const path = require("path"); -const Config = require('electron-config'); +const Config = require("electron-config"); const config = new Config(); // Handle creating/removing shortcuts on Windows when installing/uninstalling. -if (require('electron-squirrel-startup')) { // eslint-disable-line global-require +if (require("electron-squirrel-startup")) { + // eslint-disable-line global-require app.quit(); } let mainWindow; const createWindow = () => { - - const opts = { - show: false, - icon: __dirname + '/favicon.ico' + const opts = { + show: false, + icon: __dirname + "/favicon.ico", }; - Object.assign(opts, config.get('winBounds')); + Object.assign(opts, config.get("winBounds")); - if(!opts.height) opts.height = 900; - if(!opts.width) opts.width = 1300; + if (!opts.height) opts.height = 900; + if (!opts.width) opts.width = 1300; // Create the browser window. mainWindow = new BrowserWindow({ @@ -31,19 +31,19 @@ const createWindow = () => { webPreferences: { webviewTag: true, nodeIntegration: true, - nativeWindowOpen: true - } + nativeWindowOpen: true, + }, }); mainWindow.setMenu(null); - mainWindow.once('ready-to-show', mainWindow.show); + mainWindow.once("ready-to-show", mainWindow.show); - mainWindow.on('close', () => { - config.set('winBounds', mainWindow.getBounds()); + mainWindow.on("close", () => { + config.set("winBounds", mainWindow.getBounds()); }); // and load the index.html of the app. - mainWindow.loadFile(path.join(__dirname, 'index.html')); + mainWindow.loadFile(path.join(__dirname, "index.html")); // Open the DevTools. // mainWindow.webContents.openDevTools(); @@ -52,18 +52,18 @@ const createWindow = () => { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on('ready', createWindow); +app.on("ready", createWindow); // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { +app.on("window-all-closed", () => { + if (process.platform !== "darwin") { app.quit(); } }); -app.on('activate', () => { +app.on("activate", () => { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) { @@ -71,61 +71,65 @@ app.on('activate', () => { } }); -app.on('web-contents-created', (e, contents) => { - if(contents.getType() === 'webview') { +app.on("web-contents-created", (e, contents) => { + if (contents.getType() === "webview") { + contents.setWindowOpenHandler(({ url }) => { + shell.openExternal(url); + return { action: "deny" }; + }); - contents.addListener('will-navigate', (e, url) => { + contents.addListener("will-navigate", (e, url) => { e.preventDefault(); shell.openExternal(url); }); } -}) +}); // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and import them here. -const DISCORD_CLIENT_ID = '410478620096856064'; +const DISCORD_CLIENT_ID = "410478620096856064"; DiscordRPC.register(DISCORD_CLIENT_ID); let startTimestamp; -const rpc = new DiscordRPC.Client({ transport: 'ipc' }); +const rpc = new DiscordRPC.Client({ transport: "ipc" }); const setActivity = () => { - if(!rpc || !mainWindow) return; - - mainWindow.webContents.executeJavaScript('document.getElementById("game").executeJavaScript("window.discordGlobalCharacter")') - .then(function(char) { - if(!char) { + if (!rpc || !mainWindow) return; + + mainWindow.webContents + .executeJavaScript( + 'document.getElementById("game").executeJavaScript("window.discordGlobalCharacter")' + ) + .then(function (char) { + if (!char) { rpc.clearActivity(); startTimestamp = null; return; } - if(!startTimestamp) startTimestamp = new Date(); + if (!startTimestamp) startTimestamp = new Date(); rpc.setActivity({ startTimestamp, - state: 'Playing', - details: 'In ' + startCase(char.map).split('Dungeon').join('(Dungeon)'), - largeImageKey: char._gameImage || 'game-image', - largeImageText: 'Level ' + char.level + ' ' + char.baseClass + state: "Playing", + details: "In " + startCase(char.map).split("Dungeon").join("(Dungeon)"), + largeImageKey: char._gameImage || "game-image", + largeImageText: "Level " + char.level + " " + char.baseClass, }); }); - }; -rpc.on('ready', function() { +rpc.on("ready", function () { setActivity(); - setInterval(function() { + setInterval(function () { setActivity(); }, 15000); }); -rpc - .login({ clientId: DISCORD_CLIENT_ID }) - .catch(function(err) { - console.error(err); - }); \ No newline at end of file +rpc.login({ clientId: DISCORD_CLIENT_ID }).catch(function (err) { + console.error(err); +});