当前位置:网站首页>Modules that can be used by both the electron main process and the rendering process
Modules that can be used by both the electron main process and the rendering process
2022-07-06 22:56:00 【Follow the road to the end】
shell modular
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<h2>shell And iframe</h2>
<a id="openUrl" href="https://kaiwu.lagou.com/"> open URL</a>
<br><br>
<button id="openFolder"> Open Directory </button>
<script src="index.js"></script>
</body>
</html>index.js
const { shell } = require('electron')
const path = require('path')
window.addEventListener('DOMContentLoaded', () => {
const oBtn1 = document.getElementById('openUrl')
const oBtn2 = document.getElementById('openFolder')
oBtn1.addEventListener('click', (e) => {
e.preventDefault()
const urlPath = oBtn1.getAttribute('href')
shell.openExternal(urlPath) // Open the link using the default browser
})
oBtn2.addEventListener('click', () => {
shell.showItemInFolder(path.resolve(__filename))
})
})
iframe
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
iframe {
top: 0;
left: 0;
width: 100%;
height: 100%;
position: fixed;
}
</style>
</head>
<body>
<h2>shell And iframe</h2>
<iframe src="https://kaiwu.lagou.com/" frameborder="0" id="webview"></iframe>
<script src="index.js"></script>
</body>
</html>Customize menu usage shell
main.js
const { app, BrowserWindow, Menu, shell } = require('electron')
console.log(process.platform)
// Define global variables to store in the main window id
let mainWinId = null
// create a window
function createWindow () {
console.log('ready')
// Create the main process
const mainWin = new BrowserWindow({
title: ' Custom menu ',
show: false, // true: Display Form ,false: Don't show forms
width: 800,
height: 400,
webPreferences: {
nodeIntegration: true, // Allow browser environments to use Node API
enableRemoteModule: true, // Allow pages to use remote
}
})
let tmp = [
{
label: ' menu ',
submenu: [
{
label: ' About ',
click() {
shell.openExternal('https://kaiwu.lagou.com/')
}
},
{
label: ' open ',
click() {
BrowserWindow.getFocusedWindow().webContents.send('openUrl')
}
},
]
}
]
let menu = Menu.buildFromTemplate(tmp)
Menu.setApplicationMenu(menu)
// Load the specified interface in the current window and let it display the specific content
mainWin.loadFile('index.html')
mainWinId = mainWin.id
mainWin.on('ready-to-show', () => {
mainWin.show() // After the form is fully loaded , Display Form , Avoid white pages
})
mainWin.on('close', () => {
console.log('close')
//mainWin = null
})
}
// When app After starting , Perform window creation and other operations
app.on('ready', createWindow)
app.on('window-all-closed', () => {
console.log('window-all-closed')
app.quit()
})
Notice of news
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<h2> be based on H5 Implement message notification </h2>
<button id="btn"> Trigger message </button>
<script src="index.js"></script>
</body>
</html>index.js
window.addEventListener('DOMContentLoaded', () => {
const oBtn = document.getElementById('btn')
oBtn.addEventListener('click', () => {
const option = {
title: ' Notification message 123',
body: ' The message content abc',
icon: './msg.png',
}
const myNotification = new window.Notification(option.title ,option)
myNotification.onclick = function() {
console.log(' Click on the message page card ')
}
})
})
1

