2023年12月3日发(作者:)

electron编写nsis脚本,设置安装向导需求:利用eletron-builder打包程序时发现,每次安装完后需要手动打开安装目录,找到配置文件修改配置参数,比较麻烦,也不够帅气,能否在安装时就提示用户输入参数呢。配置如下:编写自定义图形界面脚本:!include !include #OutFile #RequestExecutionLevel user#ShowInstDetails showVar DialogVar nameVar entryVar websiteVar openModePage custom pgPageCreate pgPageLeaveFunction pgPageCreate nsDialogs::Create 1018 Pop $Dialog ${If} $Dialog == error Abort ${EndIf} ${NSD_CreateGroupBox} 10% 10u 80% 100u "Settings" Pop $0 ${NSD_CreateLabel} 20% 26u 20% 10u "name:" Pop $0 ${NSD_CreateText} 40% 24u 40% 12u "electron" Pop $name ${NSD_CreateLabel} 20% 40u 20% 10u "entry:" Pop $0 ${NSD_CreateText} 40% 38u 40% 12u "" Pop $entry ${NSD_CreateLabel} 20% 54u 20% 10u "website:" Pop $0 ${NSD_CreateText} 40% 52u 40% 12u "" Pop $website

${NSD_CreateLabel} 20% 68u 20% 10u "openMode:" Pop $0 ${NSD_CreateText} 40% 66u 40% 12u "false" Pop $openMode nsDialogs::ShowFunctionEndFunction PgPageLeave ${NSD_GetText} $name $0 ${NSD_GetText} $entry $1 ${NSD_GetText} $website $2 ${NSD_GetText} $openMode $3 FileOpen $9 $on w FileWrite $9 "{name:$0,entry:$1,website:$2,openMode:$3}" FileClose $9 SetFileAttributes $on NORMALFunctionEndSectionSectionEnd效果如下:在pageLeave的时候,将用户输入的参数写入到配置文件(.electron)中,electron启动后,在主进程中读取.electron,获取参数。