mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-06 01:20:41 +00:00
fix: requestPermission Promise never settled
This bug took a long time to diagnose, so I also made an async/await wrapper around #postMessageWithCallback called #postMessageAsync so that similar promise resolving errors are less likely here in the future.
This commit is contained in:
+13
-12
@@ -17,23 +17,23 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import UIAlert from './UI/UIAlert.js';
|
||||
import UIWindow from './UI/UIWindow.js';
|
||||
import UIWindowSignup from './UI/UIWindowSignup.js';
|
||||
import UIWindowRequestPermission from './UI/UIWindowRequestPermission.js';
|
||||
import UIItem from './UI/UIItem.js';
|
||||
import UIWindowFontPicker from './UI/UIWindowFontPicker.js';
|
||||
import UIWindowColorPicker from './UI/UIWindowColorPicker.js';
|
||||
import UIPrompt from './UI/UIPrompt.js';
|
||||
import download from './helpers/download.js';
|
||||
import path from './lib/path.js';
|
||||
import UIContextMenu from './UI/UIContextMenu.js';
|
||||
import update_mouse_position from './helpers/update_mouse_position.js';
|
||||
import item_icon from './helpers/item_icon.js';
|
||||
import UIPopover from './UI/UIPopover.js';
|
||||
import socialLink from './helpers/socialLink.js';
|
||||
import update_mouse_position from './helpers/update_mouse_position.js';
|
||||
import path from './lib/path.js';
|
||||
import UIAlert from './UI/UIAlert.js';
|
||||
import UIContextMenu from './UI/UIContextMenu.js';
|
||||
import UIItem from './UI/UIItem.js';
|
||||
import UIPopover from './UI/UIPopover.js';
|
||||
import UIPrompt from './UI/UIPrompt.js';
|
||||
import UIWindow from './UI/UIWindow.js';
|
||||
import UIWindowColorPicker from './UI/UIWindowColorPicker.js';
|
||||
import UIWindowEmailConfirmationRequired from './UI/UIWindowEmailConfirmationRequired.js';
|
||||
import UIWindowFontPicker from './UI/UIWindowFontPicker.js';
|
||||
import UIWindowRequestPermission from './UI/UIWindowRequestPermission.js';
|
||||
import UIWindowSaveAccount from './UI/UIWindowSaveAccount.js';
|
||||
import UIWindowSignup from './UI/UIWindowSignup.js';
|
||||
|
||||
import { PROCESS_IPC_ATTACHED } from './definitions.js';
|
||||
|
||||
@@ -1270,6 +1270,7 @@ const ipc_listener = async (event, handled) => {
|
||||
// options.permission must be provided and be a string
|
||||
if ( !event.data.options.permission || typeof event.data.options.permission !== 'string' )
|
||||
{
|
||||
console.error('IPC requestPermission requires parameter { permission }', event.data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,15 @@ class UI extends EventListener {
|
||||
...args,
|
||||
}, '*');
|
||||
//register callback
|
||||
this.#callbackFunctions[msg_id] = resolve;
|
||||
this.#callbackFunctions[msg_id] = (...a) => {
|
||||
resolve(...a);
|
||||
};
|
||||
}
|
||||
|
||||
#postMessageAsync (name, args = {}) {
|
||||
return new Promise(resolve => {
|
||||
this.#postMessageWithCallback(name, resolve, args);
|
||||
});
|
||||
}
|
||||
|
||||
#postMessageWithObject (name, value) {
|
||||
@@ -974,17 +982,14 @@ class UI extends EventListener {
|
||||
this.#postMessageWithObject('setMenubar', spec);
|
||||
};
|
||||
|
||||
requestPermission (options) {
|
||||
return new Promise((resolve) => {
|
||||
if ( this.env === 'app' ) {
|
||||
return new Promise((resolve) => {
|
||||
this.#postMessageWithCallback('requestPermission', resolve, { options });
|
||||
});
|
||||
} else {
|
||||
// TODO: Implement for web
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
async requestPermission (options) {
|
||||
if ( this.env === 'app' ) {
|
||||
const result = await this.#postMessageAsync('requestPermission', { options });
|
||||
return result.granted;
|
||||
} else {
|
||||
// TODO: Implement for web
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
disableMenuItem (item_id) {
|
||||
|
||||
Reference in New Issue
Block a user