主进程中读取电脑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 })
分类:
electron
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了