Skip to content

Instantly share code, notes, and snippets.

@d1y
Created January 5, 2020 17:20
Show Gist options
  • Select an option

  • Save d1y/862c1227735dfd02e82ade9759a71f11 to your computer and use it in GitHub Desktop.

Select an option

Save d1y/862c1227735dfd02e82ade9759a71f11 to your computer and use it in GitHub Desktop.
electron 全屏
const electron = require('electron')
const { app } = electron
const { BrowserWindow } = electron
const path = require('path')
const url = require('url')
let mainWindow
let loadingScreen
let willQuitApp = false;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1435,
height: 850,
minHeight: 500,
minWidth: 950,
title: 'Palace Connect',
center: true,
show: false,
//frame: false, REDUNDENT DUE TO titleBarStyle: hidden
autoHideMenuBar: true,
alwaysOnTop: false,
icon: '../src/images/AppIcon.icns',
titleBarStyle: 'hidden',
fullscreenWindowTitle: true,
})
mainWindow.loadURL(
process.env.ELECTRON_START_URL
|| url.format({
pathname: path.join(__dirname, '/../public/index.html'),
protocol: 'file:',
slashes: true,
}),
)
mainWindow.openDevTools()
mainWindow.webContents.on('did-finish-load', () => {
if (loadingScreen) {
loadingScreen.setResizable(true);
loadingScreen.setBounds({
width: 1435,
height: 850,
center: true
})
loadingScreen.center()
setTimeout(() => {
mainWindow.setBounds({
width: 1435,
height: 850,
title: 'Palace Connect',
center: true,
show: true,
frame: false,
autoHideMenuBar: true,
alwaysOnTop: false,
icon: '../src/images/AppIcon.icns',
titleBarStyle: 'hidden'
})
loadingScreen.close()
mainWindow.show()
}, 1000)
}
})
mainWindow.on('maximize', () => {
mainWindow.setMenuBarVisibility(visible)
})
mainWindow.on('close', (event) => {
if (willQuitApp) {
mainWindow = null;
app.quit();
} else {
mainWindow.hide();
event.preventDefault();
}
})
}
function createLoadingScreen() {
loadingScreen = new BrowserWindow({
width: 300,
height: 300,
title: 'Palace Connect',
center: true,
show: true,
frame: false,
autoHideMenuBar: true,
alwaysOnTop: false,
icon: '../src/images/AppIcon.icns',
})
loadingScreen.setResizable(false);
loadingScreen.loadURL(`file://${__dirname}/../public/loading.html`)
loadingScreen.on('closed', () => loadingScreen)
loadingScreen.webContents.on('did-finish-load', () => {
loadingScreen.show()
})
}
app.on('ready', () => {
createLoadingScreen()
createWindow()
})
app.on('toggle-popwindow', () => {
mainWindow.show();
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
} else {
mainWindow.show();
}
})
app.on('before-quit', () => willQuitApp = true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment