首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用@电容器社区/电子使用离子v5构建电子应用程序

使用@电容器社区/电子使用离子v5构建电子应用程序
EN

Stack Overflow用户
提问于 2021-10-02 15:24:11
回答 1查看 1.1K关注 0票数 1

上周我遇到了以下问题--我不仅想把我的Ionic项目编译成android版本,还想把它编译成电子桌面应用。但是,每次当我部署打包的电子版时,我都会看到一个白屏。

如何重现问题:

代码语言:javascript
复制
# i create simple angular app
ionic start example-app tabs --type angular 
cd example-app
# i add @capacitor-community version of electron, since the original electron is deprecated
npm i @capacitor-community/electron
# required to get a www folder
ionic build
# add electron folder to project
npx cap add @capacitor-community/electron
# now we work inside electron project...
cd electron
# we can build project
npm run build
# we can start live project
npm run electron:start-live
# and now we have crash - just a blank white window
npm run electron:pack
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-02 15:24:11

我已经能够在部署版本中获得可见的窗口,在./electron/src/setup.ts文件中做了以下更改。您需要找到以下片段:

代码语言:javascript
复制
// Set a CSP up for our application based on the custom scheme
export function setupContentSecurityPolicy(customScheme: string): void {
  session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
    callback({
      responseHeaders: {
        ...details.responseHeaders,
        'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' data:`,
        ],
      },
    });
  });
}

并将其更改为:

代码语言:javascript
复制
// Set a CSP up for our application based on the custom scheme
export function setupContentSecurityPolicy(customScheme: string): void {
  session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
    callback({
      responseHeaders: {
        ...details.responseHeaders,
        'Content-Security-Policy': [
             `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
        ],
      },
    });
  });
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69418292

复制
相关文章

相似问题

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