您的位置:首页 > 健康 > 美食 > Electron快速入门(二):在(一)的基础上修改两个文件完成自定义显示时间和天气的标题栏

Electron快速入门(二):在(一)的基础上修改两个文件完成自定义显示时间和天气的标题栏

2024/10/6 22:22:42 来源:https://blog.csdn.net/lulei5153/article/details/139880725  浏览:    关键词:Electron快速入门(二):在(一)的基础上修改两个文件完成自定义显示时间和天气的标题栏

修改主进程:main.js

// main.jsconst { app, BrowserWindow } = require("electron");
const path = require("node:path");
const createWindow = () => {try {const mainWindow = new BrowserWindow({width: 1200,height: 870,alwaysOnTop: true,frame: false,icon: path.join(__dirname, "./img/icon.ico"),webPreferences: {preload: path.join(__dirname, "preload.js"),},});mainWindow.loadFile(path.join(__dirname, "index.html"));// 打开开发工具mainWindow.webContents.openDevTools();} catch (e) {console.error("Failed to create window:", e);}
};app.whenReady().then(() => {createWindow();app.on("activate", () => {if (BrowserWindow.getAllWindows().length === 0) createWindow();});
});// 在 Windows 和 Linux 上,关闭所有窗口时应该退出应用
app.on("window-all-closed", () => {if (process.platform !== "darwin") app.quit();
});// 在 MacOS 上,应用没有结束,但所有窗口已关闭时,重新创建一个窗口
app.on("activate", () => {if (BrowserWindow.getAllWindows().length === 0) createWindow();
});

修改渲染进程:index.html

<!--index.html-->
<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8"><!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --><meta http-equiv="Content-Security-Policy" content="width=device-width, initial-scale=1.0"><title>空空我啊</title><!-- <link rel="stylesheet" href="./src/style.css"> --><style>/* 格式化样式 */* {margin: 0;padding: 0;/* box-sizing: border-box; *//* 防止用户选中文本 */user-select: none;}body {width: 100vw;height: 100vh;background: #2c3e50;/* 溢出隐藏 */overflow: hidden;}/* title-bar自定义标题栏  */.title-bar {width: 100vw;height: 35px;display: flex;align-items: center;justify-content: space-between;background: #ffffff9c;-webkit-app-region: drag;.logo {img {width: 30px;height: 30px;margin: 6px 0 0px 5px;-webkit-app-region: no-drag;transition: transform 0.3s ease;&:hover {transform: scale(1.2);}}}.form-btn {-webkit-app-region: no-drag;/* 最小宽度 */min-width: 100px;/* 按钮样式 */button {cursor: pointer;font-size: 1.5rem;cursor: pointer;border: none;color: #ffffffb7;text-shadow: 1px 1px 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com