About actions at the end of Inkdrop

I am developing a plugin that will confirm with a dialog when Inkdrop exits.
I am trying to take advantage of App Quit Event

The ipm init command created a project template.
Then I rewrote the entry file.

"use babel";

export function activate() {
  alert("Hello");
}

Then when I restarted Inkdrop, I got an alert on startup.
I can confirm that the Inkdrop plugin is loaded.
Next, I added onAppQuit .

"use babel";

export function activate() {
  inkdrop.onAppQuit(() => {
    alert("Hello");
  });
}

Restarted Inkdrop.
At startup, no alert were generated. Just I assumed.
I am in a Windows environment, so I clicked on the X symbol in the upper right corner.
At this moment, I would like to seen an alert occur. However, Inkdrop exits without anything occurring… :sob:

I have experience creating color themes for Inkdrop, but this is my first time developing an extension.

Hi Daiki-san,

Great to hear that you are trying to create a plugin!
So, you want to display a dialog when quitting the app.

You have to understand the concept of the renderer processes and main processes.
Plugins run on the renderer processes, and the onAppQuit event handler receives an event before-quit from the main process.
You can subscribe to this event but can’t prevent the app from quitting from your event handler, since the main process can’t know it.

Instead, you can prevent the window from closing by doing something like so:

inkdrop.window.addListener('close', (e) => {
  e.preventDefault()
  alert('prevented')
})

It can’t prevent an action like Cmd-Q on macOS though, maybe that’s what you want to achieve?

Ref:

1 Like

Hi Takuya-san!

Thank you very match :smiling_face_with_three_hearts:
I did not understand how Electron works. I was able to run it with the code you wrote. I have closing apps by mistake, so I try to show the exit confirmation dialog for other apps as well.

I will do my best to release the plugin. Thank you :blush:

1 Like