Skip to content

Commit

Permalink
feat: add electron-settings to persist user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lin.zhou committed Sep 30, 2018
1 parent 6917546 commit 85f4244
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ npm test
- [x] 关键字高亮
- [ ] 脚本编辑工具
- [ ] 串口网络共享
- [ ] Travis CI集成
- [ ] 分布式自动化测试
- [ ] slack聊天客户端
- [ ] 国际化
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "IOT-Dashboard",
"version": "0.1.4",
"version": "0.1.5",
"author": "Pansila <[email protected]>",
"description": "A debug tool helping with WiFi IOT development",
"license": "MIT",
Expand Down Expand Up @@ -29,11 +29,7 @@
"output": "build"
},
"publish": [
"github",
{
"provider": "generic",
"url": "http://127.0.0.1:8000/"
}
"github"
],
"nsis": {
"artifactName": "${productName}-${version}.${ext}"
Expand Down Expand Up @@ -78,6 +74,7 @@
"babel-register": "^6.24.1",
"bootstrap-vue": "^2.0.0-rc.11",
"electron-log": "^2.2.17",
"electron-settings": "^3.2.0",
"electron-updater": "^3.1.2",
"serialport": "^6.2.2",
"through2": "^2.0.3",
Expand Down
47 changes: 39 additions & 8 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {fork} from 'child_process'
import * as constant from '@utils/Constant.js'
import { autoUpdater } from 'electron-updater'
import log from 'electron-log'
import config from '@config/config.json'
// import fs from 'fs'
// import asar from 'asar'
import settings from 'electron-settings'

log.transports.file.level = 'debug'

Expand All @@ -18,6 +20,11 @@ if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}

log.info('node: ' + process.versions.node,
'electron: ' + process.versions['atom-shell'],
'platform: ' + require('os').platform(),
'vue: ' + require('vue/package.json').version)

let mainWindow
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
Expand Down Expand Up @@ -125,17 +132,41 @@ ipcMain.on(constant.EVENT_ASYNC_MSG, (ev, arg) => {
}
})

// const configDir = path.join(__dirname, '..', '..', '..', '..', 'config')
// const appAsar = path.join(__dirname, '..', '..', '..', 'app.asar')

function releaseStaticResource () {
// let init = 100
// asar.listPackage(appAsar).forEach(n => { if (init) { log.debug(n); init-- } if (n.startsWith('dist')) log.debug(n) })
// log.debug(configDir, appAsar)

// IOT-Dashboard\resources\app.asar\dist\electron\xxx
// fs.stat(configDir, (err, stats) => {
// if (err) {
// log.error(err)
// fs.mkdirSync(configDir)
// } else {
// if (stats.isFile()) {
// log.error(configDir + 'should be a directory')
// return
// }
// }
// // log.debug(asar.listPackage(appAsar).indexOf('\dist\electron\static\config\config.json.template'))
// // asar.extractFile(appAsar, 'dist/electron/static/config/config.json.template').pipe(fs.createWriteStream(path.join(configDir, 'config.json.template')))
// // fs.copyFileSync(path.join(configAsar, 'config.json.template'), path.join(configDir, 'config.json.template'))
// })
}

app.on('ready', () => {
if (process.env.NODE_ENV === 'production') {
let updateCheckTimer
autoUpdater.logger = log
if (config.updateServer) {
try {
autoUpdater.setFeedURL(config.updateServer)
} catch (err) {
log.error(err)
}
releaseStaticResource()

if (settings.has('updateServer')) {
autoUpdater.setFeedURL(settings.get('updateServer'))
}

autoUpdater.logger = log
autoUpdater.checkForUpdates()
ipcMain.on(constant.EVENT_UPDATE, (e, action) => {
switch (action) {
Expand Down
6 changes: 0 additions & 6 deletions src/renderer/components/TabBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

<script>
import {ipcRenderer} from 'electron'
import log from 'electron-log'
import Console from '@components/ConsolePage/Console'
import * as constant from '@utils/Constant'
Expand All @@ -70,11 +69,6 @@
}
},
mounted () {
log.info('node: ' + process.versions.node,
'electron: ' + process.versions['atom-shell'],
'platform: ' + require('os').platform(),
'vue: ' + require('vue/package.json').version)
// setTimeout(() => this.$refs.modalUpdate.show(), 5000)
ipcRenderer.on(constant.EVENT_UPDATE, (event, info) => {
// this.updateVersion = info
Expand Down
3 changes: 0 additions & 3 deletions static/config/config.json

This file was deleted.

11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,10 @@ clone@^1.0.2:
version "1.0.4"
resolved "http://r.cnpmjs.org/clone/download/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"

clone@^2.1.1:
version "2.1.2"
resolved "http://r.cnpmjs.org/clone/download/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"

co@^4.6.0:
version "4.6.0"
resolved "http://r.cnpmjs.org/co/download/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
Expand Down Expand Up @@ -3237,6 +3241,13 @@ electron-rebuild@^1.8.2:
spawn-rx "^2.0.10"
yargs "^7.0.2"

electron-settings@^3.2.0:
version "3.2.0"
resolved "http://r.cnpmjs.org/electron-settings/download/electron-settings-3.2.0.tgz#01461e153f95b6f18adbe0c360c70898eb0f43c3"
dependencies:
clone "^2.1.1"
jsonfile "^4.0.0"

electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.47:
version "1.3.58"
resolved "http://r.cnpmjs.org/electron-to-chromium/download/electron-to-chromium-1.3.58.tgz#8267a4000014e93986d9d18c65a8b4022ca75188"
Expand Down

0 comments on commit 85f4244

Please sign in to comment.