-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d82065
commit c05698b
Showing
8 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Build/Release Cherry Studio | ||
name: Release | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
provider: generic | ||
url: https://example.com/auto-updates | ||
url: http://127.0.0.1:8080 | ||
updaterCacheDirName: cherry-studio-updater |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { autoUpdater, UpdateInfo } from 'electron-updater' | ||
import logger from 'electron-log' | ||
import { dialog, ipcMain } from 'electron' | ||
|
||
export default class AppUpdater { | ||
constructor() { | ||
logger.transports.file.level = 'debug' | ||
autoUpdater.logger = logger | ||
autoUpdater.forceDevUpdateConfig = true | ||
autoUpdater.autoDownload = false | ||
autoUpdater.checkForUpdatesAndNotify() | ||
|
||
// 触发检查更新(此方法用于被渲染线程调用,例如页面点击检查更新按钮来调用此方法) | ||
ipcMain.on('check-for-update', () => { | ||
logger.info('触发检查更新') | ||
autoUpdater.checkForUpdates() | ||
}) | ||
|
||
// 检测下载错误 | ||
autoUpdater.on('error', (error) => { | ||
logger.error('更新异常', error) | ||
}) | ||
|
||
// 检测是否需要更新 | ||
autoUpdater.on('checking-for-update', () => { | ||
logger.info('正在检查更新……') | ||
}) | ||
|
||
autoUpdater.on('update-available', (releaseInfo: UpdateInfo) => { | ||
autoUpdater.logger?.info('检测到新版本,确认是否下载') | ||
const releaseNotes = releaseInfo.releaseNotes | ||
let releaseContent = '' | ||
if (releaseNotes) { | ||
if (typeof releaseNotes === 'string') { | ||
releaseContent = <string>releaseNotes | ||
} else if (releaseNotes instanceof Array) { | ||
releaseNotes.forEach((releaseNote) => { | ||
releaseContent += `${releaseNote}\n` | ||
}) | ||
} | ||
} else { | ||
releaseContent = '暂无更新说明' | ||
} | ||
|
||
// 弹框确认是否下载更新(releaseContent是更新日志) | ||
dialog | ||
.showMessageBox({ | ||
type: 'info', | ||
title: '应用有新的更新', | ||
detail: releaseContent, | ||
message: '发现新版本,是否现在更新?', | ||
buttons: ['否', '是'] | ||
}) | ||
.then(({ response }) => { | ||
if (response === 1) { | ||
autoUpdater.downloadUpdate() | ||
} | ||
}) | ||
}) | ||
|
||
// 检测到不需要更新时 | ||
autoUpdater.on('update-not-available', () => { | ||
logger.info('现在使用的就是最新版本,不用更新') | ||
}) | ||
|
||
// 更新下载进度 | ||
autoUpdater.on('download-progress', (progress) => { | ||
logger.info('下载进度', progress) | ||
}) | ||
|
||
// 当需要更新的内容下载完成后 | ||
autoUpdater.on('update-downloaded', () => { | ||
logger.info('下载完成,准备更新') | ||
dialog | ||
.showMessageBox({ | ||
title: '安装更新', | ||
message: '更新下载完毕,应用将重启并进行安装' | ||
}) | ||
.then(() => { | ||
setImmediate(() => autoUpdater.quitAndInstall()) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters