随笔 - 26  文章 - 0  评论 - 0  阅读 - 12383

主进程中读取电脑mac地址,主机名,electron vue

复制代码
 1 async function createWindow() {
 2   // 注入小段css文件
 3   // mainWindow.webContents.insertCSS(" body,html { -webkit-app-region: drag !important;}")
 4   // body,html { -webkit-app-region: drag; } 
 5   // path获取本机mac地址
 6   var path = require('path')
 7   // Create the browser window.
 8   // Menu.setApplicationMenu(null) // null值取消顶部菜单栏
 9   const win = new BrowserWindow({
10     width: 1920,
11     height: 1080,
12     // 隐藏导航栏
13     // autoHideMenuBar: true,
14     // 全屏显示
15     // fullscreenable: true,
16     // fullscreen: true,
17     // simpleFullscreen: true,
18     // 无边框窗口
19     // frame:false,
20     // transparent: true,
21     webPreferences: {
22       webSecurity:false,
26       nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
27       contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
28 
29       nodeIntegration: true,
30       contextIsolation: false,
31 
32     引入js文件 读取本地存储
33       // preload: path.join(__dirname, 'preload.js'),
34     }
35   })
复制代码

 

Preload.js

复制代码
 1 window.addEventListener('DOMContentLoaded', () => {
 2     var os = require("os");
 3     if (os.networkInterfaces().WLAN) {
 4         sessionStorage.setItem("mac", os.networkInterfaces().WLAN[0].mac)
 5         // localStorage.setItem("mac")= os.networkInterfaces().WLAN[0].mac
 6     } else {
 7         sessionStorage.setItem("mac" , os.networkInterfaces()['以太网'][0].mac)
 8         // localStorage.setItem("mac") = os.networkInterfaces()['以太网'][0].mac
 9     }
10     sessionStorage.setItem("name" , os.hostname())
11     console.log(123456);
12     // localStorage.setItem('name') = os.hostname()
13 
14     const replaceText = (selector, text) => {
15         const element = document.getElementById(selector)
16         if (element) element.innerText = text
17     }
18 
19     for (const type of ['chrome', 'node', 'electron']) {
20         replaceText(`${type}-version`, process.versions[type])
21     }
22 })
复制代码

 

posted on   阿术阿术  阅读(1515)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示