Skip to content

Commit

Permalink
mod downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
SolDev69 committed Aug 23, 2023
1 parent e496e16 commit 5ba601e
Show file tree
Hide file tree
Showing 75 changed files with 18,309 additions and 86 deletions.
1 change: 1 addition & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-22.04
env:
GPLAY_KEYSTORE_PASSWORD: ${{ secrets.GPLAY_KEYSTORE_PASSWORD }}
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ app_pojavlauncher/src/main/assets/components/jre
local.properties
.idea/
app_pojavlauncher/.cxx/
.vs/
.vs/
/curseforge_key.txt
12 changes: 12 additions & 0 deletions app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ def getVersionName = {
return TAG_STRING.trim().replace("-g", "-") + "-" + BRANCH.toString().trim()
}

def getCFApiKey = {
String key = System.getenv("CURSEFORGE_API_KEY");
if(key != null) return key;
File curseforgeKeyFile = new File("./curseforge_key.txt");
if(curseforgeKeyFile.canRead() && curseforgeKeyFile.isFile()) {
return curseforgeKeyFile.text;
}
logger.warn('BUILD: You have no CurseForge key, the curseforge api will get disabled !');
return "DUMMY";
}

configurations {
instrumentedClasspath {
canBeConsumed = false
Expand Down Expand Up @@ -107,6 +118,7 @@ android {
versionCode getDateSeconds()
versionName getVersionName()
multiDexEnabled true //important
resValue 'string', 'curseforge_api_key', getCFApiKey()
}

buildTypes {
Expand Down
5 changes: 5 additions & 0 deletions app_pojavlauncher/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:name="android.hardware.type.pc"
android:required="false" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
Expand Down Expand Up @@ -77,11 +78,15 @@
android:name=".FatalErrorActivity"
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"
android:theme="@style/Theme.AppCompat.DayNight.Dialog" />
<activity android:name=".ShowErrorActivity"
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"
android:theme="@style/Theme.AppCompat.DayNight.Dialog" />
<activity
android:name=".ExitActivity"
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"
android:theme="@style/Theme.AppCompat.DayNight.Dialog" />
<activity
android:process=":gui_installer"
android:name=".JavaGUILauncherActivity"
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|keyboard|navigation|uiMode"
android:screenOrientation="sensorLandscape" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1688133008591
1692525087345
67 changes: 67 additions & 0 deletions app_pojavlauncher/src/main/java/com/kdt/SimpleArrayAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.kdt;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Collections;
import java.util.List;

/**
* Basic adapter, expect it uses the what is passed by the code, no the resources
* @param <T>
*/
public class SimpleArrayAdapter<T> extends BaseAdapter {
private List<T> mObjects;
public SimpleArrayAdapter(List<T> objects) {
setObjects(objects);
}

public void setObjects(@Nullable List<T> objects) {
if(objects == null){
if(mObjects != Collections.emptyList()) {
mObjects = Collections.emptyList();
notifyDataSetChanged();
}
} else {
if(objects != mObjects){
mObjects = objects;
notifyDataSetChanged();
}
}
}

@Override
public int getCount() {
return mObjects.size();
}

@Override
public T getItem(int position) {
return mObjects.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if(convertView == null){
convertView = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
}

TextView v = (TextView) convertView;
v.setText(mObjects.get(position).toString());
return v;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static boolean installNewJreIfNeeded(Activity activity, JMinecraftVersion
if (versionInfo.javaVersion == null || versionInfo.javaVersion.component.equalsIgnoreCase("jre-legacy"))
return true;

LauncherProfiles.update();
LauncherProfiles.load();
MinecraftProfile minecraftProfile = LauncherProfiles.getCurrentProfile();

String selectedRuntime = Tools.getSelectedRuntime(minecraftProfile);
Expand All @@ -71,15 +71,15 @@ public static boolean installNewJreIfNeeded(Activity activity, JMinecraftVersion
JRE17Util.checkInternalNewJre(activity.getAssets());
}
minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + appropriateRuntime;
LauncherProfiles.update();
LauncherProfiles.load();
} else {
if (versionInfo.javaVersion.majorVersion <= 17) { // there's a chance we have an internal one for this case
if (!JRE17Util.checkInternalNewJre(activity.getAssets())){
showRuntimeFail(activity, versionInfo);
return false;
} else {
minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + JRE17Util.NEW_JRE_NAME;
LauncherProfiles.update();
LauncherProfiles.load();
}
} else {
showRuntimeFail(activity, versionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import com.kdt.mcgui.ProgressLayout;
import com.kdt.mcgui.mcAccountSpinner;

import net.kdt.pojavlaunch.contextexecutor.ContextExecutor;
import net.kdt.pojavlaunch.fragments.MainMenuFragment;
import net.kdt.pojavlaunch.fragments.MicrosoftLoginFragment;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.extra.ExtraListener;

import net.kdt.pojavlaunch.fragments.SelectAuthFragment;
import net.kdt.pojavlaunch.modloaders.modpacks.ModloaderInstallTracker;
import net.kdt.pojavlaunch.modloaders.modpacks.imagecache.IconCacheJanitor;
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment;
Expand All @@ -53,6 +56,7 @@ public class LauncherActivity extends BaseActivity {
private ImageButton mSettingsButton, mDeleteAccountButton;
private ProgressLayout mProgressLayout;
private ProgressServiceKeeper mProgressServiceKeeper;
private ModloaderInstallTracker mInstallTracker;

/* Allows to switch from one button "type" to another */
private final FragmentManager.FragmentLifecycleCallbacks mFragmentCallbackListener = new FragmentManager.FragmentLifecycleCallbacks() {
Expand Down Expand Up @@ -152,6 +156,7 @@ public void onDownloadFailed(Throwable th) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pojav_launcher);
IconCacheJanitor.runJanitor();
getWindow().setBackgroundDrawable(null);
bindViews();
ProgressKeeper.addTaskCountListener((mProgressServiceKeeper = new ProgressServiceKeeper(this)));
Expand All @@ -167,13 +172,29 @@ protected void onCreate(Bundle savedInstanceState) {

new AsyncVersionList().getVersionList(versions -> ExtraCore.setValue(ExtraConstants.RELEASE_TABLE, versions), false);

mInstallTracker = new ModloaderInstallTracker(this);

mProgressLayout.observe(ProgressLayout.DOWNLOAD_MINECRAFT);
mProgressLayout.observe(ProgressLayout.UNPACK_RUNTIME);
mProgressLayout.observe(ProgressLayout.INSTALL_MODPACK);
mProgressLayout.observe(ProgressLayout.AUTHENTICATE_MICROSOFT);
mProgressLayout.observe(ProgressLayout.DOWNLOAD_VERSION_LIST);
}

@Override
protected void onResume() {
super.onResume();
ContextExecutor.setActivity(this);
mInstallTracker.attach();
}

@Override
protected void onPause() {
super.onPause();
ContextExecutor.clearActivity();
mInstallTracker.detach();
}

@Override
public boolean setFullscreen() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private void runCraft(String versionId, JMinecraftVersionList.Version version) t
checkVulkanZinkIsSupported();
}
JREUtils.redirectAndPrintJRELog();
LauncherProfiles.update();
LauncherProfiles.load();
int requiredJavaVersion = 8;
if(version.javaVersion != null) requiredJavaVersion = version.javaVersion.majorVersion;
Tools.launchMinecraft(this, minecraftAccount, minecraftProfile, versionId, requiredJavaVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import net.kdt.pojavlaunch.contextexecutor.ContextExecutor;
import net.kdt.pojavlaunch.tasks.AsyncAssetManager;
import net.kdt.pojavlaunch.utils.*;

Expand All @@ -27,6 +28,7 @@ public class PojavApplication extends Application {

@Override
public void onCreate() {
ContextExecutor.setApplication(this);
Thread.setDefaultUncaughtExceptionHandler((thread, th) -> {
boolean storagePermAllowed = (Build.VERSION.SDK_INT < 23 || Build.VERSION.SDK_INT >= 29 ||
ActivityCompat.checkSelfPermission(PojavApplication.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) && Tools.checkStorageRoot(PojavApplication.this);
Expand Down Expand Up @@ -78,8 +80,14 @@ public void onCreate() {
startActivity(ferrorIntent);
}
}

@Override

@Override
public void onTerminate() {
super.onTerminate();
ContextExecutor.clearApplication();
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(LocaleUtils.setLocale(base));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.kdt.pojavlaunch;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

import net.kdt.pojavlaunch.contextexecutor.ContextExecutorTask;
import net.kdt.pojavlaunch.value.NotificationConstants;

import java.io.Serializable;

public class ShowErrorActivity extends Activity {

private static final String ERROR_ACTIVITY_REMOTE_TASK = "remoteTask";

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if(intent == null) {
finish();
return;
}
RemoteErrorTask remoteErrorTask = (RemoteErrorTask) intent.getSerializableExtra(ERROR_ACTIVITY_REMOTE_TASK);
if(remoteErrorTask == null) {
finish();
return;
}
remoteErrorTask.executeWithActivity(this);
}


public static class RemoteErrorTask implements ContextExecutorTask, Serializable {
private final Throwable mThrowable;
private final String mRolledMsg;

public RemoteErrorTask(Throwable mThrowable, String mRolledMsg) {
this.mThrowable = mThrowable;
this.mRolledMsg = mRolledMsg;
}
@Override
public void executeWithActivity(Activity activity) {
Tools.showError(activity, mRolledMsg, mThrowable);
}

@Override
public void executeWithApplication(Context context) {
sendNotification(context, this);
}
}
private static void sendNotification(Context context, RemoteErrorTask remoteErrorTask) {

Intent showErrorIntent = new Intent(context, ShowErrorActivity.class);
showErrorIntent.putExtra(ERROR_ACTIVITY_REMOTE_TASK, remoteErrorTask);

PendingIntent pendingIntent = PendingIntent.getActivity(context, NotificationConstants.PENDINGINTENT_CODE_SHOW_ERROR, showErrorIntent,
Build.VERSION.SDK_INT >=23 ? PendingIntent.FLAG_IMMUTABLE : 0);

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, context.getString(R.string.notif_channel_id))
.setContentTitle(context.getString(R.string.notif_error_occured))
.setContentText(context.getString(R.string.notif_error_occured_desc))
.setSmallIcon(R.drawable.notif_icon)
.setContentIntent(pendingIntent);
notificationManager.notify(NotificationConstants.NOTIFICATION_ID_SHOW_ERROR, notificationBuilder.build());
}

}
Loading

0 comments on commit 5ba601e

Please sign in to comment.