首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >电子反应-样板飞溅屏

电子反应-样板飞溅屏
EN

Stack Overflow用户
提问于 2022-08-06 05:02:03
回答 1查看 143关注 0票数 0

我有一个电子应用程序是用electron-react-boilerplate实例化的。我想加入一个飞溅的屏幕。也就是说,我有以下代码:

代码语言:javascript
复制
splash = new BrowserWindow({
        icon: getAssetPath("icon.png"),
        transparent: true,
        alwaysOnTop: true,
        frame: false,
        height: 600,
        width: 800,
    });

splash.loadURL(resolveHtmlPath("splash.html"));

其中resolveHtmlPath由以下代码定义:

代码语言:javascript
复制
let resolveHtmlPath: (htmlFileName: string) => string;

if (process.env.NODE_ENV === "development") {
    const port = process.env.PORT || 1212;
    resolveHtmlPath = (htmlFileName: string) => {
        const htmlUrl = new URL(`http://localhost:${port}`);
        htmlUrl.pathname = htmlFileName;
        return htmlUrl.href;
    };
} else {
    resolveHtmlPath = (htmlFileName: string) => {
        const myurl = url.format({
            pathname: path.resolve(__dirname, "../renderer/", htmlFileName),
            protocol: "file:",
            slashes: true,
        });
        return myurl;
    };
}

我知道electron-react-boilerplate在打包过程中构建了react应用程序,并创建了一个html index.html文件,该文件提供给呈现程序过程。现在,我想创建一个类似的东西,但是创建一个名为splash.html的splash页面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-06 20:14:06

如果你用的是电子生成器,你可以像我一样做这个。

package.json文件中,我添加如下extra-ressources

代码语言:javascript
复制
  "build": {
    "productName": "exemple",
    ... 
    "extraResources": [
      "./assets/**",
      "./splash/**",
    ]
  },
...

在打包应用程序时,extra-ressources中的所有文件夹都在ressources文件夹中可用。文档

main.ts中,我使用tenary操作符来验证我的应用程序是否已经打包,然后,我得到了我的启动屏幕的路径。

代码语言:javascript
复制
const splash = new BrowserWindow({
    width: 1024,
    height: 728,
    movable: true,
    center: true,
    icon: getAssetPath('icon.png'),
    transparent: true,
    frame: false,
  });

  const splashScreenSrc = app.isPackaged
    ? path.join(process.resourcesPath, 'splash', 'splash.html')
    : path.join(__dirname, '../../splash', 'splash.html');

  splash.loadFile(splashScreenSrc);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73257301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档