Skip to content

Commit

Permalink
Updates for settings
Browse files Browse the repository at this point in the history
Communicate settings updates to viewer window
Remove force of light theme
Set global variables for electron and mainWindow
Add core to global
Initialize menu after initializing core
Use localStorage for preference storage in addition to JSON file so viewer window can pull on settings updates
Pull latest HTML
  • Loading branch information
navdeepsinghkhalsa committed Apr 20, 2017
1 parent c5cf7a1 commit b741e48
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 33 deletions.
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,10 @@ ipcMain.on('show-text', (event, arg) => {
}
});

ipcMain.on('update-settings', () => {
if (viewerWindow) {
viewerWindow.webContents.send('update-settings');
}
});

ipcMain.on('openChangelog', openChangelog);
2 changes: 1 addition & 1 deletion www/core
Submodule core updated from 4925cd to e0770c
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="assets/css/bundle.css">
<link rel="stylesheet" href="core/css/font-awesome.min.css">
</head>
<body class="home light-theme">
<body class="home">
<div id="titlebar" class="noselect">
<a href="#" class="menu-button">
<svg x="0px" y="0px" viewbox="0 0 10 10">
Expand Down
6 changes: 3 additions & 3 deletions www/js/defaults.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"userPrefs": {
"app": {
"theme": "light-theme"
},
"searchResults": {
"translationEnglish": "ssk",
"transliteration": true,
"meta": true
},
"presenterWindow": {
"theme": "light-theme"
}
},
"gurmukhiKB": false,
Expand Down
8 changes: 6 additions & 2 deletions www/js/desktop_index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/* eslint import/no-unresolved: 0 */
global.electron = true;
global.mainWindow = true;

const fs = require('fs');
const path = require('path');
global.platform = require('./js/desktop_scripts');
global.controller = require('./js/controller');
const core = require('./core/js/index');
global.core = require('./core/js/index');

// Pull in navigator from core
const navigator = fs.readFileSync(path.resolve(__dirname, 'core/navigator.html'));
document.querySelector('#navigator').innerHTML = navigator;
core.search.init();
global.core.search.init();
global.core.menu.init();

document.body.classList.add(process.platform);
4 changes: 2 additions & 2 deletions www/js/desktop_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ module.exports = {
db,
store,

getAllPrefs() {
return this.getPref('userPrefs');
getAllPrefs(schema = store.data) {
return this.getPref('userPrefs', schema);
},

getUserPref(key) {
Expand Down
16 changes: 14 additions & 2 deletions www/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,41 @@ class Store {

this.data = parseDataFile(this.path, opts.defaults);
this.defaults = opts.defaults;

// Write preferences to localStorage for viewers
this.combined = ldDefaultsDeep(this.data, this.defaults);
window.localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
}

// This will just return the property on the `data` object
get(key) {
const combined = ldDefaultsDeep(this.data, this.defaults);
return ldGet(combined, key);
return ldGet(this.combined, key);
}

// ...and this will set it
set(key, val) {
ldSet(this.data, key, val);
this.combined = ldDefaultsDeep(this.data, this.defaults);

// Wait, I thought using the node.js' synchronous APIs was bad form?
// We're not writing a server so there's not nearly the same IO demand on the process
// Also if we used an async API and our app was quit
// before the asynchronous write had a chance to complete,
// we might lose that data. Note that in a real app, we would try/catch this.
fs.writeFileSync(this.path, JSON.stringify(this.data));

// Update localStorage for viewer
window.localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
}

delete(key) {
delete this.data[key];
this.combined = ldDefaultsDeep(this.data, this.defaults);

fs.writeFileSync(this.path, JSON.stringify(this.data));

// Update localStorage for viewer
window.localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
}
}

Expand Down
41 changes: 19 additions & 22 deletions www/js/viewer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint global-require: 0, import/no-unresolved: 0 */
const platform = global.platform || require('./js/desktop_scripts');
/* eslint global-require: 0, import/no-unresolved: 0, import/no-dynamic-require: 0 */
global.platform = global.platform || require('./js/desktop_scripts');
const h = require('hyperscript');

const corePath = (global.mainWindow ? '..' : '.');
const core = require(`${corePath}/core/js/index`);

let prefs = JSON.parse(window.localStorage.getItem('prefs'));

const decks = [];
let currentShabad;
const $message = document.getElementById('message');
Expand All @@ -10,38 +15,30 @@ const $viewer = document.getElementById('viewer');

$body.classList.add(process.platform);

if (!global.mainWindow) {
core.menu.settings.applySettings(prefs);
}

function hideDecks() {
Array.from(document.querySelectorAll('.deck')).forEach((el) => {
el.classList.remove('active');
});
}

function changeTheme(theme) {
$body.classList.forEach((bodyClass) => {
if (bodyClass.indexOf('theme') > -1) {
// $body.classList.remove(i);
}
});
$body.classList.add(theme);
}

function applyPresenterPrefs(prefs) {
// changeTheme(prefs.theme);
changeTheme('light-theme');
}

const prefs = platform.store.get('userPrefs.presenterWindow');
applyPresenterPrefs(prefs);

// IPC
platform.ipc.on('show-line', (event, data) => {
global.platform.ipc.on('show-line', (event, data) => {
module.exports.showLine(data.shabadID, data.lineID);
});

platform.ipc.on('show-text', (event, data) => {
global.platform.ipc.on('show-text', (event, data) => {
module.exports.showText(data.text);
});

global.platform.ipc.on('update-settings', () => {
prefs = JSON.parse(window.localStorage.getItem('prefs'));
core.menu.settings.applySettings(prefs);
});

module.exports = {
showLine(shabadID, lineID) {
const newShabadID = parseInt(shabadID, 10);
Expand All @@ -55,7 +52,7 @@ module.exports = {
Array.from($shabadDeck.querySelectorAll('.slide')).forEach(el => el.classList.remove('active'));
document.getElementById(`slide${lineID}`).classList.add('active');
} else {
platform.db.all(`SELECT v.ID, v.Gurmukhi, v.English, v.transliteration, v.PunjabiUni FROM Verse v LEFT JOIN Shabad s ON v.ID = s.VerseID WHERE s.ShabadID = ${newShabadID} ORDER BY v.ID ASC`,
global.platform.db.all(`SELECT v.ID, v.Gurmukhi, v.English, v.transliteration, v.PunjabiUni FROM Verse v LEFT JOIN Shabad s ON v.ID = s.VerseID WHERE s.ShabadID = ${newShabadID} ORDER BY v.ID ASC`,
(err, rows) => {
if (rows.length > 0) {
const cards = [];
Expand Down

0 comments on commit b741e48

Please sign in to comment.