Shortcut key registration
main.js
const { app, BrowserWindow, globalShortcut } = require('electron')
console.log(process.platform)
// Define global variables to store in the main window id
let mainWinId = null
// create a window
function createWindow () {
console.log('ready')
// Create the main process
const mainWin = new BrowserWindow({
title: ' Custom menu ',
show: false, // true: Display Form ,false: Don't show forms
width: 800,
height: 400,
webPreferences: {
nodeIntegration: true, // Allow browser environments to use Node API
enableRemoteModule: true, // Allow pages to use remote
}
})
// Load the specified interface in the current window and let it display the specific content
mainWin.loadFile('index.html')
mainWinId = mainWin.id
mainWin.on('ready-to-show', () => {
mainWin.show() // After the form is fully loaded , Display Form , Avoid white pages
})
mainWin.on('close', () => {
console.log('close')
//mainWin = null
})
}
// When app After starting , Perform window creation and other operations
app.on('ready', createWindow)
// Register shortcuts
app.on('ready', () => {
const ret = globalShortcut.register('ctrl + q', () => {
console.log(' Shortcut key registration ')
})
if (!ret) {
console.log(' Registration failed ')
}
console.log(globalShortcut.isRegistered('ctrl + q'))
console.log(ret)
})
app.on('will-quit', () => {
// Shortcut key to cancel registration
globalShortcut.unregister('ctrl + q')
// Cancel all registered shortcuts
globalShortcut.registerAll()
})
app.on('window-all-closed', () => {
console.log('window-all-closed')
app.quit()
})
Shear board module
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<h2> Clippings </h2>
<input type="text" placeholder=" Enter the content to be copied "> <button> Copy </button>
<br><br>
<input type="text" placeholder=" Paste the content here "> <button> Paste </button>
<br><br>
<button id='clipImg'> Copy the picture to the cutout and paste it into the interface </button>
<br><br>
<script src="index.js"></script>
</body>
</html>index.js
const { clipboard, nativeImage } = require('electron')
window.addEventListener('DOMContentLoaded', () => {
const aBtn = document.getElementsByTagName('button')
const aInput = document.getElementsByTagName('input')
const oBtn = document.getElementById('clipImg')
let ret = null
aBtn[0].addEventListener('click', () => {
// Copy content to clipboard
ret = clipboard.writeText(aInput[0].value)
})
aBtn[1].addEventListener('click', () => {
// Paste the contents of the clipboard
aInput[1].value = clipboard.readText(ret)
})
oBtn.addEventListener('click', () => {
// When placing the picture in the clipboard, it is required that the picture type belongs to nativeImage example
const oImage = nativeImage.createFromPath('./msg.png')
clipboard.writeImage(oImage)
// Make the picture in the clipboard as DOM Elements are displayed on the interface
const oImg = clipboard.readImage()
const oImgDom = new Image()
oImgDom.src = oImg.toDataURL()
document.body.append(oImgDom)
})
})
1
边栏推荐
- 存币生息理财dapp系统开发案例演示
- Pytest unit test series [v1.0.0] [pytest execute unittest test case]
- 专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
- How to choose indoor LED display? These five considerations must be taken into account
- Sword finger offer question brushing record 1
- Precise drag and drop within a contentable
- Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
- uniapp设置背景图效果demo(整理)
- Dayu200 experience officer homepage AITO video & Canvas drawing dashboard (ETS)
- View
猜你喜欢

On file uploading of network security

cuda 探索

#DAYU200体验官# 首页aito视频&Canvas绘制仪表盘(ets)

儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程

Children's pajamas (Australia) as/nzs 1249:2014 handling process

DR-Net: dual-rotation network with feature map enhancement for medical image segmentation

Adavit -- dynamic network with adaptive selection of computing structure

Matlab tips (27) grey prediction

Let's see through the network i/o model from beginning to end

专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
随机推荐
Detailed explanation of ThreadLocal
hdu 5077 NAND(暴力打表)
Volatile keyword
Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
How to achieve text animation effect
树的先序中序后序遍历
Matlab tips (27) grey prediction
Dayu200 experience officer homepage AITO video & Canvas drawing dashboard (ETS)
On file uploading of network security
HDU 5077 NAND (violent tabulation)
Sword finger offer question brushing record 1
Is "applet container technology" a gimmick or a new outlet?
Windows Auzre 微软的云计算产品的后台操作界面
Custom swap function
面试题:AOF重写机制,redis面试必问!!!
POJ 1094 sorting it all out
Aardio - does not declare the method of directly passing float values
Enterprises do not want to replace the old system that has been used for ten years
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)