avoid sessions without instance info

This commit is contained in:
sk 2023-05-29 02:40:02 +02:00
parent 31d22bac47
commit c80afaf9c0
2 changed files with 12 additions and 0 deletions

View File

@ -52,6 +52,12 @@ public class MainActivity extends FragmentStackActivity{
}else{
session=AccountSessionManager.getInstance().getLastActiveAccount();
}
if (session.getInstance() == null) {
// i don't know how, but i ended up having a session, but no instance info.
// removing account to avoid glitched behavior and crashes
AccountSessionManager.getInstance().removeAccount(session.getID());
session=AccountSessionManager.getInstance().getLastActiveAccount();
}
args.putString("account", session.getID());
Fragment fragment=session.activated ? new HomeFragment() : new AccountActivationFragment();
fragment.setArguments(args);

View File

@ -110,6 +110,12 @@ public class AccountSessionManager{
sessions.put(session.getID(), session);
lastActiveAccountID=session.getID();
writeAccountsFile();
// write initial instance info to file immediately to avoid sessions without instance info
InstanceInfoStorageWrapper wrapper = new InstanceInfoStorageWrapper();
wrapper.instance = instance;
MastodonAPIController.runInBackground(()->writeInstanceInfoFile(wrapper, instance.uri));
updateMoreInstanceInfo(instance, instance.uri);
if(PushSubscriptionManager.arePushNotificationsAvailable()){
session.getPushSubscriptionManager().registerAccountForPush(null);