diff --git a/main.js b/main.js index abc7516..d0f4afa 100644 --- a/main.js +++ b/main.js @@ -13,6 +13,7 @@ const os = require('os') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow +let newsWindow const BASE_PATH = os.userInfo().homedir function createWindow() { @@ -84,3 +85,26 @@ app.on('activate', function () { // In this file you can include the rest of your src's specific main process // code. You can also put them in separate files and require them here. +exports.openANewsWindow = (uri) => { + // Create the browser window. + newsWindow = new BrowserWindow({ + width: 720, + height: 480, + parent: mainWindow + }) + + // and load the index.html of the src. + newsWindow.loadURL(uri) + + newsWindow.once('ready-to-show', () => { + newsWindow.show() + }) + + // Emitted when the window is closed. + newsWindow.on('closed', function () { + // Dereference the window object, usually you would store windows + // in an array if your src supports multi windows, this is the time + // when you should delete the corresponding element. + newsWindow = null + }) +} \ No newline at end of file diff --git a/src/news/functions.js b/src/news/functions.js index 7ef6646..cf08b35 100644 --- a/src/news/functions.js +++ b/src/news/functions.js @@ -8,9 +8,15 @@ const self = this +// Will be set via configuration file. +const inside = true + +const path = require('path') const shell = require('electron').shell +const remote = require('electron').remote const malScraper = require('mal-scraper') const index = require('./index.js') +const {openANewsWindow} = remote.require(path.join(__dirname, '..', '..', 'main.js')) exports.getNews = (object) => { let tmp = malScraper.getNewsNoDetails(() => { @@ -20,5 +26,5 @@ exports.getNews = (object) => { } exports.openLink = (link) => { - shell.openExternal(link) + inside ? openANewsWindow(link) : shell.openExternal(link) }