Skip to content

Commit

Permalink
[Electron] MacOs and MessageBox fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Scavanger committed Apr 26, 2024
1 parent a4fd2bc commit 2efebec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
9 changes: 9 additions & 0 deletions js/gui.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
const { dialog } = require("@electron/remote");


const CONFIGURATOR = require('./data_storage');
const Switchery = require('./libraries/switchery/switchery')
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 5 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function createDeviceChooser() {
}

app.on('ready', () => {
createWindow();
});

function createWindow() {

let mainWindowState = windowStateKeeper({
defaultWidth: 800,
Expand Down Expand Up @@ -147,7 +151,7 @@ app.on('ready', () => {
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
});
}

app.on('window-all-closed', () => {

Expand Down
34 changes: 17 additions & 17 deletions tabs/mission_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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'));
}
}
}
Expand All @@ -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()));
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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'))) {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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));
// }
// }

Expand Down
6 changes: 3 additions & 3 deletions tabs/sitl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit 2efebec

Please sign in to comment.