Преглед изворни кода

0.1.15版本更新->更新修复,usb弹出修正

laiguoran пре 7 година
родитељ
комит
95ddfe264f

Разлика између датотеке није приказан због своје велике величине
+ 1 - 1
data/sc_software.json


+ 5 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "startup",
-  "version": "0.1.14",
+  "version": "0.1.15",
   "author": "珠海纵横软件有限公司",
   "description": "纵横Z+ 造价工作平台",
   "license": null,
@@ -50,10 +50,12 @@
       "oneClick": false,
       "perMachine": true,
       "include": "build/nsisfile/installer.nsh",
-      "guid": "startup",
+      "allowToChangeInstallationDirectory": true,
+      "createDesktopShortcut": true,
+      "deleteAppDataOnUninstall": true,
       "installerIcon": "build/icons/setup.ico",
       "uninstallerIcon": "build/icons/uninst.ico",
-      "createDesktopShortcut": true
+      "guid": "startup"
     },
     "extraResources": [
       {

+ 2 - 1
src/main/index.js

@@ -52,7 +52,8 @@ function initialize () {
       titleBarStyle: 'hidden',
       backgroundColor: '#fff',
       webPreferences: {
-        backgroundThrottling: false
+        backgroundThrottling: false,
+        webSecurity: false
       }
     }
     mainWindow = new BrowserWindow(windowOptions)

+ 12 - 3
src/main/main-process/exe-install.js

@@ -41,12 +41,10 @@ const exeinstall = function (win) {
               keyNumber: info.key_number,
               keytype: info.keytype,
               isshow: true,
-              auto: false,
+              auto: true,
               pid: info.pid,
               product_id: info.product_id,
               down_id: info.down_id,
-              product_version: info.version,
-              show_tip: false,
               show_updateVersion: info.version
             }
             let data = await checkDirectory(regeditMsg.path)
@@ -58,9 +56,20 @@ const exeinstall = function (win) {
               exeinfo.productVersion = data[i].ProductVersion
               exeinfo.fileDescription = data[i].FileDescription
               exeinfo.addtime = Date.parse(new Date()) / 1000
+              exeinfo.product_version = data[i].FileVersion
+              exeinfo.show_tip = data[i].FileVersion !== info.version && data[i].exeName !== 'BillsEditor.exe'
               exeinfo.id = GetFileNameNoExt(exeinfo.exeName) + '-' + RndNum(10)
               db.read().get('sc_exeData').insert(exeinfo).write()
             }
+            // 查找是否存在旧版本的软件,升级后屏蔽并删除旧版本
+            let exedatalist = await db.read().get('sc_exeData').filter({ product_id: info.product_id, down_id: info.down_id }).value()
+            for (let j in exedatalist) {
+              if (exedatalist[j].product_version !== info.version) {
+                await db.read().get('sc_exeData').updateById(exedatalist[j].id, { isshow: false }).write()
+              }
+            }
+            await db.read().get('sc_exeData').removeWhere({ isshow: false }).write()
+
             await db.read().get('sc_productData').updateById(info.pid, { isshow: true }).write()
             await db.read().set('sc_hadInstall.first', false).write()
             await db.read().set('sc_hadInstall.url', '/softwarestartup/' + info.pid).write()

+ 8 - 6
src/main/main-process/file-select.js

@@ -111,12 +111,12 @@ async function checkExeName (Directory, files) {
           keytype: regeditMsg.keytype,
           product_id: regeditMsg.product_id,
           down_id: regeditMsg.down_id,
-          product_version: regeditMsg.product_version,
-          show_tip: false,
-          show_updateVersion: regeditMsg.product_version,
+          product_version: files[i].FileVersion,
+          show_tip: regeditMsg.show_updateVersion !== '' && files[i].FileVersion !== regeditMsg.show_updateVersion && files[i].exeName !== 'BillsEditor.exe',
+          show_updateVersion: regeditMsg.show_updateVersion,
           addtime: Date.parse(new Date()) / 1000,
           isshow: true,
-          auto: false,
+          auto: regeditMsg.auto,
           id: GetFileNameNoExt(files[i].exeName) + '-' + RndNum(10)
         }
         await db.read().get('sc_exeData').insert(exeData).write()
@@ -193,7 +193,8 @@ async function checkRegeditbyDirectory (directory) {
     keytype: '',
     product_id: '',
     down_id: '',
-    product_version: ''
+    show_updateVersion: '',
+    auto: false
   }
   regedit.list(regeditPath).on('data', async function (result) {
     try {
@@ -218,6 +219,7 @@ async function checkRegeditbyDirectory (directory) {
               if (downinfo !== undefined) {
                 regeditMsg.simpleName = downinfo.product_title
                 regeditMsg.versionName = downinfo.title
+                regeditMsg.auto = true
                 let productInfo = db.read().get('sc_productData').find({ product_id: downinfo.product_id }).value()
                 if (productInfo !== undefined) {
                   regeditMsg.pid = productInfo.id
@@ -245,7 +247,7 @@ async function checkRegeditbyDirectory (directory) {
                 regeditMsg.keytype = downinfo.keytype
                 regeditMsg.product_id = downinfo.product_id
                 regeditMsg.down_id = downinfo.down_id
-                regeditMsg.product_version = downinfo.version
+                regeditMsg.show_updateVersion = downinfo.version
               }
               return regeditMsg
             }

+ 3 - 3
src/main/main-process/updateInstall.js

@@ -43,6 +43,7 @@ const updateInstall = function (win) {
           .then(async function (result) {
             await sleep(5000)
             if (globalSoftware !== []) {
+              console.log(globalSoftware)
               for (let i in globalSoftware) {
                 (async function () {
                   globalSoftware[i].exeName = globalExe[i]
@@ -219,15 +220,14 @@ const updateInstall = function (win) {
             db.read().get('sc_productData').updateById(productInfo.id, { isshow: true }).write()
           }
           // 获取json文件中的锁号,更新到exe当中
-          let downlist = fse.readJsonSync(softwarejson).sc_down
           for (let j in downlist) {
             if (productInfo.product_id === downlist[j].product_id && exeData.versionName === downlist[j].title) {
               exeData.keyNumber = downlist[j].key_number
               exeData.keytype = downlist[j].keytype
               exeData.product_id = downlist[j].product_id
               exeData.down_id = downlist[j].down_id
-              exeData.product_version = downlist[j].version
-              exeData.show_tip = false
+              exeData.product_version = fileinfo.FileVersion
+              exeData.show_tip = fileinfo.FileVesrion !== downlist[j].version && exeData.exeName !== 'BillsEditor.exe'
               exeData.show_updateVersion = downlist[j].version
               break
             }

+ 16 - 9
src/main/main-process/usb-ffi.js

@@ -20,7 +20,7 @@ const usbffi = function (win) {
     testUsb(win.webContents)
   })
   usb.on('attach', function (device) {
-    testUsb(win.webContents)
+    testUsb(win.webContents, true)
   })
   usb.on('detach', function (device) {
     win.webContents.send('usbOut')
@@ -31,8 +31,13 @@ const usbffi = function (win) {
     notification.show()
   })
 }
-
-async function testUsb (webContents) {
+/**
+ * 检测锁
+ * @param webContents
+ * @param usbIn  是否为插入u盘
+ * @return {Promise.<void>}
+ */
+async function testUsb (webContents, usbIn = false) {
   try {
     let pathstr = path.join('data/zhlData.dll')
     let libm = ffi.Library(pathstr, {
@@ -47,12 +52,14 @@ async function testUsb (webContents) {
       //   let productVerList = productlist[i].split(':')[1].split(';')
       // }
       let first = db.read().get('sc_hadInstall.first').value()
-      webContents.send('usbIn', { lockmsg: alllist, first: first })
-      const notification = new Notification({
-        title: '软件锁',
-        body: '启动器检测到软件锁'
-      })
-      notification.show()
+      webContents.send('usbIn', { lockmsg: alllist, first: first, usbIn: usbIn })
+      if (usbIn) {
+        const notification = new Notification({
+          title: '软件锁',
+          body: '启动器检测到软件锁'
+        })
+        notification.show()
+      }
     }
   } catch (err) {
     console.error(err)

+ 2 - 0
src/renderer/components/StartUpPage.vue

@@ -73,6 +73,8 @@
         }).then(function (response) {
           if (version !== response.data.startup_version) {
             // 加入随机数防止缓存
+            console.log(response.data)
+            console.log(version)
             self.$http.get('https://smartcost.com.cn/startup/sc_software.json?' + self.RndNum())
               .then(function (response2) {
                 fs.writeJsonSync(softwarejson, response2.data)

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

@@ -49,6 +49,7 @@
           for (let i in productlist) {
             let productNum = productlist[i].split(':')[0]
             let productVerList = productlist[i].split(':')[1].split(';')
+            productNum = await this.getkeynum(productNum)
             let data = {
               name: productNum
             }
@@ -91,7 +92,7 @@
             locklist.push(data)
           }
           this.lockList = locklist
-          if (this.$refs.usbmenu !== undefined) {
+          if (this.$refs.usbmenu !== undefined && result.usbIn === true) {
             this.$refs.usbmenu.show()
           }
         } else {
@@ -144,6 +145,37 @@
           }).catch(() => {
           })
         }
+      },
+      getkeynum (num) {
+        if (this.checkOnline()) {
+          return new Promise((resolve, reject) => {
+            this.$http({
+              url: 'http://cld.smartcost.com.cn/api/startup/keynum?num=' + num,
+              method: 'get',
+              timeout: 2000,
+              headers: {
+                'Access-Control-Allow-Origin': '*'
+              }
+            }).then(function (response) {
+              if (response.data.error === 0) {
+                resolve(response.data.info)
+              } else {
+                resolve(num)
+              }
+            }).catch(function () {
+              reject(num)
+            })
+          })
+        } else {
+          return num
+        }
+      },
+      checkOnline () {
+        if (!navigator.onLine) {
+          return false
+        } else {
+          return true
+        }
       }
     }
   }