Skip to content

Commit

Permalink
New Auto night mode feature
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Oct 19, 2017
1 parent 5a258d6 commit b6b185e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
51 changes: 49 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const electron = require('electron');
const os = require('os');
const path = require('path');
const timeStamp = require('time-stamp');
const config = require('./config');

const join = path.join;
Expand Down Expand Up @@ -180,13 +181,55 @@ ipc.on('toggle-vibrant-dark-mode', () => {
vibrantDarkMode();
});

function autoNightMode() {
// Switch between light and dark themes based on daytime
const time = timeStamp('HHmm');
switch (time <= 1800 && time >= 600) {
case true:
// Switch to the light theme
untoggleDark();
untoggleBlack();
untoggleSepia();
untoggleVibrant();
untoggleDarkVibrant();
break;

case false:
// Switch to the dark theme
untoggleBlack();
untoggleSepia();
untoggleVibrant();
untoggleDarkVibrant();
config.set('darkMode', true);
darkMode();
break;

default:
break;
}
}

function untoggleAutoNightMode() {
// Untoggle the auto night mode
untoggleDark();
}

ipc.on('auto-night-mode', () => {
// Toggle on and off the auto night mode
if (config.get('autoNightMode')) {
autoNightMode();
} else {
untoggleAutoNightMode();
}
});

function toggleMenuBar() {
// Activates the menu bar on the main window
// Activate the menu bar on the main window
ipc.send('activate-menu-bar');
}

ipc.on('toggle-menu-bar', () => {
// Toggles on and off the menu bar
// Toggle on and off the menu bar
config.set('menuBarVisible', !config.get('menuBarVisible'));
toggleMenuBar();
});
Expand Down Expand Up @@ -481,6 +524,10 @@ document.addEventListener('DOMContentLoaded', () => {
// Preserve zoom factor
const zoomFactor = config.get('zoomFactor');
webFrame.setZoomFactor(zoomFactor);
// Toggle auto night mode
if (config.get('autoNightMode')) {
autoNightMode();
}
// Toggle the menu bar
toggleMenuBar();
// Toggle sepia mode
Expand Down
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = new Config({
height: 500
},
menuBarVisible: false,
autoNightMode: false,
darkMode: false,
blackMode: false,
sepiaMode: false,
Expand Down
18 changes: 18 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ const darwinTpl = [{
activate('toggle-vibrant-dark-mode');
}
}]
}, {
label: 'Auto Night Mode',
type: 'checkbox',
checked: config.get('autoNightMode'),
accelerator: 'CmdorCtrl+Alt+N',
click(item) {
config.set('autoNightMode', item.checked);
activate('auto-night-mode');
}
}, {
type: 'separator'
}, {
Expand Down Expand Up @@ -781,6 +790,15 @@ const otherTpl = [{
activate('toggle-black-mode');
}
}]
}, {
label: 'Auto Night Mode',
type: 'checkbox',
checked: config.get('autoNightMode'),
accelerator: 'CmdorCtrl+Alt+N',
click(item) {
config.set('autoNightMode', item.checked);
activate('auto-night-mode');
}
}, {
type: 'separator'
}, {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Align Left | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>L</kbd>
Align Center | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>M</kbd>
Align Right | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>R</kbd>
Increase Indentation | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>K</kbd>
Activate Auto Night Mode | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>N</kbd>
Make Text Larger | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>=</kbd>
Export Note as PDF | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>E</kbd>
New Tag | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>T</kbd>
Expand Down
10 changes: 10 additions & 0 deletions tray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const path = require('path');
const electron = require('electron');
const config = require('./config');

const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
Expand Down Expand Up @@ -98,6 +99,15 @@ exports.create = win => {
activate('toggle-black-mode');
}
}]
}, {
label: 'Auto Night Mode',
type: 'checkbox',
checked: config.get('autoNightMode'),
click(item) {
showWin();
config.set('autoNightMode', item.checked);
activate('auto-night-mode');
}
}, {
type: 'separator'
}, {
Expand Down

0 comments on commit b6b185e

Please sign in to comment.