edvin / fxlauncher

Auto updating launcher for JavaFX Applications
Apache License 2.0
714 stars 110 forks source link

How to execute additional services during app update #116

Closed gabrielpaim closed 5 years ago

gabrielpaim commented 6 years ago

Hi there,

I'm trying to use fxlauncher for our application, but I need to execute a database migration (among other stuff) during the app update progress. The whole update should also work "atomically" - if the migration for some reason fails, the update should also fallback and the previous application version should stand. In other words, I'd like to execute some logic with conditional result before syncing files during the update procedure.

Have you guys ever thought about this? Has anyone faced something similar? Is there a way to still use FxLauncher for my app with this constraint?

Thank you, great job @edvin !

zemudkram commented 6 years ago

If I were to do something like that right now, I’d probably look at using the HeadlessMainLauncher, with a main class that performed the updates before launching the UI.

That might not be the most elegant solution though.

Cheers, Mark

On 16/05/2018, at 13:19, Gabriel Paim notifications@github.com wrote:

Hi there,

I'm trying to use fxlauncher for our application, but I need to execute a database migration (among other stuff) during the app update progress. The whole update should also work "atomically" - if the migration for some reason fails, the update should also fallback and the previous application version should stand. In other words, I'd like to execute some logic with conditional result before syncing files during the update procedure.

Have you guys ever thought about this? Has anyone faced something similar? Is there a way to still use FxLauncher for my app with this constraint?

Thank you, great job @edvin https://github.com/edvin !

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edvin/fxlauncher/issues/116, or mute the thread https://github.com/notifications/unsubscribe-auth/AKDGgYItc7-ozABZD5ts71w_u2e_71R0ks5ty5rEgaJpZM4UAlf6.

edvin commented 6 years ago

There is no support for that, so yeah, the HeadlessMainLauncher is probably your best bet. It would be possible to support a pre-update check, which would be allowed to download a jar and run a specific main method where you could perform the update and return false if no update should be done for example.

gabrielpaim commented 6 years ago

Alright, I'll take a look if this strategy is sufficient for my specific use case. I'll leave this open for a while, until I check that, ok?

Thank you!

edvin commented 6 years ago

Absolutely :)

gabrielpaim commented 6 years ago

Hi guys,

after understanding a bit better how does the launcher works, I managed to solve my problem this way:

The above steps made possible to insert specific logic inside the update flow (with the main method the same as in HeadlessMainLauncher):

protected void process() throws Exception {
    syncManifest();

    if (executeCustomTask()) {
        parameters = new LauncherParams(parameters, getManifest());
        checkSSLIgnoreflag();
        updateManifest();
        syncFiles();
    }

    createApplicationEnvironment();
    launchApp();
}

As I also want to show some UI during this process, I'm thinking in reusing some of the default Launcher code to do so. However, I didn't understand how exactly the HeadlessMainLauncher could help me in this task, tough. Am I missing anything?

Thanks again, great stuff here, guys, it's being very helpful! ;)