B4J Question B4J App Update - Idea from Discord Desktop App

hatzisn

Well-Known Member
Licensed User
Longtime User
Good morning everyone,

I am saying everyone but I think it is more suitable to direct this question to @Erel since he is the one to know how to handle this as he has created it. I recently joined the Discord of B4X and I downloaded the Desktop App and installed it. I found out that it starts automatically in each reboot. I did not want that so I started Task Manager to disable it in Startup. It was not there so I figured out that it was in Registry and I was right. Under the key "HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Run" there was this line:

B4X:
C:\Users\{PATH TO APPDATA LOCAL DISCORD FOLDER}\Update.exe --processStart Discord.exe

As I understand it it starts Update.exe which checks if there is a new update and if there is it downloads it and replaces the Discord.exe app and starts it, otherwise it starts it directly. So I am thinking to create the following procedure:

1) I package with B4J packager and I install in windows the app (this will work also in Linux but I believe not in MacOS since the notarization is needed)
2) I start the exe which starts the jar of the package (question - see later).
3) When the jar starts it checks firstly in the xui.DefaultFolder if there is a json file with the last update check date. If there is, if current date is the same, it continues and runs properly and this algorithm stops here. If there is not though or the last update date in this json is different than current date then it checks the following: it checks in the xui.DefaultFolder if there is a json file with the "current running jar" path and "current running jar" version and also if there is an "updater.jar" in this folder.
4) If none of these files exist in the xui.DefaultFolder it firstly creates the json and then downloads the "updater.jar" there
5) It executes "updater.jar" (question - see later) and immediately ends
6) When the "updater.jar" starts it checks if the on-line version is the same with the currently installed
7) If it is the same it just updates the last check date for update in the first json and starts again the Installed Application Jar (the one created with B4J packager - IAJ from now for the sake of brevity)
8) If it is not, the "updater.jar" downloads a zip with the new IAJ jar and unzips it in the folder it runs
9) Then it kills in the folder included in the second JSON the original IAJ and copies the downloaded jar to the original's IAJ place with a jShell command (which under windows will run as administrator as seen in the following message).


10) It saves in the second json the version number it downloaded
11) At last it starts the new IAJ (question - see immediately after) and immediately exits.


And now the question to @Erel: I suppose that the executable file ".exe" created by B4J packager it runs a shell command like "java -jar {IAJ name}.jar". Which command is this and how do I make it use the java components installed with the application in the package created?

Edit - the algorithm can change slightly by just running directly the jar it downloaded (or not) in the folder the "updater.jar" runs - also, here, how do I make it use the java components installed with the application in the package created?

Thanks
 
Last edited:
Top