Skip to content

Commit 8b285b5

Browse files
authored
Merge pull request #12 from Bolado/new-version-warning
Improvements surrounding version selection
2 parents e981159 + c33be89 commit 8b285b5

5 files changed

Lines changed: 225 additions & 130 deletions

File tree

‎libs/ipc-handlers.js‎

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,28 @@ module.exports = async function (deps) {
111111
url: url,
112112
responseType: 'arraybuffer',
113113
onDownloadProgress: (progressEvent) => {
114-
const totalLength = 126009591;
115-
const progress = (
116-
(progressEvent.loaded * 100) /
117-
totalLength
118-
).toFixed(2);
119-
let currentPercent = (10 + progress * 0.4).toFixed(2);
120-
event.sender.send('progress', {
121-
percent: currentPercent,
122-
status: `Downloading client ${version}... (${progress}%)`
123-
});
114+
if (progressEvent.total) {
115+
const progress = (
116+
(progressEvent.loaded * 100) /
117+
progressEvent.total
118+
).toFixed(2);
119+
// Scale from 10% to 90% for download progress
120+
let currentPercent = (10 + progress * 0.8).toFixed(2);
121+
event.sender.send('progress', {
122+
percent: currentPercent,
123+
status: `Downloading client ${version}... (${progress}%)`
124+
});
125+
} else {
126+
// Fallback
127+
const downloadedMB = (
128+
progressEvent.loaded /
129+
(1024 * 1024)
130+
).toFixed(1);
131+
event.sender.send('progress', {
132+
percent: 50,
133+
status: `Downloading client ${version}... (${downloadedMB}MB)`
134+
});
135+
}
124136
}
125137
});
126138
const filePath = path.join(microbotDir, `microbot-${version}.jar`);
@@ -269,4 +281,40 @@ module.exports = async function (deps) {
269281
return { error: error.message };
270282
}
271283
});
284+
285+
/**
286+
* Show a confirmation dialog with the given message and options
287+
* @param {string} message - The message to display in the dialog
288+
* @param {string} [defaultTitle="Confirm"] - The title of the dialog
289+
* @param {string} [yesButton="Yes"] - The text for the "Yes" button
290+
* @param {string} [noButton="No"] - The text for the "No" button
291+
*/
292+
ipcMain.handle(
293+
'show-confirmation-dialog',
294+
async (
295+
event,
296+
message,
297+
detail,
298+
defaultTitle = 'Confirm',
299+
yesButton = '&Yes',
300+
noButton = '&No'
301+
) => {
302+
try {
303+
const result = await dialog.showMessageBox({
304+
type: 'warning',
305+
title: defaultTitle,
306+
message: message,
307+
detail: detail,
308+
buttons: ['&' + yesButton, '&' + noButton],
309+
defaultId: 1,
310+
cancelId: 1,
311+
noLink: false
312+
});
313+
return result.response === 0; // Return true if 'Yes' is clicked
314+
} catch (error) {
315+
log.error(`Error showing confirmation dialog: ${error}`);
316+
return { error: error.message };
317+
}
318+
}
319+
);
272320
};

‎main.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async function createWindow() {
176176
.children('script')
177177
.last()
178178
.replaceWith(
179-
'<script src="https://files.microbot.cloud/assets/microbot-launcher/renderer.js?version=3.0.0"></script>'
179+
'<script src="https://files.microbot.cloud/assets/microbot-launcher/renderer.js?version=3.1.2"></script>'
180180
);
181181
$('head')
182182
.children('link[rel="stylesheet"]')

‎package.json‎

Lines changed: 87 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,95 @@
11
{
2-
"name": "microbot-launcher",
3-
"version": "3.1.3",
4-
"description": "Launcher for the microbot client",
5-
"main": "main.js",
6-
"scripts": {
7-
"dev": "cross-env DEBUG=true electron .",
8-
"start": "electron-forge start",
9-
"test": "echo \"Error: no test specified\" && exit 1",
10-
"release": "electron-builder --publish always",
11-
"linux": "electron-builder --linux",
12-
"mac": "electron-builder --mac"
2+
"name": "microbot-launcher",
3+
"version": "3.1.4",
4+
"description": "Launcher for the microbot client",
5+
"main": "main.js",
6+
"scripts": {
7+
"dev": "cross-env DEBUG=true electron .",
8+
"start": "electron-forge start",
9+
"test": "echo \"Error: no test specified\" && exit 1",
10+
"release": "electron-builder --publish always",
11+
"linux": "electron-builder --linux",
12+
"mac": "electron-builder --mac"
13+
},
14+
"author": "Mocrosoft",
15+
"license": "ISC",
16+
"devDependencies": {
17+
"@electron-forge/cli": "^7.8.1",
18+
"@electron-forge/maker-deb": "^7.8.1",
19+
"@electron-forge/maker-rpm": "^7.8.1",
20+
"@electron-forge/maker-squirrel": "^7.8.1",
21+
"@electron-forge/maker-zip": "^7.8.1",
22+
"@electron-forge/plugin-auto-unpack-natives": "^7.8.1",
23+
"@electron-forge/plugin-fuses": "^7.8.1",
24+
"@electron/fuses": "^1.8.0",
25+
"cross-env": "^7.0.3",
26+
"electron": "^33.2.0",
27+
"electron-builder": "^26.0.12"
28+
},
29+
"dependencies": {
30+
"adm-zip": "^0.5.15",
31+
"applicationinsights": "^2.9.6",
32+
"axios": "^1.7.2",
33+
"cheerio": "1.1.2",
34+
"detect-browsers": "^6.1.0",
35+
"electron-log": "^5.4.1",
36+
"electron-updater": "^6.1.8",
37+
"patchright": "^1.52.5",
38+
"playwright": "^1.54.1",
39+
"update-electron-app": "^3.0.0"
40+
},
41+
"build": {
42+
"asar": "true",
43+
"appId": "com.microbot.launcher",
44+
"productName": "Microbot Launcher",
45+
"files": [
46+
"main.js",
47+
"renderer.js",
48+
"preload.js",
49+
"package.json",
50+
"!**/*.map",
51+
"images/**",
52+
"libs/**",
53+
"index.html",
54+
"css/**",
55+
"build/READ THIS BEFORE INSTALL.html"
56+
],
57+
"directories": {
58+
"buildResources": "build"
1359
},
14-
"author": "Mocrosoft",
15-
"license": "ISC",
16-
"devDependencies": {
17-
"@electron-forge/cli": "^7.8.1",
18-
"@electron-forge/maker-deb": "^7.8.1",
19-
"@electron-forge/maker-rpm": "^7.8.1",
20-
"@electron-forge/maker-squirrel": "^7.8.1",
21-
"@electron-forge/maker-zip": "^7.8.1",
22-
"@electron-forge/plugin-auto-unpack-natives": "^7.8.1",
23-
"@electron-forge/plugin-fuses": "^7.8.1",
24-
"@electron/fuses": "^1.8.0",
25-
"cross-env": "^7.0.3",
26-
"electron": "^33.2.0",
27-
"electron-builder": "^26.0.12"
60+
"win": {
61+
"target": "nsis",
62+
"icon": "images/microbot_transparent.ico"
2863
},
29-
"dependencies": {
30-
"adm-zip": "^0.5.15",
31-
"applicationinsights": "^2.9.6",
32-
"axios": "^1.7.2",
33-
"cheerio": "1.1.2",
34-
"detect-browsers": "^6.1.0",
35-
"electron-log": "^5.4.1",
36-
"electron-updater": "^6.1.8",
37-
"patchright": "^1.52.5",
38-
"playwright": "^1.54.1",
39-
"update-electron-app": "^3.0.0"
64+
"mac": {
65+
"category": "public.app-category.utilities",
66+
"target": "default",
67+
"icon": "images/microbot_transparent.icns"
4068
},
41-
"build": {
42-
"asar": "true",
43-
"appId": "com.microbot.launcher",
44-
"productName": "Microbot Launcher",
45-
"files": [
46-
"main.js",
47-
"renderer.js",
48-
"preload.js",
49-
"package.json",
50-
"!**/*.map",
51-
"images/**",
52-
"libs/**",
53-
"index.html",
54-
"css/**",
55-
"build/READ THIS BEFORE INSTALL.html"
56-
],
57-
"directories": {
58-
"buildResources": "build"
69+
"dmg": {
70+
"icon": "images/microbot_transparent.icns",
71+
"background": "images/dmg-background.png",
72+
"title": "${productName} Installer",
73+
"iconSize": 108,
74+
"contents": [
75+
{
76+
"x": 530,
77+
"y": 192,
78+
"type": "file",
79+
"path": "./build/READ THIS BEFORE INSTALL.html"
5980
},
60-
"win": {
61-
"target": "nsis",
62-
"icon": "images/microbot_transparent.ico"
81+
{
82+
"x": 200,
83+
"y": 400,
84+
"type": "file"
6385
},
64-
"mac": {
65-
"category": "public.app-category.utilities",
66-
"target": "default",
67-
"icon": "images/microbot_transparent.icns"
68-
},
69-
"dmg": {
70-
"icon": "images/microbot_transparent.icns",
71-
"background": "images/dmg-background.png",
72-
"title": "${productName} Installer",
73-
"iconSize": 108,
74-
"contents": [
75-
{
76-
"x": 530,
77-
"y": 192,
78-
"type": "file",
79-
"path": "./build/READ THIS BEFORE INSTALL.html"
80-
},
81-
{
82-
"x": 200,
83-
"y": 400,
84-
"type": "file"
85-
},
86-
{
87-
"x": 730,
88-
"y": 495,
89-
"type": "link",
90-
"path": "/Applications"
91-
}
92-
]
93-
},
94-
"linux": {
95-
"target": [
96-
{
97-
"target": "AppImage",
98-
"arch": [
99-
"x64"
100-
]
101-
}
102-
],
103-
"icon": "images/microbot_transparent.png",
104-
"category": "Game"
105-
},
106-
"nsis": {
107-
"oneClick": false,
108-
"allowToChangeInstallationDirectory": true,
109-
"createDesktopShortcut": true,
110-
"createStartMenuShortcut": true,
111-
"shortcutName": "Microbot Launcher"
112-
},
113-
"publish": {
114-
"provider": "generic",
115-
"url": "https://files.microbot.cloud/releases/microbot-launcher/"
116-
},
117-
"extraMetadata": {
118-
"version": "3.1.2"
86+
{
87+
"x": 730,
88+
"y": 495,
89+
"type": "link",
90+
"path": "/"
11991
}
92+
]
12093
},
12194
"linux": {
12295
"target": [
@@ -138,6 +111,7 @@
138111
"url": "https://files.microbot.cloud/releases/microbot-launcher/"
139112
},
140113
"optionalDependencies": {
141-
"fsevents": "^2.3.2"
114+
"fsevents": "^2.3.2"
142115
}
116+
}
143117
}

‎preload.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ contextBridge.exposeInMainWorld('electron', {
3737
launcherVersion: () => ipcRenderer.invoke('launcher-version'),
3838
logError: (message) => ipcRenderer.invoke('log-error', message),
3939
errorAlert: (options) => ipcRenderer.invoke('error-alert', options),
40+
showConfirmationDialog: (message, detail, title, yesButton, noButton) =>
41+
ipcRenderer.invoke(
42+
'show-confirmation-dialog',
43+
message,
44+
detail,
45+
title,
46+
yesButton,
47+
noButton
48+
),
4049
ipcRenderer: {
4150
send: (channel, data) => ipcRenderer.send(channel, data),
4251
receive: (channel, func) =>

0 commit comments

Comments
 (0)