From 2efebecb61c8379cd74cc63f1b2e308453d9855b Mon Sep 17 00:00:00 2001 From: Scavanger Date: Fri, 26 Apr 2024 08:52:52 -0300 Subject: [PATCH] [Electron] MacOs and MessageBox fix MacOS: - Nice icon for DMG - Fix bug when Configurator was minimized and dock icon is clicked Fix (Workaround): After a MessageBox (alert()) was displayed, all input fields stopped working. --- forge.config.js | 3 ++- js/gui.js | 9 +++++++++ js/main.js | 6 +++++- tabs/mission_control.js | 34 +++++++++++++++++----------------- tabs/sitl.js | 6 +++--- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/forge.config.js b/forge.config.js index 092043be..223287f5 100644 --- a/forge.config.js +++ b/forge.config.js @@ -74,7 +74,8 @@ module.exports = { name: '@electron-forge/maker-dmg', config: { name: "INAV Configurator", - background: "./assets/osx/dmg-background.png" + background: "./assets/osx/dmg-background.png", + icon: "./images/inav.icns" } }, { diff --git a/js/gui.js b/js/gui.js index b388a9c3..3d48048c 100644 --- a/js/gui.js +++ b/js/gui.js @@ -1,4 +1,6 @@ 'use strict'; +const { dialog } = require("@electron/remote"); + const CONFIGURATOR = require('./data_storage'); const Switchery = require('./libraries/switchery/switchery') @@ -529,6 +531,13 @@ GUI_control.prototype.update_dataflash_global = function () { } }; +/** +* Don't use alert() in Electron, it has a nasty bug: https://github.com/electron/electron/issues/31917 +*/ +GUI_control.prototype.alert = function(message) { + dialog.showMessageBoxSync({ message: message, icon: "./images/inav_icon_128.png" }); +} + // initialize object into GUI variable var GUI = new GUI_control(); diff --git a/js/main.js b/js/main.js index e3a6b232..df9f05c0 100644 --- a/js/main.js +++ b/js/main.js @@ -53,6 +53,10 @@ function createDeviceChooser() { } app.on('ready', () => { + createWindow(); +}); + +function createWindow() { let mainWindowState = windowStateKeeper({ defaultWidth: 800, @@ -147,7 +151,7 @@ app.on('ready', () => { if (process.env.NODE_ENV === 'development') { mainWindow.webContents.openDevTools(); } -}); +} app.on('window-all-closed', () => { diff --git a/tabs/mission_control.js b/tabs/mission_control.js index d07ecd57..65aec177 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -483,7 +483,7 @@ TABS.mission_control.initialize = function (callback) { function checkApproachAltitude(altitude, isSeaLevelRef, sealevel) { if (altitude - (isSeaLevelRef ? sealevel * 100 : 0 ) < 0) { - alert(i18n.getMessage('MissionPlannerAltitudeChangeReset')); + GUI.alert(i18n.getMessage('MissionPlannerAltitudeChangeReset')); return false; } @@ -493,7 +493,7 @@ TABS.mission_control.initialize = function (callback) { function checkLandingAltitude(altitude, isSeaLevelRef, sealevel) { if (altitude - (isSeaLevelRef ? sealevel * 100 : 0 ) < MAX_NEG_FW_LAND_ALT) { - alert(i18n.getMessage('MissionPlannerFwLAndingAltitudeChangeReset')); + GUI.alert(i18n.getMessage('MissionPlannerFwLAndingAltitudeChangeReset')); return false; } @@ -1489,26 +1489,26 @@ TABS.mission_control.initialize = function (callback) { if ($(this).val() >= 360 || ($(this).val() < 0 && $(this).val() != -1)) { $(this).val(-1); - alert(i18n.getMessage('MissionPlannerHeadSettingsCheck')); + GUI.alert(i18n.getMessage('MissionPlannerHeadSettingsCheck')); } } else if (MWNP.WPTYPE.REV[element.getAction()] == "RTH") { if ($(this).val() != 0 && $(this).val() != 1) { $(this).val(0); - alert(i18n.getMessage('MissionPlannerRTHSettingsCheck')); + GUI.alert(i18n.getMessage('MissionPlannerRTHSettingsCheck')); } } else if (MWNP.WPTYPE.REV[element.getAction()] == "JUMP") { if ($(this).val() > mission.getNonAttachedList().length || $(this).val() < 1) { $(this).val(1); - alert(i18n.getMessage('MissionPlannerJumpSettingsCheck')); + GUI.alert(i18n.getMessage('MissionPlannerJumpSettingsCheck')); } else if (mission.getPoiList().length != 0 && mission.getPoiList()) { if (mission.getPoiList().includes(mission.convertJumpNumberToWaypoint(Number($(this).val())-1))) { $(this).val(1); - alert(i18n.getMessage('MissionPlannerJump3SettingsCheck')); + GUI.alert(i18n.getMessage('MissionPlannerJump3SettingsCheck')); } } } @@ -1523,7 +1523,7 @@ TABS.mission_control.initialize = function (callback) { if ($(this).val() > 10 || ($(this).val() < 0 && $(this).val() != -1)) { $(this).val(0); - alert(i18n.getMessage('MissionPlannerJump2SettingsCheck')); + GUI.alert(i18n.getMessage('MissionPlannerJump2SettingsCheck')); } } element.setP2(Number($(this).val())); @@ -2310,7 +2310,7 @@ TABS.mission_control.initialize = function (callback) { let found = false; mission.get().forEach(wp => { if (wp.getAction() == MWNP.WPTYPE.LAND) { - alert(i18n.getMessage('MissionPlannerOnlyOneLandWp')); + GUI.alert(i18n.getMessage('MissionPlannerOnlyOneLandWp')); found = true; $(event.currentTarget).val(selectedMarker.getAction()); } @@ -2684,7 +2684,7 @@ TABS.mission_control.initialize = function (callback) { $('#addSafehome').on('click', () => { if (FC.SAFEHOMES.safehomeCount() + 1 > FC.SAFEHOMES.getMaxSafehomeCount()){ - alert(i18n.getMessage('missionSafehomeMaxSafehomesReached')); + GUI.alert(i18n.getMessage('missionSafehomeMaxSafehomesReached')); return; } @@ -3016,7 +3016,7 @@ TABS.mission_control.initialize = function (callback) { $('#removePoint').on('click', function () { if (selectedMarker) { if (mission.isJumpTargetAttached(selectedMarker)) { - alert(i18n.getMessage('MissionPlannerJumpTargetRemoval')); + GUI.alert(i18n.getMessage('MissionPlannerJumpTargetRemoval')); } else if (mission.getAttachedFromWaypoint(selectedMarker) && mission.getAttachedFromWaypoint(selectedMarker).length != 0) { if (confirm(i18n.getMessage('confirm_delete_point_with_options'))) { @@ -3096,7 +3096,7 @@ TABS.mission_control.initialize = function (callback) { $('#saveMissionButton').on('click', function () { if (mission.isEmpty()) { - alert(i18n.getMessage('no_waypoints_to_save')); + GUI.alert(i18n.getMessage('no_waypoints_to_save')); return; } $(this).addClass('disabled'); @@ -3115,7 +3115,7 @@ TABS.mission_control.initialize = function (callback) { $('#saveEepromMissionButton').on('click', function () { if (mission.isEmpty()) { - alert(i18n.getMessage('no_waypoints_to_save')); + GUI.alert(i18n.getMessage('no_waypoints_to_save')); return; } $(this).addClass('disabled'); @@ -3445,7 +3445,7 @@ TABS.mission_control.initialize = function (callback) { $('#loadMissionButton').removeClass('disabled'); } if (!FC.MISSION_PLANNER.getCountBusyPoints()) { - alert(i18n.getMessage('no_waypoints_to_load')); + GUI.alert(i18n.getMessage('no_waypoints_to_load')); return; } mission.reinit(); @@ -3555,7 +3555,7 @@ TABS.mission_control.initialize = function (callback) { if (AbsAltCheck) { if (checkAltitude < 100 * elevation) { if (resetAltitude) { - alert(i18n.getMessage('MissionPlannerAltitudeChangeReset')); + GUI.alert(i18n.getMessage('MissionPlannerAltitudeChangeReset')); altitude = selectedMarker.getAlt(); } else { altitude = settings.alt + 100 * elevation; @@ -3566,7 +3566,7 @@ TABS.mission_control.initialize = function (callback) { let elevationAtHome = HOME.getAlt(); if ((checkAltitude / 100 + elevationAtHome) < elevation) { if (resetAltitude) { - alert(i18n.getMessage('MissionPlannerAltitudeChangeReset')); + GUI.alert(i18n.getMessage('MissionPlannerAltitudeChangeReset')); altitude = selectedMarker.getAlt(); } else { let currentGroundClearance = 100 * Number($('#groundClearanceValueAtWP').text()); @@ -3702,9 +3702,9 @@ TABS.mission_control.setBit = function(bits, bit, value) { // function handleError(evt) { // if (evt.message) { // Chrome sometimes provides this - // alert("error: "+evt.message +" at linenumber: "+evt.lineno+" of file: "+evt.filename); + // GUI.alert("error: "+evt.message +" at linenumber: "+evt.lineno+" of file: "+evt.filename); // } else { - // alert("error: "+evt.type+" from element: "+(evt.srcElement || evt.target)); + // GUI.alert("error: "+evt.type+" from element: "+(evt.srcElement || evt.target)); // } // } diff --git a/tabs/sitl.js b/tabs/sitl.js index 81ef58b7..d967f714 100644 --- a/tabs/sitl.js +++ b/tabs/sitl.js @@ -253,7 +253,7 @@ TABS.sitl.initialize = (callback) => { return; if (profiles.find(e => { return e.name == name })) { - alert(i18n.getMessage('sitlProfileExists')) + GUI.alert(i18n.getMessage('sitlProfileExists')) return; } var eerpromName = name.replace(/[^a-z0-9]/gi, '_').toLowerCase() + ".bin"; @@ -284,7 +284,7 @@ TABS.sitl.initialize = (callback) => { profileDeleteBtn_e.on('click', function () { if (currentProfile.isStdProfile) { - alert(i18n.getMessage('sitlStdProfileCantDeleted')); + GUI.alert(i18n.getMessage('sitlStdProfileCantDeleted')); return; } @@ -385,7 +385,7 @@ TABS.sitl.initialize = (callback) => { function saveProfiles() { if (currentProfile.isStdProfile) { - alert(i18n.getMessage('sitlStdProfileCantOverwritten')); + GUI.alert(i18n.getMessage('sitlStdProfileCantOverwritten')); return; } var profilesToSave = [];