diff --git a/lib/tray.js b/lib/tray.js index 280e17d..d0736a7 100644 --- a/lib/tray.js +++ b/lib/tray.js @@ -17,6 +17,8 @@ ipcMain.on('new-task-notification', (event) => { }) }); + +let isUpdate = false; ipcMain.on('put-in-tray', (event) => { if (!tray) { tray = new Tray(path.join(__dirname, '../windows-icon.png')) @@ -180,22 +182,54 @@ ipcMain.on('put-in-tray', (event) => { }, { label: "检查更新", click: function () { + if (isUpdate) { + dialog.showErrorBox(`正在更新`, "请稍后重试"); + return + } + isUpdate = true; + let git_url = "https://git.ouxuan.net/3136352472/ouxuan.oa.git"; - let workingDirPath = path.join(__dirname, "../"); - const simpleGit = require('simple-git')(workingDirPath); - simpleGit.checkIsRepo(function (err, ok) { - if (ok) { - simpleGit.pull(function (r, d) { - if (d.files.length > 0) { - app.quit() - app.relaunch(); - } + let workingDirPath = path.join(__dirname, "../../ouxuan.oa/"); + let appDir = path.join(__dirname, "../../app/"); + if (!fs.existsSync(workingDirPath)) { + fs.mkdirSync(workingDirPath) + const simpleGit = require('simple-git')(workingDirPath); + simpleGit.clone(git_url, workingDirPath, function (e) { + console.log(e) + + require('sync-copydir')("resources/ouxuan.oa/", "resources/app/") + isUpdate = false; + + dialog.showMessageBoxSync({ + "message": "更新完成" }) - } else { - dialog.showErrorBox(`更新时发生错误`, workingDirPath, err); - } - }); + app.quit() + app.relaunch(); + }) + } else { + const simpleGit = require('simple-git')(workingDirPath); + simpleGit.checkIsRepo(function (err, ok) { + if (ok) { + simpleGit.pull(function (r, d) { + if (d.files.length > 0) { + require('sync-copydir')("resources/ouxuan.oa/", "resources/app/") + dialog.showMessageBoxSync({ + "message": "更新完成" + }) + isUpdate = false; + + app.quit() + app.relaunch(); + } + }) + } else { + isUpdate = false; + + dialog.showErrorBox(`更新时发生错误`, workingDirPath + err); + } + }); + } } }, { label: "退出", diff --git a/package-lock.json b/package-lock.json index fded5a6..12660c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "electron-quick-start", + "name": "ouxuan.oa", "version": "1.0.0", "lockfileVersion": 1, "requires": true, @@ -706,8 +706,7 @@ "graceful-fs": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", - "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", - "dev": true + "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==" }, "hosted-git-info": { "version": "2.8.8", @@ -782,7 +781,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -896,6 +894,26 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node-copydir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/node-copydir/-/node-copydir-1.0.1.tgz", + "integrity": "sha512-Z10pEl8A8BVw7iRB1TuzdWMGAIBq/Chyrk+FKGxVqe6ozdXUyDMKqayyVHlwfCUVPiSxAPjqJptcAfcUO+CDEQ==", + "requires": { + "fs-extra": "^7.0.1" + }, + "dependencies": { + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -1290,6 +1308,26 @@ "debug": "^4.1.0" } }, + "sync-copydir": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sync-copydir/-/sync-copydir-1.0.3.tgz", + "integrity": "sha512-O1x97zu6zFViABPs0TnjijEE59c2rdWrZiKJvQ4SWszBGIza2iqhQiY6JWTf8lr1alAEfhR3mdRkMa76R4C01A==", + "requires": { + "fs-extra": "^7.0.1" + }, + "dependencies": { + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, "tmp": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", @@ -1347,8 +1385,7 @@ "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "url-parse-lax": { "version": "3.0.0", diff --git a/package.json b/package.json index 1ff9d1a..c16b283 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,9 @@ "electron-packager": "^14.2.1" }, "dependencies": { + "node-copydir": "^1.0.1", "os-homedir": "^2.0.0", - "simple-git": "^1.132.0" + "simple-git": "^1.132.0", + "sync-copydir": "^1.0.3" } -} \ No newline at end of file +}