Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Project Dependencies #361

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __mocks__/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = {
require: jest.fn(name => {
if (name === 'electron-settings') {
return {
set: jest.fn(),
get: jest.fn(() => 'someSettings'),
setSync: jest.fn(),
getSync: jest.fn(() => 'someSettings'),
};
}
}),
Expand Down
107 changes: 69 additions & 38 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ function createTourWindow() {
movable: false,
title: 'Tour Window',
backgroundColor: '#F9FAFA',
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
},
});
// Register WindowID with appConfig
appConfig.set('tourWindowID', parseInt(tourWindow.id));
appConfig.setSync('tourWindowID', parseInt(tourWindow.id));
// Load Content
tourWindow.loadURL(
url.format({
Expand All @@ -61,10 +65,11 @@ function createTourWindow() {
})
);
// Add Event Listeners
tourWindow.on('show', event => {
if (isDev || forceDevtools) tourWindow.webContents.openDevTools({ mode: 'detach' });
tourWindow.on('show', (event) => {
if (isDev || forceDevtools)
tourWindow.webContents.openDevTools({ mode: 'detach' });
});
tourWindow.on('close', event => {
tourWindow.on('close', (event) => {
event.preventDefault();
if (isDev || forceDevtools) tourWindow.webContents.closeDevTools();
tourWindow.hide();
Expand All @@ -85,9 +90,13 @@ function createMainWindow() {
backgroundColor: '#2e2c29',
show: false,
title: 'Main Window',
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
},
});
// Register WindowID
appConfig.set('mainWindowID', parseInt(mainWindow.id));
appConfig.setSync('mainWindowID', parseInt(mainWindow.id));
// Track window state
mainWindownStateKeeper.track(mainWindow);
// Load Content
Expand All @@ -99,10 +108,11 @@ function createMainWindow() {
})
);
// Add Event Listeners
mainWindow.on('show', event => {
if (isDev || forceDevtools) mainWindow.webContents.openDevTools({ mode: 'detach' });
mainWindow.on('show', (event) => {
if (isDev || forceDevtools)
mainWindow.webContents.openDevTools({ mode: 'detach' });
});
mainWindow.on('close', event => {
mainWindow.on('close', (event) => {
if (process.platform === 'darwin') {
event.preventDefault();
if (isDev || forceDevtools) mainWindow.webContents.closeDevTools();
Expand All @@ -127,9 +137,13 @@ function createPreviewWindow() {
backgroundColor: '#2e2c29',
show: false,
title: 'Preview Window',
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
},
});
// Register WindowID
appConfig.set('previewWindowID', parseInt(previewWindow.id));
appConfig.setSync('previewWindowID', parseInt(previewWindow.id));
// Track window state
previewWindownStateKeeper.track(previewWindow);
// Load Content
Expand All @@ -141,10 +155,11 @@ function createPreviewWindow() {
})
);
// Add Event Listener
previewWindow.on('show', event => {
if (isDev || forceDevtools) previewWindow.webContents.openDevTools({ mode: 'detach' });
previewWindow.on('show', (event) => {
if (isDev || forceDevtools)
previewWindow.webContents.openDevTools({ mode: 'detach' });
});
previewWindow.on('close', event => {
previewWindow.on('close', (event) => {
event.preventDefault();
if (isDev || forceDevtools) previewWindow.webContents.closeDevTools();
previewWindow.hide();
Expand Down Expand Up @@ -224,14 +239,16 @@ function setInitialValues() {
for (const key in defaultOptions) {
// Add level 1 key if not exist
if (Object.prototype.hasOwnProperty.call(defaultOptions, key)) {
if (!appConfig.has(`${key}`)) {
appConfig.set(`${key}`, defaultOptions[key]);
if (!appConfig.hasSync(`${key}`)) {
appConfig.setSync(`${key}`, defaultOptions[key]);
}
// Add level 2 key if not exist
for (const childKey in defaultOptions[key]) {
if (Object.prototype.hasOwnProperty.call(defaultOptions[key], childKey)) {
if (!appConfig.has(`${key}.${childKey}`)) {
appConfig.set(`${key}.${childKey}`, defaultOptions[key][childKey]);
if (
Object.prototype.hasOwnProperty.call(defaultOptions[key], childKey)
) {
if (!appConfig.hasSync(`${key}.${childKey}`)) {
appConfig.setSync(`${key}.${childKey}`, defaultOptions[key][childKey]);
}
}
}
Expand All @@ -242,7 +259,7 @@ function setInitialValues() {
function migrateData() {
// Migration scheme
const migrations = {
1: configs => {
1: (configs) => {
// Get the current configs
const { info, appSettings } = configs;
// Return current configs if this is the first time install
Expand Down Expand Up @@ -285,9 +302,13 @@ function migrateData() {
]);
},

2: configs => {
2: (configs) => {
// Return current configs if this is the first time install
if ( configs.invoice.currency.placement !== undefined) {
if (
configs.invoice &&
configs.invoice.currency &&
configs.invoice.currency.placement !== undefined
) {
return configs;
}
// Update current configs
Expand All @@ -298,30 +319,33 @@ function migrateData() {
placement: 'before',
separator: 'commaDot',
fraction: 2,
}
})
},
}),
});
},

3: configs => {
3: (configs) => {
// Return current configs if checkUpdate and lastCheck do not exist
const { checkUpdate, lastCheck} = configs.general;
if ( checkUpdate === undefined || lastCheck === undefined ) {
if (
!configs.general ||
configs.general.checkUpdate === undefined ||
configs.general.lastCheck === undefined
) {
return configs;
}
// Remove checkUpdate and lastCheck
return Object.assign({}, configs, {
general: omit(configs.general, ['checkUpdate', 'lastCheck'])
general: omit(configs.general, ['checkUpdate', 'lastCheck']),
});
},
};
// Get the current Config
const configs = appConfig.getAll();
const configs = appConfig.getSync();
// Get the current configs
const version = appConfig.get('version') || 0;
const version = appConfig.getSync('version') || 0;
// Handle migration
const newMigrations = Object.keys(migrations)
.filter(k => k > version)
.filter((k) => k > version)
.sort();
// Exit if there's no migration to run
if (!newMigrations.length) return;
Expand All @@ -332,9 +356,10 @@ function migrateData() {
configs
);
// Save the final config to DB
appConfig.deleteAll().setAll(migratedConfigs);
appConfig.reset();
appConfig.setSync(migratedConfigs);
// Update the latest config version
appConfig.set('version', newMigrations[newMigrations.length - 1]);
appConfig.setSync('version', newMigrations[newMigrations.length - 1]);
}

function addEventListeners() {
Expand All @@ -346,29 +371,35 @@ function addEventListeners() {
ipcMain.on('quit-and-install', () => {
setImmediate(() => {
// Remove this listener
app.removeAllListeners("window-all-closed");
app.removeAllListeners('window-all-closed');
// Force close all windows
tourWindow.destroy();
mainWindow.destroy();
previewWindow.destroy();
// Start the quit and update sequence
autoUpdater.quitAndInstall(false);
})
});
});
}

function loadMainProcessFiles() {
const files = glob.sync(path.join(__dirname, 'main/*.js'));
files.forEach(file => require(file));
files.forEach((file) => {
try {
require(file);
} catch (e) {
console.log(e);
}
});
}

function windowStateKeeper(windowName) {
let window, windowState;

function setBounds() {
// Restore from appConfig
if (appConfig.has(`windowState.${windowName}`)) {
windowState = appConfig.get(`windowState.${windowName}`);
if (appConfig.hasSync(`windowState.${windowName}`)) {
windowState = appConfig.getSync(`windowState.${windowName}`);
return;
}
// Default
Expand All @@ -385,12 +416,12 @@ function windowStateKeeper(windowName) {
windowState = window.getBounds();
}
windowState.isMaximized = window.isMaximized();
appConfig.set(`windowState.${windowName}`, windowState);
appConfig.setSync(`windowState.${windowName}`, windowState);
}

function track(win) {
window = win;
['resize', 'move'].forEach(event => {
['resize', 'move'].forEach((event) => {
win.on(event, saveState);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports[`Renders correctly to the DOM matches snapshot 1`] = `
Pending
</label>
<p>
01/01/70
12/31/69
</p>
</div>
<div
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getInvoiceData(formData) {
if (required_fields.currency) {
invoiceData.currency = currency;
} else {
invoiceData.currency = appConfig.get('invoice.currency');
invoiceData.currency = appConfig.getSync('invoice.currency');
}
// Set Discount
if (required_fields.discount) invoiceData.discount = discount;
Expand Down
4 changes: 2 additions & 2 deletions app/middlewares/FormMW.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const FormMW = ({ dispatch, getState }) => next => action => {
case ACTION_TYPES.SAVED_FORM_SETTING_UPDATE: {
// Save setting to DB
const { setting, data } = action.payload;
appConfig.set(`invoice.${setting}`, data);
appConfig.setSync(`invoice.${setting}`, data);
// Dispatch notification
dispatch({
type: ACTION_TYPES.UI_NOTIFICATION_NEW,
Expand All @@ -76,7 +76,7 @@ const FormMW = ({ dispatch, getState }) => next => action => {
// Pass new data to action and continue
next({
type: ACTION_TYPES.SAVED_FORM_SETTING_UPDATE,
payload: appConfig.get('invoice'),
payload: appConfig.getSync('invoice'),
});
// Reload app settings so that
// Settings tab will have up-to-date information
Expand Down
16 changes: 8 additions & 8 deletions app/middlewares/SettingsMW.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const SettingsMW = ({ dispatch }) => next => action => {
switch (action.type) {
case ACTION_TYPES.SETTINGS_GET_INITIAL: {
const savedSettings = {
profile: appConfig.get('profile'),
invoice: appConfig.get('invoice'),
general: appConfig.get('general'),
profile: appConfig.getSync('profile'),
invoice: appConfig.getSync('invoice'),
general: appConfig.getSync('general'),
};
return next(
Object.assign({}, action, {
Expand All @@ -33,13 +33,13 @@ const SettingsMW = ({ dispatch }) => next => action => {
if (!validateTax(true, action.payload.invoice.tax)) break;
if (!validateCurrency(true, action.payload.invoice.currency)) break;
// Change Preview Profile
const profile = appConfig.get('profile');
const profile = appConfig.getSync('profile');
const newProfile = action.payload.profile;
if (profile !== newProfile) {
ipc.send('change-preview-window-profile', newProfile);
}
// Change UI language
const { language } = appConfig.get('general');
const { language } = appConfig.getSync('general');
const newLang = action.payload.general.language;
if (language !== newLang) {
// Change the language
Expand All @@ -48,9 +48,9 @@ const SettingsMW = ({ dispatch }) => next => action => {
ipc.send('change-preview-window-language', newLang);
}
// Save Settings
appConfig.set('profile', action.payload.profile);
appConfig.set('invoice', action.payload.invoice);
appConfig.set('general', action.payload.general);
appConfig.setSync('profile', action.payload.profile);
appConfig.setSync('invoice', action.payload.invoice);
appConfig.setSync('general', action.payload.general);
// Reload Sounds Cache
sounds.preload();
// Continue
Expand Down
2 changes: 1 addition & 1 deletion app/reducers/FormReducer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleActions } from 'redux-actions';
import { createSelector } from 'reselect';
// Retrive settings
const appConfig = require('electron').remote.require('electron-settings');
const invoiceSettings = appConfig.get('invoice');
const invoiceSettings = appConfig.getSync('invoice');
// Helper
import { setEditRecipient } from '../helpers/form';

Expand Down
4 changes: 4 additions & 0 deletions app/renderers/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function showModalWindow(dialogOptions, returnChannel = '', ...rest) {
backgroundColor: '#282828',
frame: false,
show: false,
webPreferences: {
nodeIntegration:true,
enableRemoteModule: true,
},
});
modalWin.loadURL(
url.format({
Expand Down
2 changes: 1 addition & 1 deletion app/renderers/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ipc = require('electron').ipcRenderer;
const isDev = require('electron-is-dev');

// Get mainWindow Object
const mainWindowID = appConfig.get('mainWindowID');
const mainWindowID = appConfig.getSync('mainWindowID');
const mainWindow = BrowserWindow.fromId(mainWindowID);

const aboutMenu = {
Expand Down
Loading