Skip to content

Commit

Permalink
Open separate windows with theme, update settings theme on change
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jul 13, 2018
1 parent d014fa7 commit d8e5e5f
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions debug_log_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = url.parse(window.location.toString(), true).query;
const { locale } = config;
const localeMessages = ipcRenderer.sendSync('locale-data');

window.theme = config.theme;
window.i18n = i18n.setup(locale, localeMessages);

// got.js appears to need this to successfully submit debug logs to the cloud
Expand Down
1 change: 1 addition & 0 deletions js/debug_log_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(document).on('keyup', function(e) {
});

const $body = $(document.body);
$body.addClass(window.theme);

// got.js appears to need this to successfully submit debug logs to the cloud
window.setImmediate = window.nodeSetImmediate;
Expand Down
1 change: 1 addition & 0 deletions js/permissions_popup_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(document).on('keyup', function(e) {
});

const $body = $(document.body);
$body.addClass(window.theme);

window.view = new Whisper.ConfirmationDialogView({
message: i18n('audioPermissionNeeded'),
Expand Down
1 change: 1 addition & 0 deletions js/settings_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(document).on('keyup', function(e) {
});

const $body = $(document.body);
$body.addClass(window.theme);

const getInitialData = async () => ({
deviceName: await window.getDeviceName(),
Expand Down
10 changes: 9 additions & 1 deletion js/views/settings_view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global i18n: false */
/* global Whisper: false */
/* global $: false */

/* eslint-disable no-new */

Expand Down Expand Up @@ -82,7 +83,14 @@
el: this.$('.theme-settings'),
name: 'theme-setting',
value: window.initialData.themeSetting,
setFn: window.setThemeSetting,
setFn: theme => {
$(document.body)
.removeClass('android')
.removeClass('android-dark')
.removeClass('ios')
.addClass(theme);
window.setThemeSetting(theme);
},
});
if (Settings.isAudioNotificationSupported()) {
new CheckboxView({
Expand Down
28 changes: 19 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const loadLocale = require('./app/locale').load;
let logger;
let locale;

function prepareURL(pathSegments) {
function prepareURL(pathSegments, moreKeys) {
return url.format({
pathname: path.join.apply(null, pathSegments),
protocol: 'file:',
Expand All @@ -134,6 +134,7 @@ function prepareURL(pathSegments) {
appInstance: process.env.NODE_APP_INSTANCE,
proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy,
importMode: importMode ? true : undefined, // for stringify()
...moreKeys,
},
});
}
Expand Down Expand Up @@ -428,7 +429,7 @@ function showAbout() {
}

let settingsWindow;
function showSettingsWindow() {
async function showSettingsWindow() {
if (settingsWindow) {
settingsWindow.show();
return;
Expand All @@ -437,6 +438,7 @@ function showSettingsWindow() {
return;
}

const theme = await pify(getDataFromMainWindow)('theme-setting');
const size = mainWindow.getSize();
const options = {
width: Math.min(500, size[0]),
Expand All @@ -461,7 +463,7 @@ function showSettingsWindow() {

captureClicks(settingsWindow);

settingsWindow.loadURL(prepareURL([__dirname, 'settings.html']));
settingsWindow.loadURL(prepareURL([__dirname, 'settings.html'], { theme }));

settingsWindow.on('closed', () => {
removeDarkOverlay();
Expand All @@ -475,12 +477,13 @@ function showSettingsWindow() {
}

let debugLogWindow;
function showDebugLogWindow() {
async function showDebugLogWindow() {
if (debugLogWindow) {
debugLogWindow.show();
return;
}

const theme = await pify(getDataFromMainWindow)('theme-setting');
const size = mainWindow.getSize();
const options = {
width: Math.max(size[0] - 100, MIN_WIDTH),
Expand All @@ -505,7 +508,7 @@ function showDebugLogWindow() {

captureClicks(debugLogWindow);

debugLogWindow.loadURL(prepareURL([__dirname, 'debug_log.html']));
debugLogWindow.loadURL(prepareURL([__dirname, 'debug_log.html'], { theme }));

debugLogWindow.on('closed', () => {
removeDarkOverlay();
Expand All @@ -519,7 +522,7 @@ function showDebugLogWindow() {
}

let permissionsPopupWindow;
function showPermissionsPopupWindow() {
async function showPermissionsPopupWindow() {
if (permissionsPopupWindow) {
permissionsPopupWindow.show();
return;
Expand All @@ -528,6 +531,7 @@ function showPermissionsPopupWindow() {
return;
}

const theme = await pify(getDataFromMainWindow)('theme-setting');
const size = mainWindow.getSize();
const options = {
width: Math.min(400, size[0]),
Expand All @@ -553,7 +557,7 @@ function showPermissionsPopupWindow() {
captureClicks(permissionsPopupWindow);

permissionsPopupWindow.loadURL(
prepareURL([__dirname, 'permissions_popup.html'])
prepareURL([__dirname, 'permissions_popup.html'], { theme })
);

permissionsPopupWindow.on('closed', () => {
Expand Down Expand Up @@ -832,13 +836,19 @@ ipc.on('delete-all-data', () => {
}
});

function getDataFromMainWindow(name, callback) {
ipc.once(`get-success-${name}`, (_event, error, value) =>
callback(error, value)
);
mainWindow.webContents.send(`get-${name}`);
}

function installSettingsGetter(name) {
ipc.on(`get-${name}`, event => {
if (mainWindow && mainWindow.webContents) {
ipc.once(`get-success-${name}`, (_event, error, value) =>
getDataFromMainWindow(name, (error, value) =>
event.sender.send(`get-success-${name}`, error, value)
);
mainWindow.webContents.send(`get-${name}`);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions permissions_popup_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = url.parse(window.location.toString(), true).query;
const { locale } = config;
const localeMessages = ipcRenderer.sendSync('locale-data');

window.theme = config.theme;
window.i18n = i18n.setup(locale, localeMessages);

require('./js/logging');
Expand Down
4 changes: 0 additions & 4 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ window.closeAbout = () => ipc.send('close-about');
window.updateTrayIcon = unreadCount =>
ipc.send('update-tray-icon', unreadCount);

ipc.on('debug-log', () => {
Whisper.events.trigger('showDebugLog');
});

ipc.on('set-up-with-import', () => {
Whisper.events.trigger('setupWithImport');
});
Expand Down
1 change: 1 addition & 0 deletions settings_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = url.parse(window.location.toString(), true).query;
const { locale } = config;
const localeMessages = ipcRenderer.sendSync('locale-data');

window.theme = config.theme;
window.i18n = i18n.setup(locale, localeMessages);

require('./js/logging');
Expand Down
4 changes: 4 additions & 0 deletions stylesheets/android-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ $button-dark: #ccc;
$text-dark: #cccccc;
$text-dark_l2: darken($text-dark, 30%);

body.android-dark {
background-color: $grey-dark;
}

.android-dark {
.app-loading-screen {
background-color: $grey-dark;
Expand Down

0 comments on commit d8e5e5f

Please sign in to comment.