Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
feat(themes): theme switching
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiantheblind committed Aug 10, 2016
1 parent a7959e7 commit 090d4bb
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 437 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"start": "NODE_ENV=development ./node_modules/.bin/electron app/main.js",
"prewatch": "echo ' cleaning app/ folder except node_modules' && find app/* -maxdepth 0 -name 'node_modules' -prune -o -exec rm -rf '{}' ';'",
"watch": "./node_modules/.bin/babel src -w -d app -D",
"sass": "./node_modules/.bin/node-sass -w src/views/themes/default/scss/ -o src/views/themes/default/css/ --output-style=compact",
"sassblank": "./node_modules/.bin/node-sass -w src/views/themes/blank/scss/ -o src/views/themes/blank/css/ --output-style=compact",
"sassdefault": "./node_modules/.bin/node-sass -w src/views/themes/default/scss/ -o src/views/themes/default/css/ --output-style=compact",
"test": "./node_modules/.bin/mocha --compilers js:babel-register",
"pandoc": "echo 'trying to create markdown via pandoc for testing css in ./test/index.html' && sh bin/pandoc.sh",
"postinstall": "install-app-deps",
Expand Down
3 changes: 2 additions & 1 deletion src/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"defaults": {
"recentFiles": [],
"showIntroOnStratup": true,
"maxRecentFiles":10
"maxRecentFiles":10,
"currentTheme": "default"
},
"name": "frontal"
}
2 changes: 1 addition & 1 deletion src/help/help-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function initialHelpLoader(wins) {
wins.forEach((w, i, arr) => {
w.webContents.on('did-finish-load', () => {
send(w, 'slides', slidesHTML);
send(w, 'switch-theme', {path: 'themes/default'});
send(w, 'switch-theme', global.config.get('currentTheme'));
});
});
}
18 changes: 18 additions & 0 deletions src/lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {watch} from './watcher';
import {yamlLoader} from './load-yaml';
import {tomlLoader} from './load-toml';
import {dirname, resolve} from 'path';
import * as fs from 'fs';

export function detectTomlConfig(filePath) {
var onlypath = dirname(filePath);
Expand Down Expand Up @@ -55,3 +56,20 @@ export function processFile(file) {
sender([global.slidesWindow, global.commentsWindow], 'slides', slidesHTML);
}


export function getDirs (rootDir, cb) {
let files = fs.readdirSync(rootDir);
// console.log(files);
var dirs = [];
for (let index = 0; index < files.length; index++) {
let file = files[index];
// if (file[0] !== '.') {
let filePath = rootDir + '/' + file;
let stat = fs.statSync(filePath);
if(stat.isDirectory()) {
dirs.push(file);
// }
}
}
return dirs;
}
25 changes: 25 additions & 0 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ export function buildTemplate(windows) {
}, {
label: 'View',
submenu: [{
label: 'Themes',
submenu:
(()=>{
let currentTheme = global.config.get('currentTheme');
let dirs = getDirs(__dirname + '/views/themes');
let res = [];
for(let i = 0; i < dirs.length; i++) {
res.push({
label: dirs[i],
type: 'radio',
checked: (dirs[i] === currentTheme ? true : false),
click: ()=>{
console.log(`in menu creation ${dirs[i]}`);
switchTheme(`${dirs[i]}`);
}});
}
res.push({type: 'separator'});
res.push({label: 'Load Custom CSS...', click: ()=>{
console.log('should load a custom CSS');
}});
return res;
})()
}, {
type: 'separator'
}, {
label: 'Previous',
accelerator: 'Up',
click: function() {
Expand Down
3 changes: 2 additions & 1 deletion src/views/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<head>
<meta charset="UTF-8">
<title>Speaker Notes</title>
<link rel="stylesheet" type="text/css" href="./themes/default/css/default-comments.css">

<link rel="stylesheet" id="comments-link" type="text/css" href="./themes/default/css/main-comments.css">
</head>
<body id="notes">
<header id="speaker-notes">
Expand Down
1 change: 1 addition & 0 deletions src/views/lib/slide-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// - require all files in theme/js
// and execute them
// the js file can export one default function so we only have to execute on thing
const {ipcRenderer} = require('electron');

var libs = require('require-all')(__dirname + '/themes/default/js');
const $ = require('jquery');
Expand Down
19 changes: 15 additions & 4 deletions src/views/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,20 @@ window.onload = () => { // eslint-disable-line no-undef
});
}

function changeCSS(cssFilePath, cssLinkIndex) {
function switchCSS(themeName, cssLinkIndex) {
let cssFilePath = __dirname + '/themes/' + themeName + '/css/';
let oldLink = document.getElementsByTagName('link').item(cssLinkIndex); // eslint-disable-line no-undef
let newLink = document.createElement('link'); // eslint-disable-line no-undef
newLink.setAttribute('rel', 'stylesheet');
newLink.setAttribute('type', 'text/css');
newLink.setAttribute('href', cssFilePath);
if(oldLink.id === 'slides-link') {
newLink.setAttribute('id', 'slides-link');
newLink.setAttribute('href', cssFilePath + 'main.css');

}else if(oldLink.id === 'comments-link') {
newLink.setAttribute('id', 'comments-link');
newLink.setAttribute('href', cssFilePath + 'main-comments.css');
}
document.getElementsByTagName('head').item(0).replaceChild(newLink, oldLink); // eslint-disable-line no-undef
}
// -----------execution-------------------
Expand Down Expand Up @@ -211,10 +219,13 @@ window.onload = () => { // eslint-disable-line no-undef
ipcRenderer.on('hello', (event, arg) => {
// console.log('hello');
});

ipcRenderer.on('switch-theme', (event, arg) => {
console.log(arg);
themeLoaderJS(__dirname + '/' + arg.msg.path + '/js');
console.log('switcht ', arg.msg);
// themeLoaderJS(__dirname + '/' + arg.msg.path + '/js');
switchCSS(arg.msg, 0);
});

ipcRenderer.on('plus', (event, arg) => {
// console.log(arg);
// zoomFactorSlides += 0.1;
Expand Down
3 changes: 1 addition & 2 deletions src/views/slides.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Slides</title>
<link rel="stylesheet" type="text/css" href="./themes/default/css/default.css">
<link rel="stylesheet" href="./themes/default/css/solarized-light-default.css">
<link rel="stylesheet" id="slides-link" type="text/css" href="./themes/default/css/main.css">
</head>
<body id="frontal">
<header id="header"></header>
Expand Down
62 changes: 0 additions & 62 deletions src/views/themes/default/css/default-comments.css

This file was deleted.

113 changes: 0 additions & 113 deletions src/views/themes/default/scss/default-comments.scss

This file was deleted.

Loading

0 comments on commit 090d4bb

Please sign in to comment.