javascript - 可移植 Electron 应用程序每次打开时都被提取到不同的文件夹中

标签 javascript socket.io electron firewall electron-builder

  • electron-builder 版本:20.9.2
  • 目标:windows/portable

我正在使用 electron-builder 构建一个可移植应用程序并使用 socket.io与后端服务保持实时连接,但我遇到了防火墙问题。因为这是一个可移植应用程序,所以每次打开该应用程序时,它看起来都被提取到临时文件夹中,这将在每次运行时生成一个新文件夹(因此应用程序的路径将不同),这将使防火墙认为这是是另一个要求连接权限的应用程序。如何在运行应用程序时更改提取路径?

(这是我每次运行应用程序时得到的屏幕) image

这是我的 socket.io 配置

const io = require("socket.io")(6524);

io.on("connect", socket => {
    socket.on("notification", data => {
       EventBus.$emit("notifications", JSON.parse(data));
   });
});

我在 package.json 中的build设置

"build": {
    "productName": "xxx",
    "appId": "xxx.xxx.xxx",
    "directories": {
        "output": "build"
    },
    "files": [
        "dist/electron/**/*",
        "!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}",
        "!**/node_modules/.bin",
        "!**/*.{o,hprof,orig,pyc,pyo,rbc}",
        "!**/._*",
        "!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}",
        "!**/node_modules/search-index/si${/*}"
    ],
    "win": {
        "icon": "build/icons/myicon.ico",
        "target": "portable"
    }
},

关于至少我如何指定提取路径或将其提取为执行文件夹的任何想法?


顺便说一句,我已经创建了一个 issue关于这个在 electron-builder 仓库中

最佳答案

20.40.1 版本中,他们添加了一个新的配置 key unpackDirName

/**
   * The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.
   *
   * Defaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).
   */
  readonly unpackDirName?: string

例子

config: {
  portable: {
    unpackDirName: "0ujssxh0cECutqzMgbtXSGnjorm",
  }
}

更多信息 #3799 .

关于javascript - 可移植 Electron 应用程序每次打开时都被提取到不同的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50436934/

相关文章:

javascript - 设置模板中的日期格式以在 GMT 时区中显示

javascript - 下拉悬停在窗口调整大小时启用/禁用

javascript - 如何使用socket.io请求实现类似jQuery的回调?

python - 使用Python + Selenium进行基于 Electron 的应用测试

javascript - 结合过滤器和包含过滤多个值

c# - 使用 Javascript 设置下拉列表的值并在 C# 中获取该值

electron - 打包由 Python Flask Electron 提供支持的 Electron 应用程序

python - 如果使用Eel python的用户未安装chrome怎么办

node.js - Express/Socket.io : The right way for one socket per request

javascript - socket.io api 文档中的 "Server(srv:http#Server, opts:Object)"是什么意思?