在 Electron JS 上恢复 Main Window

Restoring Main Window on Electron JS

我创建了一个应用程序(为 OSX 完成)即使主 window 被隐藏也会发送消息,目前我的 main.js 是这样的:

const { app, shell, BrowserWindow, dialog } = require('electron')
const path = require('path')
const electron = require('electron')

// Enable live reload for all the files inside your project directory
require('electron-reload')(__dirname);

let win = null

function createWindow () {
   win = new BrowserWindow({
    width: 420,
    height: 420,
    resizable: false,
    fullscreenable: false,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: true
    }
  })

  win.on('close', (event) => {
    if (app.quitting) {
      win = null
    } else {
      event.preventDefault()
      win.hide()
    }
  })

  win.loadFile('index.html')

  win.webContents.on('new-window', function(e, url) {
  // make sure local urls stay in electron perimeter
  if('file://' === url.substr(0, 'file://'.length)) {
    return;
  }

  // and open every other protocols on the browser      
  e.preventDefault();
  shell.openExternal(url);
  });

}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })



})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => { win.show() })

app.on('before-quit', () => app.quitting = true)

想法是,当用户尝试关闭应用程序时,它只会隐藏它。我需要添加一些内容,以便应用程序在一天中的特定时间再次启动主 window。

有没有办法让主要 window 重新打开或 运行 在后台设置一个代码,以便在一天中的特定时间 window 将被取消隐藏?

当然....这将重新打开您最小化的 window

if (win) {
  if (win.isMinimized()) win.restore()
  win.focus()
}