本文介绍了将自定义页面/字段添加到使用electronic-builder创建的NSIS设置中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Electron应用程序,该应用程序与带有electronic-builder的NSIS安装程序打包在一起。

I have created an Electron app which is packaged into an NSIS installer with electron-builder.

现在,我想向安装程序中添加自定义文本字段,用户可以在其中输入一个值(该值应保存到磁盘/注册表中,以后需要在应用程序中可用)。

Now I would like to add a custom text field to the installer, where the user can input a value (the value should be saved to disk/registry, it needs to be available in the app later).

我看到有一个 customWelcomePage 宏,可能会(错误地)用于此目的?但是,如何创建一个可以创建完整页面的宏? NSIS对我来说是全新的,并且NSIS页面上的示例似乎是针对独立安装程序的,而不是用于挂钩到现有安装程序的。还是有另一种更好的方法?

I saw there is a customWelcomePage macro defined in the installer, which could probably be (mis)used for this purpose? But how would I create a macro which creates a complete page? NSIS is completely new to me, and the examples on the NSIS page seem to be for standalone installers, not for hooking into an existing installer. Or is there another, better approach?

推荐答案

我最近一直在研究同一件事。这是我所做的:

I've been working on the same thing recently. Here's what I did:

首先,使用选项指向一个.nsh文件(我在package.json中这样做):

First, use the include option to point to a .nsh file (I'm doing this in package.json):

{
  "build": {
    "appId": "...",
    "nsis": {
      "include": "build/installer.nsh"
    }
  }
}

然后您可以将自定义NSIS代码放入该.nsh文件中:

Then you can put your custom NSIS code inside that .nsh file:

!include nsDialogs.nsh

XPStyle on

Var Dialog

Page custom myCustomPage

Function myCustomPage

    nsDialogs::Create 1018
    Pop $Dialog

    ${If} $Dialog == error
        Abort
    ${EndIf}

    ...

    nsDialogs::Show

FunctionEnd

Section
SectionEnd

我改编自的在创建自定义页面时出现。这将使页面显示在实际安装之前(Mevia的问题),因此您应谨慎保存输入数据。

I adapted code from Mevia's question when I was creating my custom page. This will make a page that appears before the actual installation (Mevia's problem), so you should be careful where you save the input data.

我相信使用 include 代替 script 可以让您为单个页面编写代码,而不必自己编写整个安装程序脚本

I believe that using include instead of a script is what allows you to write code for a single page, rather than having to write the entire installer script yourself.

这篇关于将自定义页面/字段添加到使用electronic-builder创建的NSIS设置中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 03:49