vespasianvs
vespasianvs

Reputation: 259

ElectronJS: Drag and Drop and file onto the electron app icon on the Windows taskbar

I'm trying to allow a file to be dragged into my electron app in Windows. Several things work:

However, I would like to be able to SHIFT drag a file onto the electron app icon on the Windows Taskbar when the app is running. When I do the SHIFT drag, the tooltip says 'Open with Electron', but when I then drop....nothing happens. I have tried console logging inside the "second-instance" handler, which is what I would expect to fire...but nothing.

app.on("second-instance", (event, argv) => {
    log.info("HERE");
    // Someone tried to run a second instance, we should focus our window.
    if (argv.length >= 2) {
        const urlPath = encodeURI(`file:///${argv[argv.length - 1]}`);
        openDeepLink(`app://open-image-url?location=${urlPath}`, mainWindow);
    }

    if (mainWindow) {
        if (mainWindow.isMinimized()) {
            mainWindow.restore();
        }
        mainWindow.focus();
    }
});

(the deeplink shortcode isn't really 'app' of course). The log.info for "HERE" never fires (I have tested log.info works elsewhere just in case, it does!).

I am running: Windows 10 (fully updated) capacitor-community/electron: 1.3.1 electron: 11.0.1

Upvotes: 1

Views: 789

Answers (1)

vespasianvs
vespasianvs

Reputation: 259

Right - after more time looking at it - I found the problem:

I had the following code in app.on("ready"):

    if (Notification.isSupported()) {
        updateNotify = new Notification({
            title: "Update Available",
            body: "An update is available. It will be installed when you exit"
        });
    }

updateNotify.show() was then called later if needed. Turns out that when I removed that code from the "ready" handler, drag and drop worked fine. I have put the same code into the "update-downloaded" handler now and everything works fine. Not quite sure why the code broke the drag and drop, but this seems to fix it!

Upvotes: 1

Related Questions