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 Mar 6, 2020
2 parents 6e8581a + 1cb24e0 commit a33f57c
Show file tree
Hide file tree
Showing 15 changed files with 17,142 additions and 6,103 deletions.
1 change: 1 addition & 0 deletions assets/less/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
}



// table
@table-cell-padding: 10px;
@table-cell-vertical-padding-large: 14px;
Expand Down
14 changes: 14 additions & 0 deletions components/common/TestnetNotice.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
export default {
};
</script>

<template>
<div class="testnet-notice">
<div class="testnet-notice__container u-container u-container--large">
<span class="testnet-notice__icon">⚠️</span>
<span class="testnet-notice__caption">Attention! <span class="u-display-ib">This is a testnet version</span></span>
<span class="testnet-notice__icon">⚠️</span>
</div>
</div>
</template>
6 changes: 6 additions & 0 deletions desktop/electron-builder-x86.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require('./electron-builder.config');

config.nsis.artifactName = config.nsis.artifactName.replace('x64', 'x86');
config.win.artifactName = config.win.artifactName.replace('x64', 'x86');

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

module.exports = {
"productName": "Minter Console",
"appId": "com.minter.console",
"directories": {
"buildResources": "desktop",
"output": "tmp/electron",
},
"files": [
"dist/**/*",
"desktop/electron.js",
// "desktop/electron.dev.js",
// "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,
"y": 150,
"type": "link",
"path": "/Applications",
},
{
"x": 130,
"y": 150,
"type": "file",
},
],
},
// win (portable)
"win": {
"artifactName": `${appName}-\${version}-portable-x64.\${ext}`,
"icon": "desktop/icons/icon.ico",
"target": ["portable", "nsis"],
},
// win setup
"nsis": {
"artifactName": `${appName}-\${version}-setup-x64.\${ext}`,
},
// linux
"linux": {
"artifactName": `${appName}-\${version}-\${arch}.\${ext}`,
"icon": "desktop/icons",
"category": "Office",
},
};
24 changes: 24 additions & 0 deletions desktop/electron.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This file is used specifically and only for development. It installs
* `electron-debug` & `vue-devtools`. There shouldn't be any need to
* modify this file, but it can be used to extend your development
* environment.
*/

/* eslint-disable */

// Install `electron-debug` with `devtron`
require('electron-debug/index')({ showDevTools: true })

// Install `vue-devtools`
require('electron').app.on('ready', () => {
// let installExtension = require('electron-devtools-installer')
// installExtension.default(installExtension.VUEJS_DEVTOOLS)
// .then(() => {})
// .catch(err => {
// console.log('Unable to install `vue-devtools`: \n', err)
// })
})

// Require `main` process to boot app
require('./electron')
179 changes: 179 additions & 0 deletions desktop/electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
** Nuxt
*/
const path = require('path');
const argv = require('minimist')(process.argv.slice(2));

const HOST_NAME = argv.hostname || 'localhost';
const PORT = argv.port || 4000;



// const esm = require('esm');
const {Nuxt} = require('@nuxt/core');
async function initNuxt() {
let config = {}; //esm(module)('./nuxt.config.js')
if (config.default) {
config = config.default;
}
config.rootDir = path.resolve(__dirname, '..');
config.dev = false;
config.mode = 'spa';
config.dir = {
static: 'dist',
};
config.server = {
host: HOST_NAME,
port: PORT,
};
/** @type Nuxt */
let nuxt = new Nuxt(config);
await nuxt.ready();
await nuxt.server.listen();
}

const _NUXT_URL_ = `http://${HOST_NAME}:${PORT}/`;




/*
** Electron
*/

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

/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
// if (process.env.NODE_ENV !== 'development') {
// global.__static = require('path').join(__dirname, '/dist').replace(/\\/g, '\\\\') // 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
*/
mainWindow = new BrowserWindow({
width: 1260,
height: 700,
useContentSize: true,
webPreferences: {
nodeIntegration: false,
},
});

mainWindow.loadURL(_NUXT_URL_);

if (process.env.NODE_ENV === 'development' || process.env.DEBUG === 'electron-builder') {
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;
});
}

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));
}

function findInDir(startPath, filter) {
let result = [];

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

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
*
* Uncomment the following code below and install `electron-updater` to
* support auto updating. Code Signing with a valid certificate is required.
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
*/

/*
import { autoUpdater } from 'electron-updater'
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall()
})
app.on('ready', () => {
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
})
*/
Binary file added desktop/icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/icons/icon.icns
Binary file not shown.
Binary file added desktop/icons/icon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions desktop/pkg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const HOST_NAME = 'localhost';
const PORT = 4000;

const initCli = function() {
const cli = require('@nuxt/cli');
const path = require('path');
const _argv = [];
_argv[0] = 'start';
_argv.push('--spa');
_argv.push(`--port=${PORT}`);
_argv.push(`--hostname=${HOST_NAME}`);
_argv.push(path.resolve(__dirname, '..'));
cli.run(_argv);
};

/*
const initNuxt = async () => {
const {Nuxt} = require('@nuxt/core');
let config = {};
config.rootDir = __dirname;
config.dev = false;
config.mode = 'spa';
/!** @type Nuxt *!/
let nuxt = new Nuxt(config);
await nuxt.ready();
await nuxt.server.listen(PORT, HOST_NAME);
};
*/

// initNuxt();
initCli();
4 changes: 4 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<script>
import {shortHashFilter, support} from "~/assets/utils";
import {NETWORK, TESTNET} from '~/assets/variables';
import TestnetNotice from '~/components/common/TestnetNotice';
import Snackbar from '~/components/common/Snackbar';
import Language from '~/layouts/_language';
import Footer from '~/layouts/_footer';
export default {
components: {
TestnetNotice,
Snackbar,
Language,
Footer,
Expand Down Expand Up @@ -67,6 +69,8 @@

<template>
<div class="main-wrap">
<TestnetNotice/>

<header class="header">
<div class="header__container u-container u-container--large">
<nuxt-link class="header__logo no-link" :to="$i18nGetPreferredPath('index')">
Expand Down
4 changes: 4 additions & 0 deletions layouts/nonAuth.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script>
import {NETWORK, TESTNET} from '~/assets/variables';
import TestnetNotice from '~/components/common/TestnetNotice';
import Snackbar from '~/components/common/Snackbar';
import Language from '~/layouts/_language';
import Footer from '~/layouts/_footer';
export default {
components: {
TestnetNotice,
Snackbar,
Language,
Footer,
Expand All @@ -20,6 +22,8 @@

<template>
<div class="main-wrap">
<TestnetNotice/>

<header class="header">
<div class="header__container u-container u-container--medium">
<nuxt-link class="header__logo no-link" :to="$i18nGetPreferredPath('index')">
Expand Down
Loading

0 comments on commit a33f57c

Please sign in to comment.