preferences window

This commit is contained in:
Damillora 2017-07-03 23:56:29 +07:00
parent 66a371a0cf
commit ed3f79d627
5 changed files with 112 additions and 14 deletions

View File

@ -9,7 +9,6 @@ require('electron-debug')();
// Keep a global reference of the window object, if you don't, the window will // 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. // be closed automatically when the JavaScript object is garbage collected.
let win 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'}; 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 () { function createWindow () {
@ -35,6 +34,11 @@ function createWindow () {
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', createWindow) 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. // Quit when all windows are closed.
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar // On macOS it is common for applications and their menu bar

View File

@ -1,5 +1,7 @@
const { app, Menu } = require('electron'); const { app, Menu } = require('electron');
const navi = require('./dock'); 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'}; 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({ template.unshift({
label: app.getName(), label: app.getName(),
submenu: [ 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)}}, {label: "Clear Cookies / Log Out",click(){win.webContents.session.clearStorageData({storages: "cookies"});win.loadURL("http://pf.gree.net/58737",options)}},
{type: 'separator'}, {type: 'separator'},
{label: 'Preferences',click(){prefman.showPreferences()}},
{type: 'separator'},
{role: 'services', submenu: []}, {role: 'services', submenu: []},
{type: 'separator'}, {type: 'separator'},
{role: 'hide'}, {role: 'hide'},

37
preferencemanager.js Normal file
View File

@ -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();");
});
}

View File

@ -1,33 +1,57 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Photon</title> <title>Million Hopes Preferences</title>
<!-- Stylesheets --> <!-- Stylesheets -->
<link rel="stylesheet" href="photon.css"> <link rel="stylesheet" href="./node_modules/photonkit/dist/css/photon.css">
<!-- Electron Javascript -->
<script src="app.js" charset="utf-8"></script>
</head> </head>
<body> <body>
<!-- Wrap your entire app inside .window --> <!-- Wrap your entire app inside .window -->
<div class="window"> <div class="window">
<!-- .toolbar-header sits at the top of your app --> <!-- .toolbar-header sits at the top of your app -->
<header class="toolbar toolbar-header">
<h1 class="title">Photon</h1>
</header>
<!-- Your app's content goes inside .window-content --> <!-- Your app's content goes inside .window-content -->
<div class="window-content"> <div class="window-content">
<div class="padded-more"> <div class="padded-more">
<h1>Welcome to Photon</h1> <div class="pane-group">
<p> <div class="pane-sm sidebar">
Thanks for downloading Photon. This is an example HTML page that's linked up to compiled Photon CSS, has the proper meta tags <nav class="nav-group">
and the HTML structure. <h5 class="nav-group-title">Preferences</h5>
</p> <a id="mh-pane-general" class="nav-group-item active" onclick="genericpane_click(event,'mh-pref-general')">
General
</a>
<a id="mh-pane-account" class="nav-group-item" onclick="genericpane_click(event,'mh-pref-account')">
Account
</a>
<a id="mh-pane-about" class="nav-group-item" onclick="genericpane_click(event,'mh-pref-about')">
About
</a>
</nav>
</div>
<div class="pane padded-more">
<h5>General preferences</h5>
<div id="mh-pref-general" class="mh-prefs">
There aren't any configurable options currently in this tab.
</div>
<div id="mh-pref-account" class="mh-prefs">
<h5>Log out</h5>
<p>Logs you out of Million Live!</p>
<button class="btn btn-default" id="mh-account-logout">Log out</a>
</div>
<div id="mh-pref-about" class="mh-prefs">
<h5>About</h5>
<h3>Million Hopes <script>document.write(require('electron').remote.app.getVersion())</script></h3>
<i>""</i>
<p>A client for the game THE IDOLM@STER: Million Live!, using Electron.</p>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
</div>
<script src="preferences.js"></script>
</body> </body>
</html> </html>

29
preferences.js Normal file
View File

@ -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')
})
}