+ beautifier

* version info
This commit is contained in:
Taegus
2019-03-03 10:37:19 +01:00
parent de73afd5cd
commit b0cd7d517a
19 changed files with 1648 additions and 1697 deletions

View File

@@ -1,103 +1,99 @@
const {app, dialog, ipcMain} = require('electron');
const admZip = require('adm-zip');
const path = require('path');
const fs = require('fs-extra');
const os = require('os');
const {app, dialog, ipcMain} = require("electron");
const admZip = require("adm-zip");
const path = require("path");
const fs = require("fs-extra");
const os = require("os");
class Accounts {
constructor() {
}
constructor() {}
getKeyStoreLocation() {
switch(os.type()) {
case "Darwin":
return path.join(os.homedir(), 'Library', 'Ether1', 'keystore');
break;
default:
return path.join(process.env.APPDATA, 'Ether1', 'keystore');
}
switch (os.type()) {
case "Darwin":
return path.join(os.homedir(), "Library", "Ether1", "keystore");
break;
default:
return path.join(process.env.APPDATA, "Ether1", "keystore");
}
}
exportAccounts() {
var savePath = dialog.showSaveDialog({
defaultPath: path.join(app.getPath('documents'), 'accounts.zip')
defaultPath: path.join(app.getPath("documents"), "accounts.zip")
});
if (savePath) {
const accPath = EthoAccounts.getKeyStoreLocation();
fs.readdir(accPath, function(err, files) {
var zip = new admZip();
const accPath = EthoAccounts.getKeyStoreLocation();
for(let filePath of files) {
zip.addFile(filePath, fs.readFileSync(path.join(accPath, filePath)));
}
fs.readdir(accPath, function (err, files) {
var zip = new admZip();
// store zip to path
zip.writeZip(savePath);
});
for (let filePath of files) {
zip.addFile(filePath, fs.readFileSync(path.join(accPath, filePath)));
}
// store zip to path
zip.writeZip(savePath);
});
}
}
importAccounts(accountsFile) {
importAccounts(accountsFile) {
var extName = path.extname(accountsFile).toUpperCase();
const accPath = EthoAccounts.getKeyStoreLocation();
if (extName == '.ZIP') {
var zip = new admZip(accountsFile);
zip.extractAllTo(accPath, true);
return { success: true, text: "Accounts ware successfully imported."};
if (extName == ".ZIP") {
var zip = new admZip(accountsFile);
zip.extractAllTo(accPath, true);
return {success: true, text: "Accounts ware successfully imported."};
} else {
try {
fs.copySync(accountsFile, path.join(accPath, path.basename(accountsFile)));
return { success: true, text: "Account was successfully imported."};
} catch (err) {
return { success: false, text: err};
}
try {
fs.copySync(accountsFile, path.join(accPath, path.basename(accountsFile)));
return {success: true, text: "Account was successfully imported."};
} catch (err) {
return {success: false, text: err};
}
}
}
saveAccount(account) {
fs.writeFile(path.join(tEthoAccountshis.getKeyStoreLocation(), '0x' + account.address), JSON.stringify(account), 'utf8', function() {
// file was written
saveAccount(account) {
fs.writeFile(path.join(tEthoAccountshis.getKeyStoreLocation(), "0x" + account.address), JSON.stringify(account), "utf8", function () {
// file was written
});
}
}
ipcMain.on('exportAccounts', (event, arg) => {
EthoAccounts.exportAccounts();
});
ipcMain.on('importAccounts', (event, arg) => {
var openPath = dialog.showOpenDialog({
defaultPath: app.getPath('documents'),
"filters":
[
{
"name": "archive",
"extensions": ["zip"]
},
{
"name": "json",
"extensions": ["json"]
},
{
"name": "All",
"extensions": ["*.*"]
}
]
});
if (openPath) {
event.returnValue = EthoAccounts.importAccounts(openPath[0]);
} else {
event.returnValue = {};
}
ipcMain.on("exportAccounts", (event, arg) => {
EthoAccounts.exportAccounts();
});
ipcMain.on('saveAccount', (event, arg) => {
EthoAccounts.saveAccount(arg);
event.returnValue = true;
ipcMain.on("importAccounts", (event, arg) => {
var openPath = dialog.showOpenDialog({
defaultPath: app.getPath("documents"),
filters: [
{
name: "archive",
extensions: ["zip"]
}, {
name: "json",
extensions: ["json"]
}, {
name: "All",
extensions: ["*.*"]
}
]
});
if (openPath) {
event.returnValue = EthoAccounts.importAccounts(openPath[0]);
} else {
event.returnValue = {};
}
});
ipcMain.on("saveAccount", (event, arg) => {
EthoAccounts.saveAccount(arg);
event.returnValue = true;
});
EthoAccounts = new Accounts();