Skip to content

Commit

Permalink
Merge branch 'desktop' into mainnet-desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed May 14, 2019
2 parents 7350310 + 18fcb96 commit 90b3ce8
Show file tree
Hide file tree
Showing 6 changed files with 13,165 additions and 116 deletions.
4 changes: 2 additions & 2 deletions desktop/electron-builder-x86.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const config = require('./electron-builder.config');

config.nsis.artifactName = config.nsis.artifactName.replace('${arch}', 'x86');
config.win.artifactName = config.win.artifactName.replace('${arch}', 'x86');
config.nsis.artifactName = config.nsis.artifactName.replace('x64', 'x86');
config.win.artifactName = config.win.artifactName.replace('x64', 'x86');

module.exports = config;
48 changes: 19 additions & 29 deletions desktop/electron-builder.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const appName = 'minter-console';

module.exports = {
"productName": "Minter Console",
"appId": "com.minter.console",
Expand All @@ -12,7 +14,15 @@ module.exports = {
// "nuxt.config.js",
".nuxt/**/*",
],
"publish": ["github"],
// mac (zip)
"mac": {
"artifactName": `${appName}-\${version}-\${arch}-mac.\${ext}`,
"icon": "desktop/icons/icon.icns",
},
// mac dmg
"dmg": {
"artifactName": `${appName}-\${version}-\${arch}.\${ext}`,
"contents": [
{
"x": 410,
Expand All @@ -27,40 +37,20 @@ module.exports = {
},
],
},
"mac": {
"icon": "desktop/icons/icon.icns",
},
"nsis": {
"artifactName": "${productName} ${version} Setup ${arch}.${ext}",
},
// win (portable)
"win": {
"artifactName": "${productName} ${version} ${arch}.${ext}",
"artifactName": `${appName}-\${version}-portable-x64.\${ext}`,
"icon": "desktop/icons/icon.ico",
"target": ["portable", "nsis"],
// "target": [
// {
// "artifactName": "${productName} ${version} ${arch}.${ext}",
// "target": "portable",
// "arch": "x64",
// },
// {
// "artifactName": "${productName} ${version} ${arch} x86.${ext}",
// "target": "portable",
// "arch": "ia32"
// },
// {
// "artifactName": "${productName} Setup ${version} ${arch}.${ext}",
// "target": "nsis",
// "arch": "x64",
// },
// {
// "artifactName": "${productName} Setup ${version} ${arch} x86.${ext}",
// "target": "nsis",
// "arch": "ia32"
// },
// ]
},
// win setup
"nsis": {
"artifactName": `${appName}-\${version}-setup-x64.\${ext}`,
},
// linux
"linux": {
"artifactName": `${appName}-\${version}-\${arch}.\${ext}`,
"icon": "desktop/icons",
"category": "Office",
},
};
95 changes: 77 additions & 18 deletions desktop/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const _NUXT_URL_ = `http://${HOST_NAME}:${PORT}/`;
** Electron
*/

const { app, BrowserWindow } = require('electron'); // eslint-disable-line
const fs = require('fs');
const { app, BrowserWindow, Menu } = require('electron'); // eslint-disable-line

/**
* Set `__static` path to static files in production
Expand All @@ -53,6 +54,29 @@ const { app, BrowserWindow } = require('electron'); // eslint-disable-line

let mainWindow;

app.on('ready', async () => {
try {
await initNuxt();
} catch (e) {
console.log(e);
}
// setTimeout(createWindow, 3000)
createWindow();
createMenu();
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});

function createWindow() {
/**
* Initial window options
Expand All @@ -72,32 +96,67 @@ function createWindow() {
mainWindow.webContents.openDevTools();
}

// clear leveldb log if localStorage is empty
mainWindow.on('close', async () => {
let vuex = await mainWindow.webContents.executeJavaScript(`window.localStorage.getItem('vuex')`);
vuex = vuex && JSON.parse(vuex);
if (!vuex.auth.advanced && !vuex.auth.password) {
const dbPath = path.join(app.getPath('userData'), 'Local Storage/leveldb');
const logs = findInDir(dbPath, '.log');
logs.forEach((filePath) => {
fs.unlinkSync(filePath);
});
}
});

mainWindow.on('closed', () => {
mainWindow = null;
});
}

app.on('ready', async () => {
try {
await initNuxt();
} catch (e) {
console.log(e);
}
// setTimeout(createWindow, 3000)
createWindow();
});
function createMenu() {
const template = [{
label: "Minter Console",
submenu: [
{ label: "About", selector: "orderFrontStandardAboutPanel:" },
{ type: "separator" },
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }},
]}, {
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ type: "separator" },
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" },
]},
];

Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
function findInDir(startPath, filter) {
let result = [];

if (!fs.existsSync(startPath)) {
return result;
}
});

app.on('activate', () => {
if (mainWindow === null) {
createWindow();
const files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
const filename = path.join(startPath, files[i]);
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
result = result.concat(findInDir(filename, filter)); //recurse
} else if (filename.indexOf(filter) >= 0) {
result.push(filename);
}
}
});

return result;
}

/**
* Auto Updater
Expand Down
Loading

0 comments on commit 90b3ce8

Please sign in to comment.