OSDN Git Service

Add the toggle Advanced Nav Function in MenuView
authorZhiting Lin <zlin035@uottawa.ca>
Mon, 19 Mar 2018 11:12:06 +0000 (19:12 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Mon, 19 Mar 2018 11:12:06 +0000 (19:12 +0800)
main-process/menus/application-menu.js
main-process/preload.js
main.js
src/features/app/components/Navigation/Navigation.jsx
src/utility/localStorage.js

index 2b6283b..8d19631 100755 (executable)
@@ -1,6 +1,9 @@
 const {BrowserWindow, Menu, app, shell, dialog} = require('electron')
+const settings = require('electron-settings')
 const url  = require('url')
 
+let advNav = settings.get('browserSetting.app.navAdvancedState') || 'normal'
+
 let template = [{
   label: 'Account',
   submenu: [{
@@ -40,7 +43,29 @@ let template = [{
       }
     }
   }]
-},  {
+}, {
+  label: 'View',
+  submenu: [{
+    label: 'BTM Amount Unit',
+  }, {
+    label: 'Advanced Navigation',
+    type: 'checkbox',
+    checked: advNav === 'advance',
+    click: (item, focusedWindow) => {
+      if (focusedWindow) {
+        if(advNav === 'advance'){
+          focusedWindow.webContents.send('toggleNavState', 'normal')
+        }else{
+          focusedWindow.webContents.send('toggleNavState', 'advance')
+        }
+      }
+    }
+  },{
+    type: 'separator'
+  },{
+    label: 'Lanugage'
+  }]
+}, {
   label: 'Help',
   role: 'help',
   submenu: [{
@@ -153,6 +178,12 @@ if (process.platform === 'win32') {
 app.on('ready', () => {
   const menu = Menu.buildFromTemplate(template)
   Menu.setApplicationMenu(menu)
+
+  settings.watch('browserSetting.app.navAdvancedState', newValue => {
+    advNav = newValue
+    menu.items[2].submenu.items[1].checked = ( advNav === 'advance' )
+  })
+
 })
 
 app.on('browser-window-created', () => {
index a90deef..0ea43fa 100644 (file)
@@ -1 +1,3 @@
-window.ipcRenderer = require('electron').ipcRenderer
\ No newline at end of file
+window.ipcRenderer = require('electron').ipcRenderer
+
+window.settings = require('electron').remote.require('electron-settings')
diff --git a/main.js b/main.js
index aede886..0547c98 100644 (file)
--- a/main.js
+++ b/main.js
@@ -7,6 +7,7 @@ const path = require('path')
 
 let win
 
+
 function initialize () {
   // const shouldQuit = makeSingleInstance()
   // if (shouldQuit) return app.quit()
@@ -33,6 +34,8 @@ function initialize () {
     // const startUrl = 'http://localhost:3000/'
     win.loadURL(startUrl)
 
+    win.webContents.openDevTools()
+
     win.on('closed', () => {
       win = null
     })
index 5b8a9be..471e985 100644 (file)
@@ -4,6 +4,8 @@ import {Link} from 'react-router'
 import styles from './Navigation.scss'
 import {navIcon} from '../../utils'
 import Sync from '../Sync/Sync'
+import appAction from '../../../app/actions'
+
 
 class Navigation extends React.Component {
   constructor(props) {
@@ -12,6 +14,14 @@ class Navigation extends React.Component {
     this.openTutorial = this.openTutorial.bind(this)
   }
 
+  componentDidMount() {
+    if(window.ipcRenderer){
+      window.ipcRenderer.on('toggleNavState', (event, arg) => {
+        arg === 'advance'? this.props.showNavAdvanced() : this.props.hideNavAdvanced()
+      })
+    }
+  }
+
   openTutorial(event) {
     event.preventDefault()
     this.props.openTutorial()
@@ -96,6 +106,8 @@ export default connect(
     }
   },
   (dispatch) => ({
+    showNavAdvanced: () => dispatch(appAction.showNavAdvanced),
+    hideNavAdvanced: () => dispatch(appAction.hideNavAdvanced),
     openTutorial: () => dispatch({type: 'OPEN_TUTORIAL'}),
     setLang: (event) => {
       dispatch({
index 631bf2f..0ed9e46 100644 (file)
@@ -1,3 +1,5 @@
+const settings = window.settings
+
 export const clear = () => {
   try {
     localStorage.clear()
@@ -27,9 +29,19 @@ export const exportState = (store) => () => {
     },
     tutorial: state.tutorial
   }
+  const browserSetting = {
+    core:{
+      btmAmountUnit: state.core.btmAmountUnit,
+      lang: state.core.lang
+    },
+    app:{
+      navAdvancedState : state.app.navAdvancedState,
+    }
+  }
 
   try {
     localStorage.setItem('reduxState', JSON.stringify(exportable))
+    settings.set('browserSetting', browserSetting)
   } catch (err) { /* localstorage not available */ }
 }