Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly authored Aug 28, 2023
1 parent a797abc commit 5181a78
Show file tree
Hide file tree
Showing 76 changed files with 3,544 additions and 104 deletions.
12 changes: 12 additions & 0 deletions app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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 @@ -105,6 +116,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
Binary file not shown.
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 @@ -77,6 +77,11 @@ public void setSelection(int position){
mProfileAdapter.setViewProfile(this, (String) mProfileAdapter.getItem(position), false);
}

/** Reload profiles from the file, forcing the spinner to consider the new data */
public void reloadProfiles(){
mProfileAdapter.reloadProfiles();
}

/** Initialize various behaviors */
private void init(){
// Setup various attributes
Expand Down
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 @@ -322,24 +322,24 @@ private void runCraft(String versionId, JMinecraftVersionList.Version version) t
}
MinecraftAccount minecraftAccount = PojavProfile.getCurrentProfileContent(this, null);
Logger.appendToLog("--------- beginning with launcher debug");
printLauncherInfo(versionId);
printLauncherInfo(versionId, Tools.isValidString(minecraftProfile.javaArgs) ? minecraftProfile.javaArgs : LauncherPreferences.PREF_CUSTOM_JAVA_ARGS);
if (Tools.LOCAL_RENDERER.equals("vulkan_zink")) {
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);
}

private void printLauncherInfo(String gameVersion) {
private void printLauncherInfo(String gameVersion, String javaArguments) {
Logger.appendToLog("Info: Launcher version: " + BuildConfig.VERSION_NAME);
Logger.appendToLog("Info: Architecture: " + Architecture.archAsString(Tools.DEVICE_ARCHITECTURE));
Logger.appendToLog("Info: Device model: " + Build.MANUFACTURER + " " +Build.MODEL);
Logger.appendToLog("Info: API version: " + Build.VERSION.SDK_INT);
Logger.appendToLog("Info: Selected Minecraft version: " + gameVersion);
Logger.appendToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\"");
Logger.appendToLog("Info: Custom Java arguments: \"" + javaArguments + "\"");
}

private void checkVulkanZinkIsSupported() {
Expand Down Expand Up @@ -430,12 +430,12 @@ public void adjustMouseSpeedLive() {
sb.setMax(275);
tmpMouseSpeed = (int) ((LauncherPreferences.PREF_MOUSESPEED*100));
sb.setProgress(tmpMouseSpeed-25);
tv.setText(getString(R.string.percent_format, tmpGyroSensitivity));
tv.setText(getString(R.string.percent_format, tmpMouseSpeed));
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
tmpMouseSpeed = i+25;
tv.setText(getString(R.string.percent_format, tmpGyroSensitivity));
tv.setText(getString(R.string.percent_format, tmpMouseSpeed));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
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 5181a78

Please sign in to comment.