first commit
This commit is contained in:
12
day01-app-title/index.html
Normal file
12
day01-app-title/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Window Title</h1>
|
||||
<button id="btn">点击打开新窗口</button>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
19
day01-app-title/index.js
Normal file
19
day01-app-title/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const { remote } = require('electron')
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
// 点击按钮打开新窗口
|
||||
const oBtn = document.getElementById('btn')
|
||||
oBtn.addEventListener('click', () => {
|
||||
// 创建窗口
|
||||
let indexMain = new remote.BrowserWindow({
|
||||
width: 200,
|
||||
height: 200
|
||||
})
|
||||
|
||||
indexMain.loadFile('list.html')
|
||||
|
||||
indexMain.on('close', () => {
|
||||
indexMain = null
|
||||
})
|
||||
})
|
||||
})
|
||||
10
day01-app-title/list.html
Normal file
10
day01-app-title/list.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>新窗口</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>新窗口</h2>
|
||||
</body>
|
||||
</html>
|
||||
37
day01-app-title/main.js
Normal file
37
day01-app-title/main.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
function createWindow() {
|
||||
let mainWin = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
show: false,
|
||||
title: "标题", // 要在网页里的标题去除
|
||||
icon: "w.png", // 设置图标
|
||||
frame: true, // 是否显示标题栏
|
||||
transparent: false, // 透明窗体
|
||||
autoHideMenuBar: true, // 隐藏菜单
|
||||
webPreferences: {
|
||||
nodeIntegration: true, // Node集成环境
|
||||
enableRemoteModule: true, // 开启远程模块 remote
|
||||
}
|
||||
})
|
||||
|
||||
// 防止首页白屏,否则不显示
|
||||
mainWin.on('ready-to-show', () => {
|
||||
mainWin.show()
|
||||
})
|
||||
|
||||
mainWin.loadFile('index.html')
|
||||
|
||||
mainWin.on('close', () => {
|
||||
mainWin = null // 删除引用,释放空间
|
||||
})
|
||||
}
|
||||
|
||||
app.on('ready', () => {
|
||||
createWindow()
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit()
|
||||
})
|
||||
1396
day01-app-title/package-lock.json
generated
Normal file
1396
day01-app-title/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
day01-app-title/package.json
Normal file
17
day01-app-title/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "electron-life-cycle",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "nodemon --watch main.js --exec npm run build",
|
||||
"build": "electron ."
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"electron": "^11.2.1",
|
||||
"nodemon": "^3.1.9"
|
||||
}
|
||||
}
|
||||
BIN
day01-app-title/w.png
Normal file
BIN
day01-app-title/w.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Reference in New Issue
Block a user