branchseer / DeskGap

A cross-platform desktop app framework based on Node.js and the system webview
https://deskgap.com/
MIT License
1.83k stars 73 forks source link

window.location.reload() breaks window.deskgap and drag #41

Closed TorstenDittmann closed 4 years ago

TorstenDittmann commented 4 years ago

Using window.location.reload() in code removes the window.deskgap reference and all of the drag functionality from elements with the data-deskgap-drag attribute.

Reloading with BrowserWindow works fine.

branchseer commented 4 years ago

What OS/web engine did you use?

TorstenDittmann commented 4 years ago

It occurs on Windows with both EdgeHTML and Trident. On Webkit everything works fine. You can reproduce it by just adding a window.location.reload() to the API Demo :+1:

branchseer commented 4 years ago

@TorstenDittmann Hi,

After some googling it turns out this issue has been studied for a long time since the dark age of IE. There are some workaround but never perfect. I think I'll just leave this issue unsolved.

Inconsistencies about navigations happen a lot among different platforms. For cross-platform consistency I would avoid usages of navigation-related functions and events (except ready-to-show and first-time loadURL/loadFile), especially those in BOM.

TorstenDittmann commented 4 years ago

Alright. I fully understand you.

For people with the same problem I am gonna edit this post later and add some examples on how to handle this problem.

Gonna close it later.

Edit: Add a messageNode to your DeskGap main js file:

// index.js
const { 
    app, 
    BrowserWindow, 
    messageNode 
} = require('deskgap');

app.once('ready', () => {
    // Add MessageNode for reloading with BrowserWindow
    messageNode.on("reload", () => {
        win.reload();
    });

const win = new BrowserWindow();
win.loadFile('index.html');
});

For any time you want to reload your page you can use a reload() method like this:

// Inside App Code
const { messageUI } = window.deskgap || {};

function  reload() {
    return  window.deskgap ? messageUI.send('reload') : window.location.reload();
};