fix(NotificationDownloadListener): Crash on no-installer forge versions

Fixes #282
This commit is contained in:
tomikun
2026-06-26 03:26:42 +08:00
parent 9fbdb7ebc2
commit a34e1f55ed

View File

@@ -14,19 +14,20 @@ import java.io.File;
public class NotificationDownloadListener implements ModloaderDownloadListener {
private final Context mContext;
private final Intent mIntent;
private final ModLoader mModLoader;
public NotificationDownloadListener(Context context, ModLoader modLoader) {
mModLoader = modLoader;
mContext = context.getApplicationContext();
mIntent = new Intent(mContext, LauncherActivity.class);
}
@Override
public void onDownloadFinished(File downloadedFile) {
if(mModLoader.requiresGuiInstallation()) {
ModloaderInstallTracker.saveModLoader(mContext, mModLoader, downloadedFile);
Intent mainActivityIntent = new Intent(mContext, LauncherActivity.class);
sendIntentNotification(mainActivityIntent, R.string.modpack_install_notification_success);
sendIntentNotification(R.string.modpack_install_notification_success);
}
}
@@ -40,11 +41,11 @@ public class NotificationDownloadListener implements ModloaderDownloadListener {
Tools.showErrorRemote(mContext, R.string.modpack_install_modloader_download_failed, e);
}
private void sendIntentNotification(Intent intent, int localeString) {
private void sendIntentNotification(int localeString) {
Tools.runOnUiThread(() -> NotificationUtils.sendBasicNotification(mContext,
R.string.modpack_install_notification_title,
localeString,
intent,
mIntent,
NotificationUtils.PENDINGINTENT_CODE_DOWNLOAD_SERVICE,
NotificationUtils.NOTIFICATION_ID_DOWNLOAD_LISTENER
));
@@ -54,7 +55,7 @@ public class NotificationDownloadListener implements ModloaderDownloadListener {
Tools.runOnUiThread(()->NotificationUtils.sendBasicNotification(mContext,
R.string.modpack_install_notification_title,
localeString,
null,
mIntent,
NotificationUtils.PENDINGINTENT_CODE_DOWNLOAD_SERVICE,
NotificationUtils.NOTIFICATION_ID_DOWNLOAD_LISTENER
));