const {Menu, app, shell} = require('electron')
const settings = require('electron-settings')
-const i18n = global.i18n
+global.language = settings.get('browserSetting.core.lang') || app.getLocale()
+const i18n = require('../i18n.js')
+global.i18n = i18n
const path = require('path')
const logger = require('../logger')
const log = logger.create('menu')
return menu
}
-
-function findReopenMenuItem () {
- const menu = Menu.getApplicationMenu()
- if (!menu) return
-
- let reopenMenuItem
- menu.items.forEach(item => {
- if (item.submenu) {
- item.submenu.items.forEach(item => {
- if (item.key === 'reopenMenuItem') {
- reopenMenuItem = item
- }
- })
- }
- })
- return reopenMenuItem
-}
+//
+// function findReopenMenuItem () {
+// const menu = Menu.getApplicationMenu()
+// if (!menu) return
+//
+// let reopenMenuItem
+// menu.items.forEach(item => {
+// if (item.submenu) {
+// item.submenu.items.forEach(item => {
+// if (item.key === 'reopenMenuItem') {
+// reopenMenuItem = item
+// }
+// })
+// }
+// })
+// return reopenMenuItem
+// }
const createMenu = function () {
Menu.setApplicationMenu(menu)
}
-app.on('ready', () => {
- createMenu()
- settings.watch('browserSetting.app.navAdvancedState', newValue => {
- advNav = newValue
- menu.items[2].submenu.items[1].checked = ( advNav === 'advance' )
- })
+settings.watch('browserSetting.app.navAdvancedState', newValue => {
+ advNav = newValue
+ menu.items[2].submenu.items[1].checked = ( advNav === 'advance' )
+})
- settings.watch('browserSetting.core.btmAmountUnit', newValue => {
- btmAmountUnit = newValue
- menu.items[2].submenu.items[0].submenu.items[0].checked = ( btmAmountUnit === 'BTM' )
- menu.items[2].submenu.items[0].submenu.items[1].checked = ( btmAmountUnit === 'mBTM' )
- menu.items[2].submenu.items[0].submenu.items[2].checked = ( btmAmountUnit === 'NEU' )
- })
+settings.watch('browserSetting.core.btmAmountUnit', newValue => {
+ btmAmountUnit = newValue
+ menu.items[2].submenu.items[0].submenu.items[0].checked = ( btmAmountUnit === 'BTM' )
+ menu.items[2].submenu.items[0].submenu.items[1].checked = ( btmAmountUnit === 'mBTM' )
+ menu.items[2].submenu.items[0].submenu.items[2].checked = ( btmAmountUnit === 'NEU' )
+})
- settings.watch('browserSetting.core.lang', newValue => {
- i18n.changeLanguage(newValue, (err, t) => {
- if (err) return log.error('i18n: something went wrong loading', err)
- createMenu()
- })
+settings.watch('browserSetting.core.lang', newValue => {
+ i18n.changeLanguage(newValue, (err, t) => {
+ if (err) return log.error('i18n: something went wrong loading', err)
+ createMenu()
})
-
})
-app.on('browser-window-created', () => {
- let reopenMenuItem = findReopenMenuItem()
- if (reopenMenuItem) reopenMenuItem.enabled = false
-})
+module.exports = createMenu()
-app.on('window-all-closed', () => {
- let reopenMenuItem = findReopenMenuItem()
- if (reopenMenuItem) reopenMenuItem.enabled = true
-})
+
+// app.on('ready', () => {
+// // createMenu()
+//
+// settings.watch('browserSetting.app.navAdvancedState', newValue => {
+// advNav = newValue
+// menu.items[2].submenu.items[1].checked = ( advNav === 'advance' )
+// })
+//
+// settings.watch('browserSetting.core.btmAmountUnit', newValue => {
+// btmAmountUnit = newValue
+// menu.items[2].submenu.items[0].submenu.items[0].checked = ( btmAmountUnit === 'BTM' )
+// menu.items[2].submenu.items[0].submenu.items[1].checked = ( btmAmountUnit === 'mBTM' )
+// menu.items[2].submenu.items[0].submenu.items[2].checked = ( btmAmountUnit === 'NEU' )
+// })
+//
+// settings.watch('browserSetting.core.lang', newValue => {
+// i18n.changeLanguage(newValue, (err, t) => {
+// if (err) return log.error('i18n: something went wrong loading', err)
+// createMenu()
+// })
+// })
+//
+// })
+//
+// app.on('browser-window-created', () => {
+// let reopenMenuItem = findReopenMenuItem()
+// if (reopenMenuItem) reopenMenuItem.enabled = false
+// })
+
+// app.on('window-all-closed', () => {
+// let reopenMenuItem = findReopenMenuItem()
+// if (reopenMenuItem) reopenMenuItem.enabled = true
+// })
const exec = require('child_process').exec
const glob = require('glob')
const settings = require('electron-settings')
-global.language = settings.get('browserSetting.core.lang')
-const i18n = require('./main-process/i18n.js')
const url = require('url')
const path = require('path')
const fs = require('fs')
global.fileExist = false
-global.i18n = i18n
function initialize () {
- loadMenu()
-
function createWindow() {
// Create browser Window
win = new BrowserWindow({
})
win.loadURL(startUrl)
- win.webContents.openDevTools()
+ if(process.env.DEV){
+ win.webContents.openDevTools()
+ }
win.on('closed', () => {
win = null
}
app.on('ready', () => {
- // init i18n
- if(!settings.get('browserSetting.core.lang')){
- i18n.init({lng: app.getLocale()})
- }
- const logFolder = {logFolder: path.join(app.getPath('userData'), 'logs')}
- const loggerOptions = Object.assign(logFolder)
- logger.setup(loggerOptions)
+ loadMenu()
+
+ setupConfigure()
fs.stat(`${path.join(app.getPath('userData'), '/.bytomd/genesis.json')}`, function(err) {
if(err == null) {
})
}
+const bytomdPath = process.env.DEV?
+ path.join(__dirname, '/bytomd/bytomd-darwin_amd64'):
+ glob.sync( path.join(__dirname, '/bytomd/bytomd*').replace('app.asar', 'app.asar.unpacked'))
+const bytomdDataPath = path.join(app.getPath('userData'), '/.bytomd')
function setBytomMining(event) {
- bytomdMining = exec( `cd "${app.getPath('userData')}" \
- && ${path.join(__dirname, '/bytomd/bytomd').replace('app.asar', 'app.asar.unpacked')} node --mining` ,
+ bytomdMining = exec( `${bytomdPath} node --mining --home "${bytomdDataPath}" --web.closed` ,
(error, stdout, stderr) => {
if (error) {
log.error(`bytomd mining exec error: ${error}`)
function setBytomInit(event, bytomNetwork) {
// Init bytomd
- bytomdInit = exec(`cd "${app.getPath('userData')}" \
- && ${path.join(__dirname, '/bytomd/bytomd').replace('app.asar', 'app.asar.unpacked')} init --chain_id ${bytomNetwork}` ,
+ bytomdInit = exec(`${bytomdPath} init --chain_id ${bytomNetwork} --home "${bytomdDataPath}"` ,
(error, stdout, stderr) => {
if (error) {
log.error(`bytomd init exec error: ${error}`)
files.forEach((file) => { require(file) })
}
+function setupConfigure(){
+ const logFolder = {logFolder: path.join(app.getPath('userData'), 'logs')}
+ const loggerOptions = Object.assign(logFolder)
+ logger.setup(loggerOptions)
+}
+
// Handle Squirrel on Windows startup events
switch (process.argv[1]) {
case '--squirrel-install':