From 85f42444928bf1690a884e0b3410ba19709569c3 Mon Sep 17 00:00:00 2001 From: "lin.zhou" Date: Sun, 30 Sep 2018 15:54:30 +0800 Subject: [PATCH] feat: add electron-settings to persist user settings --- README.md | 1 + package.json | 9 ++---- src/main/index.js | 47 +++++++++++++++++++++++++----- src/renderer/components/TabBar.vue | 6 ---- static/config/config.json | 3 -- yarn.lock | 11 +++++++ 6 files changed, 54 insertions(+), 23 deletions(-) delete mode 100644 static/config/config.json diff --git a/README.md b/README.md index ab21ffe..890a309 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ npm test - [x] 关键字高亮 - [ ] 脚本编辑工具 - [ ] 串口网络共享 +- [ ] Travis CI集成 - [ ] 分布式自动化测试 - [ ] slack聊天客户端 - [ ] 国际化 diff --git a/package.json b/package.json index dfd2c9c..db8756c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "IOT-Dashboard", - "version": "0.1.4", + "version": "0.1.5", "author": "Pansila ", "description": "A debug tool helping with WiFi IOT development", "license": "MIT", @@ -29,11 +29,7 @@ "output": "build" }, "publish": [ - "github", - { - "provider": "generic", - "url": "http://127.0.0.1:8000/" - } + "github" ], "nsis": { "artifactName": "${productName}-${version}.${ext}" @@ -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", diff --git a/src/main/index.js b/src/main/index.js index 9dd51a2..0fa699b 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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' @@ -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` @@ -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) { diff --git a/src/renderer/components/TabBar.vue b/src/renderer/components/TabBar.vue index a5f3d6b..0819318 100644 --- a/src/renderer/components/TabBar.vue +++ b/src/renderer/components/TabBar.vue @@ -57,7 +57,6 @@