diff --git a/main.js b/main.js index 9cc72eb..f148030 100644 --- a/main.js +++ b/main.js @@ -9,7 +9,6 @@ require('electron-debug')(); // 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 win - const options = {userAgent: 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F27E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36'}; function createWindow () { @@ -35,6 +34,11 @@ function createWindow () { // Some APIs can only be used after this event occurs. app.on('ready', createWindow) +ipc.on('log-out',function(){ + console.log("logging out"); + win.webContents.session.clearStorageData({storages: "cookies"});win.loadURL("http://pf.gree.net/58737",options); +}); + // Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar diff --git a/menu.js b/menu.js index e2c1729..2b212c5 100644 --- a/menu.js +++ b/menu.js @@ -1,5 +1,7 @@ const { app, Menu } = require('electron'); const navi = require('./dock'); +const prefman = require('./preferencemanager'); +const ipc = require('electron').ipcMain; const options = {userAgent: 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F27E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36'}; @@ -50,9 +52,11 @@ module.exports = function(win){ template.unshift({ label: app.getName(), submenu: [ - {role: 'about'}, + {label: 'About Million Hopes',click(){prefman.showAbout()}}, {label: "Clear Cookies / Log Out",click(){win.webContents.session.clearStorageData({storages: "cookies"});win.loadURL("http://pf.gree.net/58737",options)}}, {type: 'separator'}, + {label: 'Preferences',click(){prefman.showPreferences()}}, + {type: 'separator'}, {role: 'services', submenu: []}, {type: 'separator'}, {role: 'hide'}, diff --git a/preferencemanager.js b/preferencemanager.js new file mode 100644 index 0000000..46ef284 --- /dev/null +++ b/preferencemanager.js @@ -0,0 +1,37 @@ +const {app, Menu, BrowserWindow} = require('electron') + +const url = require('url') + +const path = require('path') + +let preferencesWindow; + +require('electron-debug')(); +function showPreferences_int(){ + if(!preferencesWindow){ + preferencesWindow = new BrowserWindow({width: 800, height: 600}) + preferencesWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'preferences.html'), + protocol: 'file:', + slashes: true + })) + preferencesWindow.on('closed', () => { + // Dereference the window object, usually you would store windows + // in an array if your app supports multi windows, this is the time + // when you should delete the corresponding element. + preferencesWindow = null + }) +} +} +module.exports.showPreferences = function(){ + showPreferences_int(); + preferencesWindow.webContents.on('did-finish-load', function() { + preferencesWindow.webContents.executeJavaScript("document.getElementById('mh-pane-general').click();"); +}); +} +module.exports.showAbout = function(){ + showPreferences_int(); + preferencesWindow.webContents.on('did-finish-load', function() { + preferencesWindow.webContents.executeJavaScript("document.getElementById('mh-pane-about').click();"); + }); + } diff --git a/preferences.html b/preferences.html index ad13755..8bf42e4 100644 --- a/preferences.html +++ b/preferences.html @@ -1,33 +1,57 @@ - Photon + Million Hopes Preferences - + - -
-
-

Photon

-
-

Welcome to Photon

-

- Thanks for downloading Photon. This is an example HTML page that's linked up to compiled Photon CSS, has the proper meta tags - and the HTML structure. -

+
+ +
+
General preferences
+
+ There aren't any configurable options currently in this tab. +
+
+
Log out
+

Logs you out of Million Live!

+
+
+
About
+

Million Hopes

+ "" +

A client for the game THE IDOLM@STER: Million Live!, using Electron.

+
+
+
+ diff --git a/preferences.js b/preferences.js new file mode 100644 index 0000000..4795f64 --- /dev/null +++ b/preferences.js @@ -0,0 +1,29 @@ +const ipc = require('electron').ipcRenderer; + +function logout_click(){ + ipc.send('log-out'); +} + +function genericpane_click(evt,prefname){ + var i, tabcontent, tablinks; + tabcontent = document.getElementsByClassName("mh-prefs"); + for (i = 0; i < tabcontent.length; i++) { + tabcontent[i].style.display = "none"; + } + + // Get all elements with class="tablinks" and remove the class "active" + tablinks = document.getElementsByClassName("nav-group-item"); + for (i = 0; i < tablinks.length; i++) { + tablinks[i].classList.remove("active"); + } + + // Show the current tab, and add an "active" class to the button that opened the tab + document.getElementById(prefname).style.display = "block"; + document.getElementById(prefname.replace("pref","pane")).classList.add("active"); + + const asyncMsgBtn = document.getElementById('mh-account-logout'); + asyncMsgBtn.addEventListener('click', function () { + ipc.send('log-out') + }) + +}