-
Notifications
You must be signed in to change notification settings - Fork 113
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
Showing
16 changed files
with
657 additions
and
386 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
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,121 @@ | ||
import type { ProgressInfo } from "electron-updater"; | ||
|
||
export interface IpcMainEventListener<Send = void, Receive = void> { | ||
ipcMainHandle: Send extends void | ||
? (event: Electron.IpcMainInvokeEvent) => Receive | Promise<Receive> | ||
: ( | ||
event: Electron.IpcMainInvokeEvent, | ||
args: Send | ||
) => Receive | Promise<Receive>; | ||
ipcRendererInvoke: Send extends void | ||
? () => Promise<Receive> | ||
: (args: Send) => Promise<Receive>; | ||
} | ||
|
||
export interface IpcRendererEventListener<Send = void> { | ||
ipcRendererOn: Send extends void | ||
? (event: Electron.IpcRendererEvent) => void | ||
: (event: Electron.IpcRendererEvent, args: Send) => void; | ||
webContentSend: Send extends void | ||
? (webContents: Electron.WebContents) => void | ||
: (webContents: Electron.WebContents, args: Send) => void; | ||
} | ||
|
||
export class IpcChannelMainClass { | ||
IsUseSysTitle: IpcMainEventListener<void, boolean>; | ||
/** | ||
* 退出应用 | ||
*/ | ||
AppClose: IpcMainEventListener; | ||
CheckUpdate: IpcMainEventListener; | ||
ConfirmUpdate: IpcMainEventListener; | ||
OpenMessagebox: IpcMainEventListener< | ||
Electron.MessageBoxOptions, | ||
Electron.MessageBoxReturnValue | ||
>; | ||
StartDownload: IpcMainEventListener<string>; | ||
OpenErrorbox: IpcMainEventListener<{ title: string; message: string }>; | ||
StartServer: IpcMainEventListener<void, string>; | ||
StopServer: IpcMainEventListener<void, string>; | ||
HotUpdate: IpcMainEventListener; | ||
|
||
/** | ||
* | ||
* 打开窗口 | ||
*/ | ||
OpenWin: IpcMainEventListener<{ | ||
/** | ||
* 新的窗口地址 | ||
* | ||
* @type {string} | ||
*/ | ||
url: string; | ||
|
||
/** | ||
* 是否是支付页 | ||
* | ||
* @type {boolean} | ||
*/ | ||
IsPay?: boolean; | ||
|
||
/** | ||
* 支付参数 | ||
* | ||
* @type {string} | ||
*/ | ||
PayUrl?: string; | ||
|
||
/** | ||
* 发送的新页面数据 | ||
* | ||
* @type {unknown} | ||
*/ | ||
sendData?: unknown; | ||
}>; | ||
} | ||
export class IpcChannelRendererClass { | ||
// ipcRenderer | ||
DownloadProgress: IpcRendererEventListener<number>; | ||
DownloadError: IpcRendererEventListener<Boolean>; | ||
DownloadPaused: IpcRendererEventListener<Boolean>; | ||
DownloadDone: IpcRendererEventListener<{ | ||
/** | ||
* 下载的文件路径 | ||
* | ||
* @type {string} | ||
*/ | ||
filePath: string; | ||
}>; | ||
UpdateMsg: IpcRendererEventListener<{ | ||
state: number; | ||
msg: string | ProgressInfo; | ||
}>; | ||
UpdateProcessStatus: IpcRendererEventListener<{ | ||
status: | ||
| "init" | ||
| "downloading" | ||
| "moving" | ||
| "finished" | ||
| "failed" | ||
| "download"; | ||
message: string; | ||
}>; | ||
|
||
SendDataTest: IpcRendererEventListener<unknown>; | ||
BrowserViewTabDataUpdate: IpcRendererEventListener<{ | ||
bvWebContentsId: number; | ||
title: string; | ||
url: string; | ||
status: 1 | -1; // 1 添加/更新 -1 删除 | ||
}>; | ||
BrowserViewTabPositionXUpdate: IpcRendererEventListener<{ | ||
dragTabOffsetX: number; | ||
positionX: number; | ||
bvWebContentsId: number; | ||
}>; | ||
BrowserTabMouseup: IpcRendererEventListener; | ||
HotUpdateStatus: IpcRendererEventListener<{ | ||
status: string; | ||
message: string; | ||
}>; | ||
} |
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,24 @@ | ||
import { | ||
IpcChannelMainClass, | ||
IpcChannelRendererClass, | ||
IpcMainEventListener, | ||
IpcRendererEventListener, | ||
} from "./channel"; | ||
|
||
type GetChannelType< | ||
T extends IpcChannelMainClass | IpcChannelRendererClass, | ||
K extends keyof IpcMainEventListener | keyof IpcRendererEventListener | ||
> = { | ||
[Key in keyof T]: K extends keyof T[Key] ? T[Key][K] : never; | ||
}; | ||
|
||
export interface IIpcMainHandle | ||
extends GetChannelType<IpcChannelMainClass, "ipcMainHandle"> {} | ||
export interface IIpcRendererInvoke | ||
extends GetChannelType<IpcChannelMainClass, "ipcRendererInvoke"> {} | ||
export interface IIpcRendererOn | ||
extends GetChannelType<IpcChannelRendererClass, "ipcRendererOn"> {} | ||
export interface IWebContentSend | ||
extends GetChannelType<IpcChannelRendererClass, "webContentSend"> {} | ||
|
||
export * from "./channel"; |
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,76 +1,74 @@ | ||
import { autoUpdater } from 'electron-updater' | ||
import { BrowserWindow } from 'electron' | ||
import { autoUpdater } from "electron-updater"; | ||
import { BrowserWindow } from "electron"; | ||
import { webContentSend } from "./web-content-send"; | ||
/** | ||
* -1 检查更新失败 0 正在检查更新 1 检测到新版本,准备下载 2 未检测到新版本 3 下载中 4 下载完成 | ||
**/ | ||
class Update { | ||
public mainWindow: BrowserWindow | ||
public mainWindow: BrowserWindow; | ||
constructor() { | ||
// 设置url | ||
autoUpdater.setFeedURL('http://127.0.0.1:25565/') | ||
autoUpdater.setFeedURL("http://127.0.0.1:25565/"); | ||
|
||
// 当更新发生错误的时候触发。 | ||
autoUpdater.on('error', (err) => { | ||
console.log('更新出现错误', err.message) | ||
if (err.message.includes('sha512 checksum mismatch')) { | ||
this.Message(this.mainWindow, -1, 'sha512校验失败') | ||
autoUpdater.on("error", (err) => { | ||
console.log("更新出现错误", err.message); | ||
if (err.message.includes("sha512 checksum mismatch")) { | ||
this.Message(this.mainWindow, -1, "sha512校验失败"); | ||
} else { | ||
this.Message(this.mainWindow, -1, '错误信息请看主进程控制台') | ||
|
||
this.Message(this.mainWindow, -1, "错误信息请看主进程控制台"); | ||
} | ||
}) | ||
}); | ||
|
||
// 当开始检查更新的时候触发 | ||
autoUpdater.on('checking-for-update', () => { | ||
console.log('开始检查更新') | ||
this.Message(this.mainWindow, 0) | ||
}) | ||
autoUpdater.on("checking-for-update", () => { | ||
console.log("开始检查更新"); | ||
this.Message(this.mainWindow, 0); | ||
}); | ||
|
||
// 发现可更新数据时 | ||
autoUpdater.on('update-available', () => { | ||
console.log('有更新') | ||
this.Message(this.mainWindow, 1) | ||
}) | ||
autoUpdater.on("update-available", () => { | ||
console.log("有更新"); | ||
this.Message(this.mainWindow, 1); | ||
}); | ||
|
||
// 没有可更新数据时 | ||
autoUpdater.on('update-not-available', () => { | ||
console.log('没有更新') | ||
this.Message(this.mainWindow, 2) | ||
}) | ||
autoUpdater.on("update-not-available", () => { | ||
console.log("没有更新"); | ||
this.Message(this.mainWindow, 2); | ||
}); | ||
|
||
// 下载监听 | ||
autoUpdater.on('download-progress', (progressObj) => { | ||
this.Message(this.mainWindow, 3, `${progressObj}`) | ||
}) | ||
autoUpdater.on("download-progress", (progressObj) => { | ||
this.Message(this.mainWindow, 3, `${progressObj}`); | ||
}); | ||
|
||
// 下载完成 | ||
autoUpdater.on('update-downloaded', () => { | ||
console.log('下载完成') | ||
this.Message(this.mainWindow, 4) | ||
}) | ||
|
||
|
||
autoUpdater.on("update-downloaded", () => { | ||
console.log("下载完成"); | ||
this.Message(this.mainWindow, 4); | ||
}); | ||
} | ||
// 负责向渲染进程发送信息 | ||
Message(mainWindow: BrowserWindow, type: Number, data?: String) { | ||
Message(mainWindow: BrowserWindow, type: number, data?: string) { | ||
const senddata = { | ||
state: type, | ||
msg: data || '' | ||
} | ||
mainWindow.webContents.send('update-msg', senddata) | ||
msg: data || "", | ||
}; | ||
webContentSend(mainWindow.webContents, "UpdateMsg", senddata); | ||
} | ||
|
||
// 执行自动更新检查 | ||
checkUpdate(mainWindow: BrowserWindow) { | ||
this.mainWindow = mainWindow | ||
autoUpdater.checkForUpdates().catch(err => { | ||
console.log('网络连接问题', err) | ||
}) | ||
this.mainWindow = mainWindow; | ||
autoUpdater.checkForUpdates().catch((err) => { | ||
console.log("网络连接问题", err); | ||
}); | ||
} | ||
// 退出并安装 | ||
quitAndInstall() { | ||
autoUpdater.quitAndInstall() | ||
autoUpdater.quitAndInstall(); | ||
} | ||
} | ||
|
||
export default Update | ||
export default Update; |
Oops, something went wrong.