Browse Source

启动器v0.1.2正式版

laiguoran 6 years ago
parent
commit
dd3e74400a

+ 1 - 1
.electron-vue/webpack.renderer.config.js

@@ -18,7 +18,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
  * that provide pure *.vue files that need compiling
  * https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
  */
-let whiteListedModules = ['vue']
+let whiteListedModules = ['vue', 'electron', 'fs-extra', 'axios', 'vuex', 'element-ui', 'vue-electron']
 
 let rendererConfig = {
   devtool: '#cheap-module-eval-source-map',

+ 1 - 0
package.json

@@ -28,6 +28,7 @@
     "directories": {
       "output": "build"
     },
+    "asar": false,
     "files": [
       "dist/electron/**/*"
     ],

+ 5 - 4
src/main/index.js

@@ -5,7 +5,7 @@ import usbffi from './main-process/usb-ffi'
 import downloads from './main-process/downloads'
 import updateInstall from './main-process/updateInstall'
 import fileselect from './main-process/file-select'
-import db from '../database/index'
+import db from '../database'
 const path = require('path')
 // const glob = require('glob')
 const electron = require('electron')
@@ -28,7 +28,7 @@ let winURL = process.env.NODE_ENV === 'development'
   : `file://${__dirname}/index.html`
 
 let firsturl = db.read().get('sc_hadInstall.first').value()
-winURL += firsturl ? '/#/firstopen' : '/#' + db.read().get('sc_hadInstall.url').value()
+winURL += firsturl ? '#/firstopen' : '#' + db.read().get('sc_hadInstall.url').value()
 
 function initialize () {
   function createWindow () {
@@ -37,8 +37,8 @@ function initialize () {
      * Initial window options
      */
     const windowOptions = {
-      // width: 900,
-      width: 1450,
+      width: 900,
+      // width: 1450,
       height: 564,
       resizable: false,
       show: true,
@@ -54,6 +54,7 @@ function initialize () {
     }
     mainWindow = new BrowserWindow(windowOptions)
     mainWindow.loadURL(winURL)
+    // 打包测试弹出devtools
     // mainWindow.webContents.openDevTools()
 
     mainWindow.on('closed', () => {

+ 1 - 1
src/main/main-process/downloads.js

@@ -7,7 +7,7 @@
  * @date 2018/6/22
  * @version
  */
-import db from '../../database/index'
+import db from '../../database'
 const path = require('path')
 const electron = require('electron')
 const ipcMain = electron.ipcMain

+ 1 - 1
src/main/main-process/file-select.js

@@ -7,7 +7,7 @@
  * @date 2018/6/20
  * @version
  */
-import db from '../../database/index'
+import db from '../../database'
 const path = require('path')
 const ffi = require('ffi')
 const fs = require('fs')

+ 60 - 49
src/main/main-process/updateInstall.js

@@ -7,7 +7,7 @@
  * @date 2018/6/20
  * @version
  */
-import db from '../../database/index'
+import db from '../../database'
 const fs = require('fs')
 const fse = require('fs-extra')
 const path = require('path')
@@ -32,44 +32,52 @@ const updateInstall = function (win) {
         await productAndExeDataIsshow()
         let softwarelist = result.data.keys
         let promiseArr = []
+        let promiseArr2 = []
         for (let i in softwarelist) {
           if (softwarelist[i].indexOf('SmartCost_') !== -1) {
-            await getExeDataList(softwarelist[i])
+            promiseArr2.push(getExeDataList(softwarelist[i]))
           }
         }
-        await sleep(3000)
-        if (globalSoftware !== []) {
-          for (let i in globalSoftware) {
-            globalSoftware[i].exeName = globalExe[i]
-            promiseArr.push(insertData(globalSoftware[i]))
-          }
-        }
-        await Promise.all(promiseArr)
+        await Promise.all(promiseArr2)
           .then(async function (result) {
-            let delnum = await delProductAndExeDataAsync()
-            await db.read().set('sc_hadInstall.first', false).write()
-            let exeInfo = await db.read().get('sc_exeData').last().value()
-            let gourl = exeInfo.pid === undefined ? 1 : exeInfo.pid
-            await db.read().set('sc_hadInstall.url', '/softwarestartup/' + gourl).write()
-            if (promiseArr !== undefined && promiseArr.length !== 0) {
-              win.webContents.send('successUpdate', { id: gourl, num: globalNUM, delnum: delnum })
-              console.log(globalSoftware)
-              globalNUM = 0
-              globalSoftware = []
-              globalExe = []
-            } else {
-              win.webContents.send('failedUpdate', { id: '1' })
+            await sleep(5000)
+            if (globalSoftware !== []) {
+              for (let i in globalSoftware) {
+                globalSoftware[i].exeName = globalExe[i]
+                promiseArr.push(insertData(globalSoftware[i]))
+              }
             }
+            await Promise.all(promiseArr)
+              .then(async function (result) {
+                console.log(globalSoftware)
+                let delnum = await delProductAndExeDataAsync()
+                await db.read().set('sc_hadInstall.first', false).write()
+                let exeInfo = await db.read().get('sc_exeData').last().value()
+                let gourl = exeInfo === '{}' || exeInfo.pid === undefined ? 1 : exeInfo.pid
+                await db.read().set('sc_hadInstall.url', '/softwarestartup/' + gourl).write()
+                if (promiseArr !== undefined && promiseArr.length !== 0) {
+                  win.webContents.send('successUpdate', {id: gourl, num: globalNUM, delnum: delnum})
+                  // console.log(globalSoftware)
+                } else {
+                  win.webContents.send('failedUpdate', {id: '1', error: 200})
+                }
+                globalNUM = 0
+                globalSoftware = []
+                globalExe = []
+              })
+              .catch(function (err) {
+                win.webContents.send('failedUpdate', {id: '1', error: err})
+                console.log(err)
+                globalNUM = 0
+                globalSoftware = []
+                globalExe = []
+              })
           })
           .catch(function (err) {
-            win.webContents.send('failedUpdate', { id: '1' })
             console.log(err)
-            globalNUM = 0
-            globalSoftware = []
-            globalExe = []
           })
-      } catch (err) {
-        console.log(err)
+      } catch (error) {
+        console.log(error)
       }
     })
   })
@@ -224,28 +232,31 @@ const updateInstall = function (win) {
    * @param Info
    */
   function getExeDataList (Info) {
+    return new Promise(resolve => {
     // setTimeout(function () {
-    regedit.list(regeditPath + '\\' + Info).on('data', async function (result) {
-      let values = result.data.values
-      let simpleVersion = values['DisplayVersion'] === undefined || values['DisplayVersion'] === null ? '' : values['DisplayVersion'].value.split('_')
-      let regeditData = {
-        path: values['Inno Setup: App Path'].value,
-        name: values['DisplayName'].value,
-        regeditName: Info,
-        fileName: values['Inno Setup: Icon Group'].value,
-        simpleName: simpleVersion === '' ? '' : simpleVersion[0],
-        versionName: simpleVersion === '' ? '' : simpleVersion[1]
-      }
-      let dirname = await fs.readdirSync(regeditData.path)
-      for (let i in dirname) {
-        if (path.extname(dirname[i]) === '.exe' && existSoftwareName(dirname[i])) {
-          let exeData = regeditData
-          // exeData.exeName = diraname[i]
-          // 这里必须分离2个数组记录值并在外面合并,push才不会出错,否则会重复exeName名,未知bug,坑
-          globalSoftware.push(exeData)
-          globalExe.push(dirname[i])
+      regedit.list(regeditPath + '\\' + Info).on('data', async function (result) {
+        let values = result.data.values
+        let simpleVersion = values['DisplayVersion'] === undefined || values['DisplayVersion'] === null ? '' : values['DisplayVersion'].value.split('_')
+        let regeditData = {
+          path: values['Inno Setup: App Path'].value,
+          name: values['DisplayName'].value,
+          regeditName: Info,
+          fileName: values['Inno Setup: Icon Group'].value,
+          simpleName: simpleVersion === '' ? '' : simpleVersion[0],
+          versionName: simpleVersion === '' ? '' : simpleVersion[1]
         }
-      }
+        let dirname = await fs.readdirSync(regeditData.path)
+        for (let i in dirname) {
+          if (path.extname(dirname[i]) === '.exe' && existSoftwareName(dirname[i])) {
+            let exeData = regeditData
+            // exeData.exeName = diraname[i]
+            // 这里必须分离2个数组记录值并在外面合并,push才不会出错,否则会重复exeName名,未知bug,坑
+            globalSoftware.push(exeData)
+            globalExe.push(dirname[i])
+          }
+        }
+      })
+      resolve('ok')
     })
   }
 }

+ 1 - 1
src/main/main-process/usb-ffi.js

@@ -37,7 +37,7 @@ async function testUsb (webContents) {
     let libm = ffi.Library(pathstr, {
       'GetProductIDList': ['string', []]
     })
-    console.log(await libm.GetProductIDList())
+    // console.log(await libm.GetProductIDList())
     let alllist = await libm.GetProductIDList()
     if (alllist !== '') {
       // let productlist = alllist.split('|')

+ 1 - 1
src/main/software-update.js

@@ -38,7 +38,7 @@ exports.initialize = function (win) {
   autoUpdater.on('download-progress', function (progressObj) {
     win.webContents.send('downloadProgress', progressObj)
     win.setProgressBar(progressObj.percent / 100)
-    console.log(progressObj)
+    // console.log(progressObj)
   })
   autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
     ipcMain.on('isUpdateNow', (e, arg) => {

+ 7 - 1
src/renderer/components/StartUpPage.vue

@@ -110,7 +110,7 @@
     padding: 0!important;
   }
   .el-loading-mask {
-    position: fixed;
+    position: fixed !important;
   }
   .el-tabs__item.is-active {
     color: #495057!important;
@@ -140,4 +140,10 @@
     border-left: 1px solid #dee2e6!important;
     border-right-color: #dee2e6;
   }
+  .btn-sm {
+    padding: .25rem .5rem !important;
+    font-size: .875rem !important;
+    line-height: 1.5 !important;
+    border-radius: .2rem !important;
+  }
 </style>

+ 11 - 13
src/renderer/components/StartUpPage/DownloadHeader.vue

@@ -163,14 +163,18 @@
         }
       },
       testbtn () {
-        console.log(`新增了 1 个纵横软件`)
-        this.$message({
-          message: `新增了 1 个纵横软件`,
-          onClass: () => {
-            console.log('close')
-            // this.message.info(`移除了 1 个纵横软件`)
-          }
+        const path = require('path')
+        const ffi = require('ffi')
+        let exeData = {
+          path: 'C:\\Program Files (x86)\\纵横软件\\广东公路造价编审系统(标准化2011)专业版 910(营改增)',
+          exeName: 'SmartCost_GuangDong.exe'
+        }
+        let pathstr = path.join('data/fileInfo.dll')
+        let libm = ffi.Library(pathstr, {
+          'GetFileInfo': ['string', ['string']]
         })
+        let fileinfo = JSON.parse(libm.GetFileInfo(path.join(exeData.path, exeData.exeName)))
+        console.log(fileinfo)
       },
       installbtn (id) {
         let info = this.$db.read().get('sc_download').getById(id).value()
@@ -205,12 +209,6 @@
   .el-progress-bar__inner,.el-progress-bar__outer {
     border-radius: .25rem !important;
   }
-  .btn-sm {
-    padding: .25rem .5rem;
-    font-size: .875rem;
-    line-height: 1.5;
-    border-radius: .2rem;
-  }
   .badge-info {
     color: #fff;
     background-color: #17a2b8;

+ 21 - 18
src/renderer/components/StartUpPage/SoftwareList.vue

@@ -43,24 +43,27 @@
       if (this.checkOnline()) {
         let version = fs.readJsonSync(softwarejson).startup_version
         let self = this
-        this.$http.get('http://www.smartcost.com.cn/startup/sc_version.json')
-          .then(function (response) {
-            if (version === response.data.startup_version) {
-              self.softwarelist = fs.readJsonSync(softwarejson).sc_product
-            } else {
-              self.loading = true
-              self.$http.get('http://www.smartcost.com.cn/startup/sc_software.json')
-                .then(function (response2) {
-                  fs.writeJsonSync(softwarejson, response2.data)
-                  self.softwarelist = response2.data.sc_product
-                  self.loading = false
-                })
-                .catch(function (error2) {
-                  self.loading = false
-                  throw error2
-                })
-            }
-          })
+        this.$http({
+          url: 'http://www.smartcost.com.cn/startup/sc_version.json',
+          method: 'get',
+          timeout: 5000
+        }).then(function (response) {
+          if (version === response.data.startup_version) {
+            self.softwarelist = fs.readJsonSync(softwarejson).sc_product
+          } else {
+            self.loading = true
+            self.$http.get('http://www.smartcost.com.cn/startup/sc_software.json')
+              .then(function (response2) {
+                fs.writeJsonSync(softwarejson, response2.data)
+                self.softwarelist = response2.data.sc_product
+                self.loading = false
+              })
+              .catch(function (error2) {
+                self.loading = false
+                throw error2
+              })
+          }
+        })
           .catch(function () {
             self.$message.error('网络不佳,无法获取最新列表')
           })

+ 68 - 55
src/renderer/components/StartUpPage/SoftwareStartup.vue

@@ -50,65 +50,78 @@
       this.fetchData()
       let self = this
       this.$electron.ipcRenderer.on('successUpdate', (event, msg) => {
-        self.loading = false
-        let num = msg.num
-        let delnum = msg.delnum
-        this.$electron.ipcRenderer.send('testUsb')
-        if (num !== 0 && delnum !== 0) {
-          self.$message({
-            message: `新增了 ${num} 个纵横软件`,
-            type: 'success'
-          })
-          setTimeout(function () {
-            self.$message({
-              message: `移除了 ${delnum} 个纵横软件`,
-              type: 'error'
-            })
-          }, 2000)
-        } else {
-          if (delnum !== 0) {
-            self.$message({
-              message: `移除了 ${delnum} 个纵横软件`,
-              type: 'error'
-            })
-          }
-
-          if (num !== 0) {
+        try {
+          self.loading = false
+          let num = msg.num
+          let delnum = msg.delnum
+          this.$electron.ipcRenderer.send('testUsb')
+          if (num !== 0 && delnum !== 0) {
             self.$message({
               message: `新增了 ${num} 个纵横软件`,
               type: 'success'
             })
+            setTimeout(function () {
+              self.$message({
+                message: `移除了 ${delnum} 个纵横软件`,
+                type: 'error'
+              })
+            }, 2000)
+          } else {
+            if (delnum !== 0) {
+              self.$message({
+                message: `移除了 ${delnum} 个纵横软件`,
+                type: 'error'
+              })
+            }
+
+            if (num !== 0) {
+              self.$message({
+                message: `新增了 ${num} 个纵横软件`,
+                type: 'success'
+              })
+            }
+            if (num === 0 && delnum === 0) {
+              self.$message.info('更新没有获取到新的纵横软件')
+            }
           }
-          if (num === 0 && delnum === 0) {
-            self.$message.info('更新没有获取到新的纵横软件')
+          let id = msg.id
+          // 如果不跳转出本产品,则让downlist 每次都执行更新一遍
+          if (self.$route.params.productid === id) {
+            self.fetchData()
+            if (self.$refs.startupDetail !== undefined) {
+              self.$refs.startupDetail.fetchData()
+            }
+          } else {
+            self.$router.push({
+              name: 'software-startup-detail',
+              params: {productid: id}
+            })
           }
-        }
-        let id = msg.id
-        // 如果不跳转出本产品,则让downlist 每次都执行更新一遍
-        if (self.$route.params.productid === id) {
-          self.fetchData()
-          self.$refs.startupDetail.fetchData()
-        } else {
-          self.$router.push({
-            name: 'software-startup-detail',
-            params: { productid: id }
-          })
+        } catch (err) {
+          console.log(err)
         }
       })
 
       this.$electron.ipcRenderer.on('failedUpdate', (event, msg) => {
-        self.loading = false
-        self.$message.info('你的电脑还没安装过纵横软件')
-        let id = msg.id
-        this.$electron.ipcRenderer.send('testUsb')
-        if (self.$route.params.productid === id) {
-          self.fetchData()
-          self.$refs.startupDetail.fetchData()
-        } else {
-          self.$router.push({
-            name: 'software-startup-detail',
-            params: { productid: id }
-          })
+        try {
+          self.loading = false
+          self.$message.info('你的电脑还没安装过纵横软件')
+          console.log(msg.error)
+          let id = msg.id
+          this.$electron.ipcRenderer.send('testUsb')
+          if (self.$route.params.productid === id && msg.error !== 200) {
+            self.fetchData()
+            if (self.$refs.startupDetail !== undefined) {
+              self.$refs.startupDetail.fetchData()
+            }
+          } else {
+            self.$router.push({
+              name: 'software-startup-detail',
+              params: { productid: id }
+            })
+          }
+        } catch (err) {
+          console.log(err)
         }
       })
 
@@ -229,14 +242,14 @@
     display: inline-block!important;
   }
   .command-menu {
-    padding: .5rem 0 ;
-    color: #212529;
-    border-radius: .25rem;
-    margin: .125rem 0 0;
-    font-size: 1rem;
+    padding: .5rem 0 !important;
+    color: #212529 !important;
+    border-radius: .25rem !important;
+    margin: .125rem 0 0 !important;
+    font-size: 1rem !important;
   }
   .command-item {
-    font-size: 1rem;
+    font-size: 1rem !important;
   }
   .el-popper[x-placement^=top] {
     margin-bottom: 5px!important;

+ 1 - 0
src/renderer/components/StartUpPage/UsbHeader.vue

@@ -84,6 +84,7 @@
           locklist.push(data)
         }
         this.lockList = locklist
+        this.$refs.usbmenu.show()
       })
       this.$electron.ipcRenderer.on('usbOut', (event) => {
         this.usbshow = false