|
1 | | -import { Socket } from 'net'; |
2 | | -import { autoUpdater } from 'electron-updater'; |
3 | | -let electronSocket; |
| 1 | +import type { Socket } from "net"; |
| 2 | +import { autoUpdater } from "electron-updater"; |
4 | 3 |
|
5 | | -export = (socket: Socket) => { |
6 | | - electronSocket = socket; |
7 | | - |
8 | | - socket.on('register-autoUpdater-error', (id) => { |
9 | | - autoUpdater.on('error', (error) => { |
10 | | - electronSocket.emit('autoUpdater-error' + id, error.message); |
11 | | - }); |
12 | | - }); |
13 | | - |
14 | | - socket.on('register-autoUpdater-checking-for-update', (id) => { |
15 | | - autoUpdater.on('checking-for-update', () => { |
16 | | - electronSocket.emit('autoUpdater-checking-for-update' + id); |
17 | | - }); |
18 | | - }); |
19 | | - |
20 | | - socket.on('register-autoUpdater-update-available', (id) => { |
21 | | - autoUpdater.on('update-available', (updateInfo) => { |
22 | | - electronSocket.emit('autoUpdater-update-available' + id, updateInfo); |
23 | | - }); |
24 | | - }); |
25 | | - |
26 | | - socket.on('register-autoUpdater-update-not-available', (id) => { |
27 | | - autoUpdater.on('update-not-available', (updateInfo) => { |
28 | | - electronSocket.emit('autoUpdater-update-not-available' + id, updateInfo); |
29 | | - }); |
30 | | - }); |
31 | | - |
32 | | - socket.on('register-autoUpdater-download-progress', (id) => { |
33 | | - autoUpdater.on('download-progress', (progressInfo) => { |
34 | | - electronSocket.emit('autoUpdater-download-progress' + id, progressInfo); |
35 | | - }); |
36 | | - }); |
37 | | - |
38 | | - socket.on('register-autoUpdater-update-downloaded', (id) => { |
39 | | - autoUpdater.on('update-downloaded', (updateInfo) => { |
40 | | - electronSocket.emit('autoUpdater-update-downloaded' + id, updateInfo); |
41 | | - }); |
42 | | - }); |
43 | | - |
44 | | - // Properties ***** |
45 | | - |
46 | | - socket.on('autoUpdater-autoDownload', () => { |
47 | | - electronSocket.emit('autoUpdater-autoDownload-completed', autoUpdater.autoDownload); |
48 | | - }); |
49 | | - |
50 | | - socket.on('autoUpdater-autoDownload-set', (value) => { |
51 | | - autoUpdater.autoDownload = value; |
52 | | - }); |
53 | | - |
54 | | - socket.on('autoUpdater-autoInstallOnAppQuit', () => { |
55 | | - electronSocket.emit('autoUpdater-autoInstallOnAppQuit-completed', autoUpdater.autoInstallOnAppQuit); |
56 | | - }); |
57 | | - |
58 | | - socket.on('autoUpdater-autoInstallOnAppQuit-set', (value) => { |
59 | | - autoUpdater.autoInstallOnAppQuit = value; |
60 | | - }); |
61 | | - |
62 | | - socket.on('autoUpdater-allowPrerelease', () => { |
63 | | - electronSocket.emit('autoUpdater-allowPrerelease-completed', autoUpdater.allowPrerelease); |
64 | | - }); |
65 | | - |
66 | | - socket.on('autoUpdater-allowPrerelease-set', (value) => { |
67 | | - autoUpdater.allowPrerelease = value; |
68 | | - }); |
69 | | - |
70 | | - socket.on('autoUpdater-fullChangelog', () => { |
71 | | - electronSocket.emit('autoUpdater-fullChangelog-completed', autoUpdater.fullChangelog); |
72 | | - }); |
| 4 | +let electronSocket: Socket; |
73 | 5 |
|
74 | | - socket.on('autoUpdater-fullChangelog-set', (value) => { |
75 | | - autoUpdater.fullChangelog = value; |
76 | | - }); |
77 | | - |
78 | | - socket.on('autoUpdater-allowDowngrade', () => { |
79 | | - electronSocket.emit('autoUpdater-allowDowngrade-completed', autoUpdater.allowDowngrade); |
80 | | - }); |
81 | | - |
82 | | - socket.on('autoUpdater-allowDowngrade-set', (value) => { |
83 | | - autoUpdater.allowDowngrade = value; |
84 | | - }); |
85 | | - |
86 | | - socket.on('autoUpdater-updateConfigPath', () => { |
87 | | - electronSocket.emit('autoUpdater-updateConfigPath-completed', autoUpdater.updateConfigPath || ''); |
88 | | - }); |
89 | | - |
90 | | - socket.on('autoUpdater-updateConfigPath-set', (value) => { |
91 | | - autoUpdater.updateConfigPath = value; |
92 | | - }); |
93 | | - |
94 | | - socket.on('autoUpdater-currentVersion', () => { |
95 | | - electronSocket.emit('autoUpdater-currentVersion-completed', autoUpdater.currentVersion); |
96 | | - }); |
97 | | - |
98 | | - socket.on('autoUpdater-channel', () => { |
99 | | - electronSocket.emit('autoUpdater-channel-completed', autoUpdater.channel || ''); |
100 | | - }); |
101 | | - |
102 | | - socket.on('autoUpdater-channel-set', (value) => { |
103 | | - autoUpdater.channel = value; |
104 | | - }); |
105 | | - |
106 | | - socket.on('autoUpdater-requestHeaders', () => { |
107 | | - electronSocket.emit('autoUpdater-requestHeaders-completed', autoUpdater.requestHeaders); |
108 | | - }); |
109 | | - |
110 | | - socket.on('autoUpdater-requestHeaders-set', (value) => { |
111 | | - autoUpdater.requestHeaders = value; |
112 | | - }); |
113 | | - |
114 | | - socket.on('autoUpdater-checkForUpdatesAndNotify', async (guid) => { |
115 | | - autoUpdater.checkForUpdatesAndNotify().then((updateCheckResult) => { |
116 | | - electronSocket.emit('autoUpdater-checkForUpdatesAndNotify-completed' + guid, updateCheckResult); |
117 | | - }).catch((error) => { |
118 | | - electronSocket.emit('autoUpdater-checkForUpdatesAndNotifyError' + guid, error); |
119 | | - }); |
120 | | - }); |
121 | | - |
122 | | - socket.on('autoUpdater-checkForUpdates', async (guid) => { |
123 | | - autoUpdater.checkForUpdates().then((updateCheckResult) => { |
124 | | - electronSocket.emit('autoUpdater-checkForUpdates-completed' + guid, updateCheckResult); |
125 | | - }).catch((error) => { |
126 | | - electronSocket.emit('autoUpdater-checkForUpdatesError' + guid, error); |
127 | | - }); |
128 | | - }); |
129 | | - |
130 | | - socket.on('autoUpdater-quitAndInstall', async (isSilent, isForceRunAfter) => { |
131 | | - autoUpdater.quitAndInstall(isSilent, isForceRunAfter); |
132 | | - }); |
133 | | - |
134 | | - socket.on('autoUpdater-downloadUpdate', async (guid) => { |
135 | | - const downloadedPath = await autoUpdater.downloadUpdate(); |
136 | | - electronSocket.emit('autoUpdater-downloadUpdate-completed' + guid, downloadedPath); |
137 | | - }); |
| 6 | +export = (socket: Socket) => { |
| 7 | + electronSocket = socket; |
138 | 8 |
|
139 | | - socket.on('autoUpdater-getFeedURL', async (guid) => { |
140 | | - const feedUrl = await autoUpdater.getFeedURL(); |
141 | | - electronSocket.emit('autoUpdater-getFeedURL-completed' + guid, feedUrl || ''); |
| 9 | + socket.on("register-autoUpdater-error", (id) => { |
| 10 | + autoUpdater.on("error", (error) => { |
| 11 | + electronSocket.emit("autoUpdater-error" + id, error.message); |
142 | 12 | }); |
| 13 | + }); |
| 14 | + |
| 15 | + socket.on("register-autoUpdater-checking-for-update", (id) => { |
| 16 | + autoUpdater.on("checking-for-update", () => { |
| 17 | + electronSocket.emit("autoUpdater-checking-for-update" + id); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + socket.on("register-autoUpdater-update-available", (id) => { |
| 22 | + autoUpdater.on("update-available", (updateInfo) => { |
| 23 | + electronSocket.emit("autoUpdater-update-available" + id, updateInfo); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + socket.on("register-autoUpdater-update-not-available", (id) => { |
| 28 | + autoUpdater.on("update-not-available", (updateInfo) => { |
| 29 | + electronSocket.emit("autoUpdater-update-not-available" + id, updateInfo); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + socket.on("register-autoUpdater-download-progress", (id) => { |
| 34 | + autoUpdater.on("download-progress", (progressInfo) => { |
| 35 | + electronSocket.emit("autoUpdater-download-progress" + id, progressInfo); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + socket.on("register-autoUpdater-update-downloaded", (id) => { |
| 40 | + autoUpdater.on("update-downloaded", (updateInfo) => { |
| 41 | + electronSocket.emit("autoUpdater-update-downloaded" + id, updateInfo); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + // Properties ***** |
| 46 | + |
| 47 | + socket.on("autoUpdater-autoDownload", () => { |
| 48 | + electronSocket.emit( |
| 49 | + "autoUpdater-autoDownload-completed", |
| 50 | + autoUpdater.autoDownload, |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + socket.on("autoUpdater-autoDownload-set", (value) => { |
| 55 | + autoUpdater.autoDownload = value; |
| 56 | + }); |
| 57 | + |
| 58 | + socket.on("autoUpdater-autoInstallOnAppQuit", () => { |
| 59 | + electronSocket.emit( |
| 60 | + "autoUpdater-autoInstallOnAppQuit-completed", |
| 61 | + autoUpdater.autoInstallOnAppQuit, |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + socket.on("autoUpdater-autoInstallOnAppQuit-set", (value) => { |
| 66 | + autoUpdater.autoInstallOnAppQuit = value; |
| 67 | + }); |
| 68 | + |
| 69 | + socket.on("autoUpdater-allowPrerelease", () => { |
| 70 | + electronSocket.emit( |
| 71 | + "autoUpdater-allowPrerelease-completed", |
| 72 | + autoUpdater.allowPrerelease, |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + socket.on("autoUpdater-allowPrerelease-set", (value) => { |
| 77 | + autoUpdater.allowPrerelease = value; |
| 78 | + }); |
| 79 | + |
| 80 | + socket.on("autoUpdater-fullChangelog", () => { |
| 81 | + electronSocket.emit( |
| 82 | + "autoUpdater-fullChangelog-completed", |
| 83 | + autoUpdater.fullChangelog, |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + socket.on("autoUpdater-fullChangelog-set", (value) => { |
| 88 | + autoUpdater.fullChangelog = value; |
| 89 | + }); |
| 90 | + |
| 91 | + socket.on("autoUpdater-allowDowngrade", () => { |
| 92 | + electronSocket.emit( |
| 93 | + "autoUpdater-allowDowngrade-completed", |
| 94 | + autoUpdater.allowDowngrade, |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + socket.on("autoUpdater-allowDowngrade-set", (value) => { |
| 99 | + autoUpdater.allowDowngrade = value; |
| 100 | + }); |
| 101 | + |
| 102 | + socket.on("autoUpdater-updateConfigPath", () => { |
| 103 | + electronSocket.emit( |
| 104 | + "autoUpdater-updateConfigPath-completed", |
| 105 | + autoUpdater.updateConfigPath || "", |
| 106 | + ); |
| 107 | + }); |
| 108 | + |
| 109 | + socket.on("autoUpdater-updateConfigPath-set", (value) => { |
| 110 | + autoUpdater.updateConfigPath = value; |
| 111 | + }); |
| 112 | + |
| 113 | + socket.on("autoUpdater-currentVersion", () => { |
| 114 | + electronSocket.emit( |
| 115 | + "autoUpdater-currentVersion-completed", |
| 116 | + autoUpdater.currentVersion, |
| 117 | + ); |
| 118 | + }); |
| 119 | + |
| 120 | + socket.on("autoUpdater-channel", () => { |
| 121 | + electronSocket.emit( |
| 122 | + "autoUpdater-channel-completed", |
| 123 | + autoUpdater.channel || "", |
| 124 | + ); |
| 125 | + }); |
| 126 | + |
| 127 | + socket.on("autoUpdater-channel-set", (value) => { |
| 128 | + autoUpdater.channel = value; |
| 129 | + }); |
| 130 | + |
| 131 | + socket.on("autoUpdater-requestHeaders", () => { |
| 132 | + electronSocket.emit( |
| 133 | + "autoUpdater-requestHeaders-completed", |
| 134 | + autoUpdater.requestHeaders, |
| 135 | + ); |
| 136 | + }); |
| 137 | + |
| 138 | + socket.on("autoUpdater-requestHeaders-set", (value) => { |
| 139 | + autoUpdater.requestHeaders = value; |
| 140 | + }); |
| 141 | + |
| 142 | + socket.on("autoUpdater-checkForUpdatesAndNotify", async (guid) => { |
| 143 | + autoUpdater |
| 144 | + .checkForUpdatesAndNotify() |
| 145 | + .then((updateCheckResult) => { |
| 146 | + electronSocket.emit( |
| 147 | + "autoUpdater-checkForUpdatesAndNotify-completed" + guid, |
| 148 | + updateCheckResult, |
| 149 | + ); |
| 150 | + }) |
| 151 | + .catch((error) => { |
| 152 | + electronSocket.emit( |
| 153 | + "autoUpdater-checkForUpdatesAndNotifyError" + guid, |
| 154 | + error, |
| 155 | + ); |
| 156 | + }); |
| 157 | + }); |
| 158 | + |
| 159 | + socket.on("autoUpdater-checkForUpdates", async (guid) => { |
| 160 | + autoUpdater |
| 161 | + .checkForUpdates() |
| 162 | + .then((updateCheckResult) => { |
| 163 | + electronSocket.emit( |
| 164 | + "autoUpdater-checkForUpdates-completed" + guid, |
| 165 | + updateCheckResult, |
| 166 | + ); |
| 167 | + }) |
| 168 | + .catch((error) => { |
| 169 | + electronSocket.emit("autoUpdater-checkForUpdatesError" + guid, error); |
| 170 | + }); |
| 171 | + }); |
| 172 | + |
| 173 | + socket.on("autoUpdater-quitAndInstall", async (isSilent, isForceRunAfter) => { |
| 174 | + autoUpdater.quitAndInstall(isSilent, isForceRunAfter); |
| 175 | + }); |
| 176 | + |
| 177 | + socket.on("autoUpdater-downloadUpdate", async (guid) => { |
| 178 | + const downloadedPath = await autoUpdater.downloadUpdate(); |
| 179 | + electronSocket.emit( |
| 180 | + "autoUpdater-downloadUpdate-completed" + guid, |
| 181 | + downloadedPath, |
| 182 | + ); |
| 183 | + }); |
| 184 | + |
| 185 | + socket.on("autoUpdater-getFeedURL", async (guid) => { |
| 186 | + const feedUrl = await autoUpdater.getFeedURL(); |
| 187 | + electronSocket.emit( |
| 188 | + "autoUpdater-getFeedURL-completed" + guid, |
| 189 | + feedUrl || "", |
| 190 | + ); |
| 191 | + }); |
143 | 192 | }; |
0 commit comments