Skip to content

Commit

Permalink
Version 0.1.1
Browse files Browse the repository at this point in the history
- Commented console.log debug calls
- Ignoring prompt() function as it's not supported by Electron
- Other small fixes
  • Loading branch information
fabiofabbri84 committed Oct 1, 2024
1 parent a6d1d0c commit fbaac4f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
"comma-style": ["error", "last"],
"no-eval": ["error", {"allowIndirect": false}],
"no-redeclare": "off",
"no-console": "warn",
"no-console": "error",

"curly": "error",
"brace-style": ["error", "1tbs"],
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Cordova Electron dialogs fix
===

Electron has a bug (see https://github.com/electron/electron/issues/41603) that breaks focus when using alert(), confirm() or prompt() functions.
Electron has a known bug (see https://github.com/electron/electron/issues/31917 and https://github.com/electron/electron/issues/41603) that disrupts focus when using the `alert()` or `confirm()` functions.

This Cordova plugin fixes this by overriding these functions in order to call the main context methods blur() and focus() of the BrowserWindow after the dialogs are closed.
This Cordova plugin resolves the issue by overriding these functions and subsequently calling the `blur()` and `focus()` methods of the `BrowserWindow` in the main context once the dialogs are closed.

This plugin works out of the box and is compatible with other platforms (but it does nothing), just install it if you use native JavaScript dialogs in your Cordova Electron app, and you noticed focus issues.
This plugin works out of the box and is compatible with other platforms, though it does nothing on iOS or Android. Just install it if you use native JavaScript dialogs in your Cordova Electron app, and you noticed focus issues.

Installation
---
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cordova-electron-dialogs-fix",
"version": "0.1.0",
"description": "Fix focus issue when alert(), confirm() or prompt() are called in a Cordova Electron app",
"version": "0.1.1",
"description": "Fix focus issue when alert() or confirm() are called in a Cordova Electron app",
"cordova": {
"id": "cordova-electron-dialogs-fix",
"platforms": [
Expand All @@ -18,7 +18,6 @@
"cordova-electron",
"alert",
"confirm",
"prompt",
"focus",
"input"
],
Expand Down
24 changes: 17 additions & 7 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2024 Andrea Cimatti - https://www.cimatti.it
See a full copy of license in the root folder of the project
Copyright 2024 Andrea Cimatti - https://www.cimatti.it
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-electron-dialogs-fix"
version="1.0.0">
version="0.1.1">

<name>Cordova Electron dialogs fix</name>
<description>Fix focus issue when alert(), confirm() or prompt() are called in a Cordova Electron app</description>
<description>Fix focus issue when alert() or confirm() are called in a Cordova Electron app</description>
<author>Andrea Cimatti - https://www.cimatti.it</author>
<license>MIT</license>
<keywords>cordova,electron,alert,confirm,prompt,focus,input</keywords>
<license>Apache-2.0</license>
<keywords>cordova,electron,alert,confirm,focus,input</keywords>
<repo>https://github.com/cimatti/cordova-electron-dialogs-fix</repo>
<issue>https://github.com/cimatti/cordova-electron-dialogs-fix/issues</issue>

Expand Down
5 changes: 2 additions & 3 deletions src/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

const { BrowserWindow } = require('electron');
Expand All @@ -23,9 +22,9 @@ module.exports = {
if (w) {
w.blur();
w.focus();
console.log('refocused');
// console.log('refocused');
} else {
console.log("BrowserWindow.getFocusedWindow() returned null");
console.log("BrowserWindow.getFocusedWindow() returned null"); // eslint-disable-line no-console
}
}
}
10 changes: 5 additions & 5 deletions www/cordova-electron-dialogs-fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

{
// Store reference to original alert, confirm and prompt functions
const originals = {alert, confirm, prompt};
// Store reference to the original alert() and confirm()
// prompt() is not supported by Electron, so let's ignore it
const originals = {alert, confirm};

// Returns a function that calls the original function and then executes the refocus on the main process
const altFuncBuilder = function(fname){
const f = originals[fname]; //this is necessary, because if we call originals[fname](...args), the function will be called in "originals" context and not in "window" context
return function(...args) {
console.log(`alternative ${fname} called`);
// console.log(`alternative ${fname} called`);
const ret = f(...args);
console.log(ret);
// console.log(ret);
Cordova.exec(()=>{}, ()=>{}, "cordovaElectronDialogsFix", "refocus", []);
return ret;
}
Expand Down

0 comments on commit fbaac4f

Please sign in to comment.