电子应用程序在应用程序关闭时加载外部URL

时间:2019-03-24 18:59:09

标签: javascript electron

一旦尝试关闭应用程序关闭按钮,我正尝试加载注销URL

类似以下内容。问题是我收到一个错误消息,窗口已经关闭并且无法加载。任何帮助实现这一目标将不胜感激。

const snacks = "strawberry";

const fruits = [{
    label: "yellowFruit",
    value: "banana"
  },
  {
    label: "purpleFruit",
    value: "grape"
  },
  {
    label: "redFruit",
    value: [{
        val: "apple"
      },
      {
        val: "strawberry"
      }
    ]
  },
  {
    label: "greenFruit",
    value: "waltermelon"
  },
];

let res = fruits.find(({ value }) => Array.isArray(value) ? value.some(({ val }) => val === snacks) : value === snacks) || fruits[0]

console.log(res);

1 个答案:

答案 0 :(得分:2)

我对您要执行的操作感到有些困惑,但是听起来您可以在触发close事件时加载URL,取消该事件以防止closed触发,然后在页面加载后,您可以再次关闭,但是这次是真实的。

mainWindow.on('close', (e) => {
    mainWindow.webContents.on('did-finish-load', logOutPageLoaded);        
    mainWindow.loadURL('https://www.url.com/logout.php?logout=true');       
    e.preventDefault();
});

function logOutPageLoaded() {
    mainWindow.destroy();
}

mainWindow.on('closed', () => {              
    mainWindow = null;
    app.quit();
});
相关问题