Workaround: Remove the temp account system

Note: The newer system won't need it. It still displays an error on first login.
This commit is contained in:
Boulay Mathias 2022-11-03 22:27:59 +01:00
parent 8e8d40ffe0
commit 631f84ab17
4 changed files with 15 additions and 44 deletions

View File

@ -145,10 +145,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity
// Try to load the temporary account // Try to load the temporary account
final List<String> accountList = new ArrayList<>(); final List<String> accountList = new ArrayList<>();
final MinecraftAccount tempProfile = PojavProfile.getTempProfileContent();
if (tempProfile != null) {
accountList.add(tempProfile.username);
}
for (String s : new File(Tools.DIR_ACCOUNT_NEW).list()) { for (String s : new File(Tools.DIR_ACCOUNT_NEW).list()) {
accountList.add(s.substring(0, s.length() - 5)); accountList.add(s.substring(0, s.length() - 5));
} }
@ -159,26 +156,19 @@ public class PojavLauncherActivity extends BaseLauncherActivity
adapterAcc.setDropDownViewResource(android.R.layout.simple_list_item_single_choice); adapterAcc.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
accountSelector.setAdapter(adapterAcc); accountSelector.setAdapter(adapterAcc);
if (tempProfile != null) { for (int i = 0; i < accountList.size(); i++) {
accountSelector.setSelection(0); String account = accountList.get(i);
} else { if (account.equals(mProfile.username)) {
for (int i = 0; i < accountList.size(); i++) { accountSelector.setSelection(i);
String account = accountList.get(i);
if (account.equals(mProfile.username)) {
accountSelector.setSelection(i);
}
} }
} }
accountSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ accountSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override @Override
public void onItemSelected(AdapterView<?> p1, View p2, int position, long p4) { public void onItemSelected(AdapterView<?> p1, View p2, int position, long p4) {
if (tempProfile != null && position == 0) { PojavProfile.setCurrentProfile(PojavLauncherActivity.this, accountList.get(position));
PojavProfile.setCurrentProfile(PojavLauncherActivity.this, tempProfile);
} else {
PojavProfile.setCurrentProfile(PojavLauncherActivity.this,
accountList.get(position + (tempProfile != null ? 1 : 0)));
}
pickAccount(); pickAccount();
} }

View File

@ -696,7 +696,7 @@ public class PojavLoginActivity extends BaseActivity {
profileName = mProfile.save(); profileName = mProfile.save();
} }
PojavProfile.launch(PojavLoginActivity.this, profileName == null ? mProfile : profileName); PojavProfile.launch(PojavLoginActivity.this, profileName);
} catch (IOException e) { } catch (IOException e) {
Tools.showError(this, e); Tools.showError(this, e);
} }

View File

@ -11,7 +11,6 @@ import androidx.annotation.Nullable;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.UUID;
import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener; import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener;
import net.kdt.pojavlaunch.authenticator.mojang.RefreshTokenTask; import net.kdt.pojavlaunch.authenticator.mojang.RefreshTokenTask;
@ -70,24 +69,17 @@ public class PojavProfile {
return name; return name;
} }
public static boolean setCurrentProfile(Context ctx, Object obj) { public static boolean setCurrentProfile(@NonNull Context ctx, @Nullable Object obj) {
SharedPreferences.Editor pref = getPrefs(ctx).edit(); SharedPreferences.Editor pref = getPrefs(ctx).edit();
try { try { if (obj instanceof String) {
if (obj instanceof MinecraftAccount) {
try {
MinecraftAccount.saveTempAccount((MinecraftAccount) obj);
} catch (IOException e) {
Tools.showError(ctx, e);
}
} else if (obj instanceof String) {
String acc = (String) obj; String acc = (String) obj;
pref.putString(PROFILE_PREF_FILE, acc); pref.putString(PROFILE_PREF_FILE, acc);
MinecraftAccount.clearTempAccount(); //MinecraftAccount.clearTempAccount();
} else if (obj == null) { } else if (obj == null) {
pref.putString(PROFILE_PREF_FILE, ""); pref.putString(PROFILE_PREF_FILE, "");
} else { } else {
throw new IllegalArgumentException("Profile must be MinecraftAccount.class, String.class or null"); throw new IllegalArgumentException("Profile must be String.class or null");
} }
} finally { } finally {
return pref.commit(); return pref.commit();
@ -99,8 +91,8 @@ public class PojavProfile {
} }
public static void launch(Activity ctx, Object o) { public static void launch(Activity ctx, String accountName) {
PojavProfile.setCurrentProfile(ctx, o); PojavProfile.setCurrentProfile(ctx, accountName);
LauncherProfiles.update(); LauncherProfiles.update();
if(!LauncherProfiles.mainProfileJson.profilesWereMigrated && LauncherProfiles.mainProfileJson.profiles != null) { if(!LauncherProfiles.mainProfileJson.profilesWereMigrated && LauncherProfiles.mainProfileJson.profiles != null) {
MinecraftProfile defaultProfile = LauncherProfiles.mainProfileJson.profiles.get("(Default)"); MinecraftProfile defaultProfile = LauncherProfiles.mainProfileJson.profiles.get("(Default)");

View File

@ -100,15 +100,4 @@ public class MinecraftAccount {
private static boolean accountExists(String username){ private static boolean accountExists(String username){
return new File(Tools.DIR_ACCOUNT_NEW + "/" + username + ".json").exists(); return new File(Tools.DIR_ACCOUNT_NEW + "/" + username + ".json").exists();
} }
public static void clearTempAccount() {
File tempAccFile = new File(Tools.DIR_DATA, "cache/tempacc.json");
tempAccFile.delete();
}
public static void saveTempAccount(MinecraftAccount acc) throws IOException {
File tempAccFile = new File(Tools.DIR_DATA, "cache/tempacc.json");
tempAccFile.delete();
acc.save(tempAccFile.getAbsolutePath());
}
} }