+ create user data dir

! fixed keystore path for MacOS
+ check file types on import accounts and notify of success or error
This commit is contained in:
Taegus
2019-01-03 15:38:11 +01:00
parent 5090754127
commit 7fb212f7fc
3 changed files with 58 additions and 7 deletions

View File

@@ -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!");
}
}
}
}

View File

@@ -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) {

View File

@@ -1,6 +1,6 @@
{
"name": "Ether1Wallet",
"version": "0.2.2",
"version": "0.2.3",
"description": "Desktop wallet for Ether1 currency",
"main": "main.js",
"scripts": {