Skip to content

Commit

Permalink
refactor: Moved backup listener in own file
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed May 22, 2021
1 parent 535bc3e commit 2e80729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 9 additions & 1 deletion app/backup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import * as Path from 'path';
import { app, IpcMainEvent } from 'electron';
import { app, IpcMainEvent, ipcMain } from 'electron';
import * as BackupIPC from './constants/BackupIPC';

export default class Backup {
Expand All @@ -22,6 +22,14 @@ export default class Backup {
if (!fs.existsSync(Backup.backupDir)) {
fs.mkdirSync(Backup.backupDir);
}

ipcMain.on(BackupIPC.BACKUP_START, (event, p) => {
this.startBackup(event, p);
});

ipcMain.on(BackupIPC.BACKUP_STOP, () => {
this.stopBackup();
});
}

public startBackup(event: IpcMainEvent, filePath: string) {
Expand Down
11 changes: 1 addition & 10 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import path from 'path';
import { app, BrowserWindow, ipcMain } from 'electron';
import MenuBuilder from './menu';
import * as IPCConstants from './constants/ipc';
import * as BackupIPC from './constants/BackupIPC';
import AppUpdater from './updater';
import Backup from './backup';
import Exporter from './exporter';
import Importer from './importer';
import AutoCorrection from './autocorrection';

let mainWindow: BrowserWindow | null = null;
let backup: Backup | null = null;
let file = '';

if (process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -102,7 +100,7 @@ const createWindow = async () => {
menuBuilder.buildMenu();

new AppUpdater();
backup = new Backup();
new Backup();
new Importer(mainWindow);
new Exporter();
new AutoCorrection();
Expand All @@ -124,13 +122,6 @@ const openWithFileHandler = (argv: string[]) => {
* Add event listeners...
*/

ipcMain.on(BackupIPC.BACKUP_START, (event, p) => {
if (backup != null) backup.startBackup(event, p);
});
ipcMain.on(BackupIPC.BACKUP_STOP, () => {
if (backup != null) backup.stopBackup();
});

ipcMain.on(IPCConstants.REQUEST_FILE_PATH, () => {
if (process.platform === 'win32') {
openWithFileHandler(process.argv);
Expand Down

0 comments on commit 2e80729

Please sign in to comment.