first commit

This commit is contained in:
2025-01-09 18:30:49 +08:00
commit ead83056ff
99 changed files with 27286 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>shell && iframe</title>
<style>
* {
margin: 0;
padding: 0;
}
iframe {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<!-- <h2>shell and iframe</h2>
<a id="openUrl" href="https://cantyonion.site">打开url</a>
<br><br>
<button id="openFolder">打开目录</button> -->
<iframe src="https://cantyonion.site" frameborder="0" id="webview"></iframe>
<script src="index.js"></script>
</body>
</html>

View File

@@ -0,0 +1,27 @@
const { shell, ipcRenderer } = require("electron")
const path = require('path')
// window.onload = () => {
// // 1 获取元素
// let oBtn1 = document.getElementById('openUrl')
// let oBtn2 = document.getElementById('openFolder')
// oBtn1.addEventListener('click', (ev) => {
// ev.preventDefault()
// let urlPath = oBtn1.getAttribute('href')
// // 打开外部浏览器
// shell.openExternal(urlPath)
// })
// oBtn2.addEventListener('click', () => {
// // 打开当前目录
// shell.showItemInFolder(path.resolve(__filename))
// })
// }
ipcRenderer.on('open', () => {
let iframe = document.getElementById('webview')
iframe.src = 'https://cantyonion.site/git/'
})

View File

@@ -0,0 +1,45 @@
const { app, BrowserWindow, shell, Menu } = require('electron')
const createWindow = () => {
let mainWin = new BrowserWindow({
width: 800,
height: 400,
show: false,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true
}
})
let tmp = [
{
label: '菜单',
submenu: [
{
label: '关于',
click() {
shell.openExternal('https://cantyonion.site')
}
},
{
label: '打开',
click() {
BrowserWindow.getFocusedWindow().webContents.send('open')
}
},
]
}
]
let menu = Menu.buildFromTemplate(tmp)
Menu.setApplicationMenu(menu)
mainWin.loadFile('index.html')
mainWin.on('ready-to-show', mainWin.show)
mainWin.on('close', () => {
mainWin = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', app.quit)

1396
day03-shell-and-iframe/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View 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"
}
}