Skip to content

Commit

Permalink
Add case about save widget setting.
Browse files Browse the repository at this point in the history
- save setting every 5 minutes.
- save setting when add new widget.
  • Loading branch information
HyunmoAhn committed Dec 2, 2018
1 parent f9f410d commit 6daf1d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/main/controllers/__tests__/widget.spec.js
Expand Up @@ -4,8 +4,11 @@ import * as TYPES from 'actions/constant/actionTypes';
import storeMock from 'store/storeMain';
import { openBrowserWindow } from 'actions/window';
import * as utils from 'main/utils/widget/makeWidget';
import saveData from 'main/utils/disk/saveData';
import widgetController from '../widget';

jest.mock('main/utils/disk/saveData');

describe('test widgetController', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -41,6 +44,7 @@ describe('test widgetController', () => {
mockBrowserWindow,
),
);
expect(saveData).toHaveBeenCalledTimes(1);
});

describe('should handle TYPES.WIDGET_OPEN', () => {
Expand Down
4 changes: 2 additions & 2 deletions app/main/controllers/widget.js
Expand Up @@ -13,6 +13,7 @@ import { isUrlCheckFetchSelector } from 'store/reducers/share/status/selectors';
import { modalOpen } from 'actions/modal';
import * as sharedId from 'store/reducers/share/identification/selectors';
import * as identificationSelector from 'store/reducers/personal/identification/selectors';
import saveData from 'main/utils/disk/saveData';

const widgetController = (action, prev) => {
const { type } = action;
Expand All @@ -22,6 +23,7 @@ const widgetController = (action, prev) => {
const widgetWin = makeWidget(id, undefined, true);

store.dispatch(openBrowserWindow(id, widgetWin));
saveData();
break;
}
case TYPES.WIDGET_OPEN: {
Expand All @@ -39,7 +41,6 @@ const widgetController = (action, prev) => {

store.dispatch(openBrowserWindow(id, widgetWin));
}

break;
}
case TYPES.WIDGET_CLOSE:
Expand All @@ -51,7 +52,6 @@ const widgetController = (action, prev) => {
if (widget) {
widget.close();
}

break;
}
case TYPES.WIDGET_UPDATE_INFO: {
Expand Down
5 changes: 5 additions & 0 deletions app/main/utils/init.js
Expand Up @@ -11,16 +11,21 @@ import openAllWidgetStatusOpen from 'main/utils/window/openAllWidgetStatusOpen';
import store from 'store/storeMain';
import subscribeActionMain from 'store/utils/subscribeActionMain';
import { hotKeySearchWindowSelector } from 'store/reducers/share/config/selectors';
import saveData from 'main/utils/disk/saveData';
import TrayMenuBar from 'main/utils/menu/trayMenuBar';
import { setInitialStore } from 'actions/setting';

// save data about setting every 5 minutes.
const SAVE_SETTING_INTERVAL = 300000;

function init() {
autoLaunch();
subscribeActionMain(store);
createMenu();
handlingSearchHotKey(hotKeySearchWindowSelector(store.getState()));
openAllWidgetStatusOpen();
autoUpdater.checkForUpdatesAndNotify();
setInterval(saveData, SAVE_SETTING_INTERVAL);

app.on('activate', (e, isOpenWindow) => {
if (!isOpenWindow) {
Expand Down

0 comments on commit 6daf1d9

Please sign in to comment.