diff --git a/packages/gui/pkg/after-all-artifact-build.js b/packages/gui/pkg/after-all-artifact-build.js new file mode 100644 index 0000000..cb35328 --- /dev/null +++ b/packages/gui/pkg/after-all-artifact-build.js @@ -0,0 +1,21 @@ +const path = require('path') +const pkg = require('../package.json') +const fs = require('fs') + +function appendIntro (context, systemType, latest) { + const partUpdateFile = `update-${systemType}-${pkg.version}.zip` + + const partUpdateUrl = context.configuration.publish.url + partUpdateFile + + const latestFilePath = path.join(context.outDir, latest) + fs.appendFile(latestFilePath, `\npartPackage: ${partUpdateUrl}\nreleaseNotes: \n - 升级日志`, (err) => { + if (err) { + console.log('修改latest 失败') + } + }) +} +exports.default = async function (context) { + console.log('context222', context) + appendIntro(context, 'mac', 'latest-mac.yml') + appendIntro(context, 'win', 'latest.yml') +} diff --git a/packages/gui/pkg/after-pack.js b/packages/gui/pkg/after-pack.js index e511d2c..cf7b012 100644 --- a/packages/gui/pkg/after-pack.js +++ b/packages/gui/pkg/after-pack.js @@ -1,29 +1,19 @@ const path = require('path') const AdmZip = require('adm-zip') const pkg = require('../package.json') -const fs = require('fs') exports.default = async function (context) { console.log('context', context) let targetPath - let latest = null + let systemType = '' if (context.packager.platform.nodeName === 'darwin') { targetPath = path.join(context.appOutDir, `${context.packager.appInfo.productName}.app/Contents/Resources`) - latest = 'latest-mac.yml' + systemType = 'mac' } else { targetPath = path.join(context.appOutDir, './resources') - latest = 'latest.yml' + systemType = 'win' } const zip = new AdmZip() zip.addLocalFolder(targetPath) - const partUpdateFile = `update-${pkg.version}.zip` + const partUpdateFile = `update-${systemType}-${pkg.version}.zip` zip.writeZip(path.join(context.outDir, partUpdateFile)) - - const partUpdateUrl = 'http://dev-sidecar.docmirror.cn/update/' + partUpdateFile - - const latestFilePath = path.join(context.outDir, latest) - fs.appendFile(latestFilePath, `\npartPackage: ${partUpdateUrl}\nreleaseNotes: \n - 升级日志`, (err) => { - if (err) { - console.log('修改latest 失败') - } - }) } diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index d47f377..451d737 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -210,7 +210,7 @@ if (!isFirstInstance) { } try { createWindow() - const context = { win, app, beforeQuit, ipcMain, dialog, log } + const context = { win, app, beforeQuit, quit, ipcMain, dialog, log } backend.install(context) // 模块安装 } catch (err) { log.info('err', err) diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index 429eda3..fbd5265 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -7,6 +7,7 @@ import progress from 'request-progress' import fs from 'fs' import AdmZip from 'adm-zip' import logger from '../../utils/util.log' +import appPathUtil from '../../utils/util.apppath' // eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' @@ -33,7 +34,7 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) { } // 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写 -function updateHandle (app, win, beforeQuit, log) { +function updateHandle (app, win, beforeQuit, quit, log) { // // 更新前,删除本地安装包 ↓ // const updaterCacheDirName = 'dev-sidecar-updater' // const updatePendingPath = path.join(autoUpdater.app.baseCachePath, updaterCacheDirName, 'pending') @@ -58,9 +59,9 @@ function updateHandle (app, win, beforeQuit, log) { let partPackagePath = null function downloadPart (app, value) { - const appPath = app.getAppPath() + const appPath = appPathUtil.getAppRootPath() const fileDir = path.join(appPath, 'update') - console.log('fileDir', fileDir) + logger.info('download dir', fileDir) try { fs.accessSync(fileDir, fs.constants.F_OK) } catch (e) { @@ -84,8 +85,8 @@ function updateHandle (app, win, beforeQuit, log) { }) } - function updatePart (app, value, partPackagePath) { - const appPath = app.getAppPath() + function updatePart (app, value, partPackagePath, quit) { + const appPath = appPathUtil.getAppRootPath() const target = path.join(appPath, 'resources') log.info('开始解压缩,安装升级包', partPackagePath, target) // 解压缩 @@ -93,7 +94,7 @@ function updateHandle (app, win, beforeQuit, log) { zip.extractAllTo(target, true) log.info('安装完成,重启app') app.relaunch() - app.quit() + quit() } autoUpdater.on('error', function (error) { @@ -169,7 +170,7 @@ function updateHandle (app, win, beforeQuit, log) { export default { install (context) { - const { app, win, beforeQuit, log } = context + const { app, win, beforeQuit, quit, log } = context if (process.env.NODE_ENV === 'development') { Object.defineProperty(app, 'isPackaged', { get () { @@ -179,6 +180,6 @@ export default { // updateUrl = 'http://dev-sidecar.docmirror.cn/update/' // updateUrl = 'http://localhost/dev-sidecar/' } - updateHandle(app, win, beforeQuit, log) + updateHandle(app, win, beforeQuit, quit, log) } } diff --git a/packages/gui/src/utils/util.apppath.js b/packages/gui/src/utils/util.apppath.js new file mode 100644 index 0000000..b3c86ca --- /dev/null +++ b/packages/gui/src/utils/util.apppath.js @@ -0,0 +1,13 @@ +import path from 'path' +// const isDevelopment = process.env.NODE_ENV !== 'production' +export default { + getAppRootPath () { + // if (isDevelopment) { + // return app.getAppPath() + // } else { + // return path.join(app.getAppPath(), '../../') + // } + + return path.resolve('.') + } +} diff --git a/packages/gui/src/view/App.vue b/packages/gui/src/view/App.vue index 74d717b..3b8f74b 100644 --- a/packages/gui/src/view/App.vue +++ b/packages/gui/src/view/App.vue @@ -36,7 +36,7 @@ @@ -52,6 +52,7 @@ export default { }, data () { return { + info: {}, menus: undefined } }, @@ -59,6 +60,9 @@ export default { }, created () { this.menus = createMenus(this) + this.$api.info.get().then(ret => { + this.info = ret + }) }, methods: { handleClick (e) { diff --git a/packages/gui/vue.config.js b/packages/gui/vue.config.js index 2e21a46..055c3f1 100644 --- a/packages/gui/vue.config.js +++ b/packages/gui/vue.config.js @@ -36,6 +36,7 @@ module.exports = { mainProcessWatch: ['src/bridge', 'src/*.js', 'node_modules/dev-sidecar/src'], builderOptions: { afterPack: './pkg/after-pack.js', + afterAllArtifactBuild: './pkg/after-all-artifact-build.js', // builderOptions: { // publish: ['github']// 此处写入github 就好,不用添加其他内容 // },