From 7fb212f7fca8741d0a7ebe227ddf395c5bb6c96c Mon Sep 17 00:00:00 2001 From: Taegus Date: Thu, 3 Jan 2019 15:38:11 +0100 Subject: [PATCH] + create user data dir ! fixed keystore path for MacOS + check file types on import accounts and notify of success or error --- modules/accounts.js | 59 ++++++++++++++++++++++++++++++++++++++++----- modules/geth.js | 4 +++ package.json | 2 +- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/modules/accounts.js b/modules/accounts.js index 0671cca..3367efe 100644 --- a/modules/accounts.js +++ b/modules/accounts.js @@ -2,18 +2,28 @@ const {app, dialog, ipcMain} = require('electron'); const admZip = require('adm-zip'); const path = require('path'); const fs = require('fs'); +const os = require('os'); class Accounts { constructor() { + this.getKeyStoreLocation = function() { + switch(os.type()) { + case "Darwin": + return path.join(process.env.HOMEPATH, 'Documents/ethereum-wallet/ethereum-wallet/Classes/Business layer/Core/Services', 'keystore'); + break; + default: + return path.join(process.env.APPDATA, 'Ether1', 'keystore'); + } + } } - + exportAccounts() { var savePath = dialog.showSaveDialog({ defaultPath: path.join(app.getPath('documents'), 'accounts.zip') }); if (savePath) { - const accPath = path.join(path.join(process.env.APPDATA, 'Ether1'), 'keystore'); + const accPath = this.getKeyStoreLocation(); fs.readdir(accPath, function(err, files) { var zip = new admZip(); @@ -29,15 +39,52 @@ class Accounts { } importAccounts() { - const accPath = path.join(path.join(process.env.APPDATA, 'Ether1'), 'keystore'); + const accPath = this.getKeyStoreLocation(); var openPath = dialog.showOpenDialog({ - defaultPath: app.getPath('documents') + defaultPath: app.getPath('documents'), + "filters": + [ + { + "name": "archive", + "extensions": ["zip"] + }, + { + "name": "json", + "extensions": ["json"] + } + ] }); if (openPath) { - var zip = new admZip(openPath[0]); - zip.extractAllTo(accPath, true); + var extName = path.extname(openPath[0]).toUpperCase(); + + if (extName = '.ZIP') { + var zip = new admZip(openPath[0]); + zip.extractAllTo(accPath, true); + + iziToast.success({ + title: 'Imported', + message: 'Accounts ware successfully imported.', + position: 'topRight', + timeout: 2000 + }); + } else if (extName = '.JSON') { + fs.copyFile(openPath[0], path.join(accPath, path.basename(openPath[0])), (err) => { + if (err) { + EthoMainGUI.showGeneralError(err); + } else { + iziToast.success({ + title: 'Imported', + message: 'Account was successfully imported.', + position: 'topRight', + timeout: 2000 + }); + } + }); + } else { + EthoMainGUI.showGeneralError("This is not a valid account file or arhive!"); + } } } } diff --git a/modules/geth.js b/modules/geth.js index 20b3958..fd1bfff 100644 --- a/modules/geth.js +++ b/modules/geth.js @@ -9,6 +9,10 @@ const os = require('os'); class Geth { constructor() { this.gethProcess = null; + // create the user data dir (needed for MacOS) + if (!fs.existsSync(app.getPath('userData'))) { + fs.mkdirSync(app.getPath('userData')); + } this.logStream = fs.createWriteStream(path.join(app.getPath('userData'), 'gethlog.txt')); if (appRoot.path.indexOf('app.asar') > -1) { diff --git a/package.json b/package.json index 3abeb34..7b97010 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Ether1Wallet", - "version": "0.2.2", + "version": "0.2.3", "description": "Desktop wallet for Ether1 currency", "main": "main.js", "scripts": {