From 7964a36b69e18c7dab544dfaceeaff7425405fd7 Mon Sep 17 00:00:00 2001 From: Ivan Kadochnikov Date: Fri, 22 Nov 2019 17:42:24 +0300 Subject: [PATCH] Fix electron dialog api for backup/restore Use promises instead of callbacks --- app/ux/FileBackup.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/ux/FileBackup.js b/app/ux/FileBackup.js index 1066bf71..6d1083f6 100644 --- a/app/ux/FileBackup.js +++ b/app/ux/FileBackup.js @@ -23,13 +23,15 @@ Ext.define('Hamsket.ux.FileBackup', { const json_string = JSON.stringify(services, null, 4); me.remote.dialog.showSaveDialog({ defaultPath: me.myDefaultPath - }, function(filename, bookmark) { - if (!filename) return; - me.fs.writeFile(filename, json_string, function(err) { + }).then((result) => { + if (!result.filePath) return; + me.fs.writeFile(result.filePath, json_string, function(err) { if (err) { console.log(err); } }); + }).catch((err) => { + console.log(err); }); if (Ext.isFunction(callback)) callback.bind(me)(); }, @@ -38,9 +40,9 @@ Ext.define('Hamsket.ux.FileBackup', { me.remote.dialog.showOpenDialog({ defaultPath: me.myDefaultPath, properties: ['openFile'] - }, function(filePaths, bookmarks) { - if (filePaths && filePaths.length === 1) { - const filePath = filePaths[0]; + }).then((result) => { + if (result.filePaths && result.filePaths.length === 1) { + const filePath = result.filePaths[0]; me.fs.readFile(filePath, function (err, data) { if (err) { console.log(err); @@ -59,6 +61,8 @@ Ext.define('Hamsket.ux.FileBackup', { } }); } + }).catch((err) => { + console.log(err); }); } });