install4J,如何通过Java首选项存储正确传递`updatesUrl`给更新程序?

huangapple go评论50阅读模式
英文:

install4J, how to correctly pass `updatesUrl` to the updater via the Java preference store?

问题

我正在尝试根据另一个SO帖子中的建议,为我的应用程序实现多通道(deb/beta/stable)更新。

我已经完成了以下步骤:

  1. 创建一个编译器变量 mediaID=${compiler:sys.mediaId}
  2. 当我的应用程序的用户更改其发布通道首选项时,会调用以下函数:mediaID = Variables.getCompilerVariable("mediaID"); Variables.saveToPreferenceStore(Map.of("updatesUrl", xmlURL), mediaID, true);
  3. 当用户决定更新时,会调用以下函数:ApplicationLauncher.launchApplicationInProcess(UPDATER_APPLICATION_ID, null, ....),但这会引发错误(退出值=1):

install4J,如何通过Java首选项存储正确传递`updatesUrl`给更新程序?

根据错误消息,似乎更新程序找不到 updatesUrl 变量,但在调用该函数之前,我记录了 com.install4j.api.launcher.Variables.loadFromPreferenceStore(mediaID, true); 的输出,结果为 {updatesUrl=https://github.com/akasolace/HO/releases/download/dev/updatesDEV.xml},这是合法的URL,因此似乎 updatesUrl 已正确存储。

现在,我有点困惑这应该如何工作。例如,我同时运行2个应用程序版本,并且我的设置如下:

  • mediaID 1,发布通道 Stable
  • mediaID 2,发布通道 Dev

在我的系统上,我将在2个不同的包中存储变量 updatesUrl,类似于:

{(1, "updatesUrl"): "...updatesSTABLE.xml", (2, "updatesUrl"): "...updatesDEV.xml"}

现在,在install4J中,我添加了操作“从Java首选项存储加载安装程序变量”,并且我看到包名称默认为${compiler:sys.applicationId}。这导致了以下问题:

  • 我认为applicationID 对于应用程序是唯一的,而mediaID 对于每个媒体是不同的。为了实现我的目标,我认为我需要使更新程序使用调用它的媒体的媒体ID作为包名称。也就是说,如果更新程序是从媒体ID x 调用的,我需要它查看包x中的变量“updatesUrl”。这可行吗,还是我弄错了?

[编辑] 我尝试将“从Java首选项存储加载安装程序变量”的包名称设置为${compiler:sys.mediaId},但这会引发以下错误:

install4J,如何通过Java首选项存储正确传递`updatesUrl`给更新程序?

感谢您提前的帮助。

英文:

I am trying to implement multi-channels (deb/beta/stable) update for my app following recommendation made in another SO post.

I have done the following steps:

  1. create a compiler variable mediaID=${compiler:sys.mediaId}
  2. when user of my app changes it release channel preference, the ollowing function is called: mediaID = Variables.getCompilerVariable("mediaID");
    Variables.saveToPreferenceStore(Map.of("updatesUrl", xmlURL), mediaID, true);
  3. when user decide to update the following function is called:
    ApplicationLauncher.launchApplicationInProcess(UPDATER_APPLICATION_ID, null, ....) but this throws an error (exit value = 1):

install4J,如何通过Java首选项存储正确传递`updatesUrl`给更新程序?

Based on the error message, it seems that the updater does not find the updatesUrl variable but just before the call to the function I logged the output of com.install4j.api.launcher.Variables.loadFromPreferenceStore(mediaID, true); and I got as a result {updatesUrl=https://github.com/akasolace/HO/releases/download/dev/updatesDEV.xml} which is the legit URL, so it seems updatesUrl was properly stored.

Now, I am a bit confused on how this should work. Me for example, I am running 2 version of the app in parralel and my setup is something like:

  • mediaID 1, release channel Stable
  • mediaID 2, release channel Dev

on my system I will have variable updatesUrl store in 2 differents package something like:

{(1, "updatesUrl"): "...updatesSTABLE.xml", (2, "updatesUrl"): "...updatesDEV.xml"}

Now, in install4J, I added the action "Load installer variable from the Java preference store" and I see package name default to ${compiler:sys.applicationId. This leads to the following question:

  • I believe applicationID unique for the app and mediaID different for each media. To achieve what I want I believe I need the updater to use as package name, the media ID of the media that called it. I mean if the updater is called from media ID x , I need it to look at the variable "updatesUrl" from package x. Is it doable or am I getting lost?

[Edit] I tried to set package name of "Load installer variable from the Java preference store" to ${compiler:sys.mediaId but this throws instead

install4J,如何通过Java首选项存储正确传递`updatesUrl`给更新程序?
Thank you in advance for your help.

with the following stack trace

    java.lang.NullPointerException
 com.install4j.runtime.installer.Application.runApplicationInProcess(Application.java:64)
com.install4j.runtime.installer.helper.apiimpl.ApplicationLauncherImpl$1.run(ApplicationLauncherImpl.java:57)

答案1

得分: 1

调用com.install4j.api.launcher.Variables.loadFromPreferenceStore不会设置安装程序变量,它会返回一个包含变量值的映射。这是为了在您的应用程序中使用而设计的。

您需要做的是在更新下载器的“启动”节点中添加一个“从Java首选项存储加载安装程序变量”的操作。这样,updatesUrl安装程序变量实际上会被设置为首选项存储中的值。

英文:

Calling com.install4j.api.launcher.Variables.loadFromPreferenceStore does not set installer variables, it returns a map with the variable values. This is intended for use in your application.

What you have to do is to add a "Load installer variables from the Java preference store" action to the "Startup" node in in the update downloader. In that way, the updatesUrl installer variable is actually set to the value from the preference store.

huangapple
  • 本文由 发表于 2020年7月30日 01:10:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63158908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定