diff --git a/app/ux/FileBackup.js b/app/ux/FileBackup.js index a57caecb..193978bb 100644 --- a/app/ux/FileBackup.js +++ b/app/ux/FileBackup.js @@ -1,14 +1,13 @@ -const remote = require('electron').remote; -const dialog = remote.dialog; -const app = remote.app; -const fs = require('fs'); -const path = require('path'); -const userPath = app.getPath('userData'); -const defaultFileName = 'rambox-backup.json'; -const myDefaultPath = userPath + path.sep + defaultFileName; - Ext.define('Rambox.ux.FileBackup', { singleton: true, + initComponent: () => { + this.remote = require('electron').remote; + this.path = this.remote.require('path'); + this.fs = this.remote.require('fs'); + this.userPath = this.remote.app.getPath('userData'); + this.defaultFileName = 'rambox-backup.json'; + this.myDefaultPath = this.userPath + this.path.sep + this.defaultFileName; + }, backupConfiguration: function (callback) { var me = this; let services = []; @@ -20,11 +19,11 @@ Ext.define('Rambox.ux.FileBackup', { }); const json_string = JSON.stringify(services, null, 4); - dialog.showSaveDialog({ - defaultPath: myDefaultPath + me.remote.dialog.showSaveDialog({ + defaultPath: me.myDefaultPath }, function(filename, bookmark) { if (!filename) return; - fs.writeFile(filename, json_string, function(err) { + me.fs.writeFile(filename, json_string, function(err) { if (err) { console.log(err); } @@ -34,13 +33,13 @@ Ext.define('Rambox.ux.FileBackup', { }, restoreConfiguration: function () { var me = this; - dialog.showOpenDialog({ - defaultPath: myDefaultPath, + me.remote.dialog.showOpenDialog({ + defaultPath: me.myDefaultPath, properties: ['openFile'] }, function(filePaths, bookmarks) { if (filePaths && filePaths.length === 1) { const filePath = filePaths[0]; - fs.readFile(filePath, function (err, data) { + me.fs.readFile(filePath, function (err, data) { if (err) { console.log(err); } @@ -52,7 +51,7 @@ Ext.define('Rambox.ux.FileBackup', { service.save(); Ext.getStore('Services').add(service); }); - remote.getCurrentWindow().reload(); + me.remote.getCurrentWindow().reload(); }); }