Я внедрил JavaScript, как показано ниже
Код: Выделить всё
var jsCode = @"
const { ipcRenderer } = require('electron');
if (window != null) {
window.onbeforeunload = (e) => {
e.returnValue = false;
ipcRenderer.send('minimize-app');
};
}
";
mainWindow.WebContents.OnDomReady += async() =>
{
if (mainWindow != null && !(await mainWindow.IsDestroyedAsync()))
{
await mainWindow.WebContents.ExecuteJavaScriptAsync(jsCode);
}
};
Код: Выделить всё
Electron.IpcMain.On("minimize-app", async(e) =>
{
Console.WriteLine("Got in here");
Log.Logger.Debug("Got in here");
try
{
if (mainWindow != null && !(await mainWindow.IsDestroyedAsync()))
{
Console.Write("here as well");
Log.Logger.Debug("here as well");
mainWindow.Minimize();
Console.WriteLine("Did this as well");
Log.Logger.Debug("Did this as well");
}
}
catch (Exception ex)
{
Log.Logger.Error(ex, "Error in minimize-app");
}
});
Electron.App.On("app-before-quit")
Но добавление любого кода, связанного с Electron.App.On, просто ломает мое приложение, и я не знаю причины этого. Я подумал, как и в случае с onbeforeunload, есть ли какой-нибудь код JavaScript, который я могу добавить, чтобы все заработало?
Подробнее здесь: https://stackoverflow.com/questions/793 ... m-shutdown