Skip to content

Commit

Permalink
Merge pull request #355 from buttercup/fix-windows-data-loss
Browse files Browse the repository at this point in the history
Update the way state is saved, fix menubar autohide
  • Loading branch information
sallar authored Oct 17, 2017
2 parents 2a907a6 + efd33af commit d7fc018
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "buttercup",
"version": "0.21.2",
"version": "0.21.3",
"productName": "Buttercup",
"main": "./dist/app.js",
"description": "Free and Open Source password vault",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "buttercup",
"productName": "Buttercup",
"version": "0.21.2",
"version": "0.21.3",
"description": "Free and Open Source password vault",
"main": "app/dist/app.js",
"scripts": {
Expand Down Expand Up @@ -148,7 +148,7 @@
"electron-debug": "^1.1.0",
"electron-devtools-installer": "^2.2.0",
"electron-installer-dmg": "^0.1.2",
"electron-json-storage": "^3.0.6",
"electron-json-storage": "^3.2.0",
"electron-log": "^2.2.6",
"electron-rpc": "^2.0.1",
"electron-store": "^1.2.0",
Expand Down
18 changes: 10 additions & 8 deletions src/main/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { app, ipcMain as ipc } from 'electron';
import pify from 'pify';
import log from 'electron-log';
import { throttle } from 'lodash';
import debounce from 'lodash/debounce';
import jsonStorage from 'electron-json-storage';
import configureStore from '../shared/store/configure-store';
import { setupMenu } from './menu';
Expand All @@ -23,7 +23,7 @@ const windowManager = getWindowManager();

let appIsReady = false;
let initialFile = null;
let isSaving = false;
let isSavingWorkspace = false;

// Crash reporter for alpha and beta releases
// After we come out of beta, we should be rolling our own
Expand Down Expand Up @@ -101,8 +101,10 @@ app.on('ready', async () => {

// Persist Store to Disk
store.subscribe(
throttle(() => {
storage.set('state', store.getState());
debounce(async () => {
log.info('Start Saving state');
await storage.set('state', store.getState());
log.info('Finish Saving state');
}, 100)
);

Expand Down Expand Up @@ -142,21 +144,21 @@ app.on('activate', () => {
// Prevent quitting if a file is being saved
// to prevent data loss
ipc.on('workspace-save-started', () => {
isSaving = true;
isSavingWorkspace = true;
});

ipc.on('workspace-save-finished', () => {
isSaving = false;
isSavingWorkspace = false;
});

app.on('before-quit', e => {
const mainWindow = getMainWindow();
mainWindow.webContents.send('will-quit');

if (isSaving === true) {
if (isSavingWorkspace === true) {
e.preventDefault();
ipc.once('workspace-save-finished', () => {
isSaving = false;
isSavingWorkspace = false;
app.quit();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function setupMenu(store) {
store.dispatch(setSetting('condencedSidebar', condenced));
}
},
...(isOSX()
...(!isOSX()
? [
{
label: 'Auto-hide Menubar',
Expand Down

0 comments on commit d7fc018

Please sign in to comment.