Skip to content

Commit

Permalink
Added macOS Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
willpill committed Oct 21, 2023
1 parent 49b9b60 commit 24afa2d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
2 changes: 2 additions & 0 deletions platform/mac/mac.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ tasks.register('exportMacX64', Copy.class) {
into('Resources') {
from file('platform/mac/' + appIcon) rename(appIcon, 'mcreatorapp.icns')
from file('platform/mac/' + icon) rename(icon, 'mcreator.icns')
from file('platform/mac/macOSUpdater.jar')
}
into('MacOS') {
from file('platform/mac/mcreator_x64') rename('mcreator_x64', 'mcreator')
Expand Down Expand Up @@ -111,6 +112,7 @@ tasks.register('exportMacAarch64', Copy.class) {
into('Resources') {
from file('platform/mac/' + appIcon) rename(appIcon, 'mcreatorapp.icns')
from file('platform/mac/' + icon) rename(icon, 'mcreator.icns')
from file('platform/mac/macOSUpdater.jar')
}
into('MacOS') {
from file('platform/mac/mcreator_aarch64') rename('mcreator_aarch64', 'mcreator')
Expand Down
Binary file added platform/mac/macOSUpdater.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions plugins/mcreator-localization/lang/texts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,15 @@ dialog.unsaved_changes.message=<html>There may be unsaved changes of this mod el
dialog.unsaved_changes.title=Unsaved changes
dialog.update_notify.message=<html><font size=5>You are using an outdated version of MCreator</font><br>Consider updating your MCreator to get the latest features and bug fixes!<br><br>Your version: {0} <br>The latest version: <b>{1}</b><br><br>Changelog of the latest releases:<br>
dialog.update_notify.update_title=MCreator update
dialog.update_notify.more_recent_build=<html><font size=5>There is a more recent build for version {0} available</font><br>Consider <b>re-downloading the current version</b> to get the latest features and bug fixes!<br><br>Your build number: {1}<br>The latest build number: <b>{2} </b><br><br>Changelog of {3} builds:<br>
dialog.update_notify.more_recent_build=<html><font size=5>There is a more recent build for version {0} available</font><br>Consider <b>updating now</b> to get the latest features and bug fixes!<br><br>Your build number: {1}<br>The latest build number: <b>{2} </b><br><br>Changelog of {3} builds:<br>
dialog.update_notify.error_failed_check_internet_message=Failed to check for updates. Reason: no internet
dialog.update_notify.error_failed_check_internet_title=No internet
dialog.update_notify.no_update_message=You have the latest version of MCreator installed!
dialog.update_notify.no_pluin_update_message=There are no plugin updates available at this time!
dialog.update_notify.no_update_title=No updates
dialog.update_notify.open_download_page=Open download page
dialog.update_notify.learn_more=Learn More
dialog.update_notify.remind_later=Remind me later
dialog.update_notify.update_now=Update Now
dialog.plugin_update_notify.message=MCreator detected the following plugins can be updated:
dialog.plugin_update_notify.update=Update plugin
dialog.plugin_update_notify.close=Close this window
Expand Down
61 changes: 50 additions & 11 deletions src/main/java/net/mcreator/ui/dialogs/UpdateNotifyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package net.mcreator.ui.dialogs;

import net.mcreator.io.OS;
import net.mcreator.Launcher;
import net.mcreator.io.net.api.update.Release;
import net.mcreator.io.net.api.update.UpdateInfo;
Expand All @@ -28,15 +29,19 @@
import net.mcreator.ui.laf.MCreatorTheme;
import net.mcreator.util.DesktopUtils;
import net.mcreator.util.MCreatorVersionNumber;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nullable;
import javax.swing.*;
import javax.swing.text.DefaultCaret;
import java.awt.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class UpdateNotifyDialog {
private static final Logger LOG = LogManager.getLogger("Updater");

public static void showUpdateDialogIfUpdateExists(Window parent, boolean notifyForUpdates, boolean notifyForPatches,
boolean showNoUpdates) {
Expand Down Expand Up @@ -64,12 +69,29 @@ public static void showUpdateDialogIfUpdateExists(Window parent, boolean notifyF

ar.setText(fullChangelog(updateInfo));

Object[] options = { L10N.t("dialog.update_notify.open_download_page"),
L10N.t("dialog.update_notify.remind_later") };
int option = JOptionPane.showOptionDialog(parent, pan, L10N.t("dialog.update_notify.update_title"),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (option == 0) {
Object[] options = {
L10N.t("dialog.update_notify.update_now"),
L10N.t("dialog.update_notify.learn_more"),
L10N.t("dialog.update_notify.remind_later"),
};
int option = JOptionPane.showOptionDialog(parent, pan,
L10N.t("dialog.update_notify.update_title"),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);

if (option == 1) {
DesktopUtils.browseSafe(MCreatorApplication.SERVER_DOMAIN + "/download#update");
} else if (option == 0) {
if (OS.getOS() == OS.MAC) {
try {
Runtime.getRuntime().exec("./jdk.bundle/Contents/Home/bin/java -jar ./Resources/macOSUpdater.jar");
System.exit(0);
} catch (IOException e) {
LOG.error("Failed to launch updater for macOS");
}
} else {
DesktopUtils.browseSafe(MCreatorApplication.SERVER_DOMAIN + "/download#update");
}
}
} else if (updateInfo.isNewPatchAvailable() && notifyForPatches) {
JPanel pan = new JPanel(new BorderLayout());
Expand All @@ -94,12 +116,29 @@ public static void showUpdateDialogIfUpdateExists(Window parent, boolean notifyF
ar.setText(releaseChangelog(updateInfo.getReleases().get(Launcher.version.major).getBuilds(),
Launcher.version.buildlong));

Object[] options = { L10N.t("dialog.update_notify.open_download_page"),
L10N.t("dialog.update_notify.remind_later") };
int option = JOptionPane.showOptionDialog(parent, pan, L10N.t("dialog.update_notify.update_title"),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (option == 0) {
DesktopUtils.browseSafe(MCreatorApplication.SERVER_DOMAIN + "/download#updatebuild");
Object[] options = {
L10N.t("dialog.update_notify.update_now"),
L10N.t("dialog.update_notify.learn_more"),
L10N.t("dialog.update_notify.remind_later"),
};
int option = JOptionPane.showOptionDialog(parent, pan,
L10N.t("dialog.update_notify.update_title"),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);

if (option == 1) {
DesktopUtils.browseSafe(MCreatorApplication.SERVER_DOMAIN + "/download#update");
} else if (option == 0) {
if (OS.getOS() == OS.MAC) {
try {
Runtime.getRuntime().exec("./jdk.bundle/Contents/Home/bin/java -jar ./Resources/macOSUpdater.jar");
System.exit(0);
} catch (IOException e) {
LOG.error("Failed to launch updater for macOS");
}
} else {
DesktopUtils.browseSafe(MCreatorApplication.SERVER_DOMAIN + "/download#update");
}
}
} else if (showNoUpdates) {
JOptionPane.showMessageDialog(parent, L10N.t("dialog.update_notify.no_update_message"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static <T extends Window & INotificationConsumer> void handleUpdatesCore
updateInfo.getLatestMajor()),
new NotificationsRenderer.ActionButton(L10N.t("notification.common.more_info"),
e -> UpdateNotifyDialog.showUpdateDialogIfUpdateExists(parent, true, false, false)),
new NotificationsRenderer.ActionButton(L10N.t("dialog.update_notify.open_download_page"),
new NotificationsRenderer.ActionButton(L10N.t("dialog.update_notify.learn_more"),
e -> DesktopUtils.browseSafe(
MCreatorApplication.SERVER_DOMAIN + "/download#update")));
}
Expand All @@ -85,7 +85,7 @@ private static <T extends Window & INotificationConsumer> void handleUpdatesCore
updateInfo.getLatestPatchVersion()),
new NotificationsRenderer.ActionButton(L10N.t("notification.common.more_info"),
e -> UpdateNotifyDialog.showUpdateDialogIfUpdateExists(parent, false, true, false)),
new NotificationsRenderer.ActionButton(L10N.t("dialog.update_notify.open_download_page"),
new NotificationsRenderer.ActionButton(L10N.t("dialog.update_notify.learn_more"),
e -> DesktopUtils.browseSafe(
MCreatorApplication.SERVER_DOMAIN + "/download#updatebuild")));
}
Expand Down

0 comments on commit 24afa2d

Please sign in to comment.