TrollStore/PersistenceHelper/TSPHRootViewController.m

160 lines
5.1 KiB
Mathematica
Raw Normal View History

2022-09-02 23:19:48 +08:00
#import "TSPHRootViewController.h"
#import "../Helper/Shared.h"
#import "../Store/TSUtil.h"
@implementation TSPHRootViewController
2022-09-22 23:38:58 +08:00
- (BOOL)isTrollStore
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
return NO;
2022-09-02 23:19:48 +08:00
}
2022-09-22 23:38:58 +08:00
- (void)viewDidLoad
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadSpecifiers) name:UIApplicationWillEnterForegroundNotification object:nil];
2022-09-02 23:19:48 +08:00
2022-09-22 23:38:58 +08:00
fetchLatestTrollStoreVersion(^(NSString* latestVersion)
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
NSString* currentVersion = [self getTrollStoreVersion];
NSComparisonResult result = [currentVersion compare:latestVersion options:NSNumericSearch];
if(result == NSOrderedAscending)
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
_newerVersion = latestVersion;
dispatch_async(dispatch_get_main_queue(), ^
{
[self reloadSpecifiers];
});
2022-09-02 23:19:48 +08:00
}
2022-09-22 23:38:58 +08:00
});
2022-09-02 23:19:48 +08:00
}
- (NSMutableArray*)specifiers
{
if(!_specifiers)
{
_specifiers = [NSMutableArray new];
PSSpecifier* infoGroupSpecifier = [PSSpecifier emptyGroupSpecifier];
infoGroupSpecifier.name = @"Info";
[_specifiers addObject:infoGroupSpecifier];
PSSpecifier* infoSpecifier = [PSSpecifier preferenceSpecifierNamed:@"TrollStore"
target:self
set:nil
get:@selector(getTrollStoreInfoString)
detail:nil
cell:PSTitleValueCell
edit:nil];
infoSpecifier.identifier = @"info";
[infoSpecifier setProperty:@YES forKey:@"enabled"];
[_specifiers addObject:infoSpecifier];
2022-09-22 23:38:58 +08:00
BOOL isInstalled = trollStoreAppPath();
if(_newerVersion && isInstalled)
{
// Update TrollStore
PSSpecifier* updateTrollStoreSpecifier = [PSSpecifier preferenceSpecifierNamed:[NSString stringWithFormat:@"Update TrollStore to %@", _newerVersion]
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
updateTrollStoreSpecifier.identifier = @"updateTrollStore";
[updateTrollStoreSpecifier setProperty:@YES forKey:@"enabled"];
updateTrollStoreSpecifier.buttonAction = @selector(updateTrollStorePressed);
[_specifiers addObject:updateTrollStoreSpecifier];
}
2022-09-02 23:19:48 +08:00
PSSpecifier* utilitiesGroupSpecifier = [PSSpecifier emptyGroupSpecifier];
[_specifiers addObject:utilitiesGroupSpecifier];
2022-09-22 23:38:58 +08:00
if(isInstalled)
2022-09-02 23:19:48 +08:00
{
PSSpecifier* refreshAppRegistrationsSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Refresh App Registrations"
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
refreshAppRegistrationsSpecifier.identifier = @"refreshAppRegistrations";
[refreshAppRegistrationsSpecifier setProperty:@YES forKey:@"enabled"];
2022-09-22 23:38:58 +08:00
refreshAppRegistrationsSpecifier.buttonAction = @selector(refreshAppRegistrationsPressed);
2022-09-02 23:19:48 +08:00
[_specifiers addObject:refreshAppRegistrationsSpecifier];
2022-09-04 06:48:40 +08:00
PSSpecifier* uninstallTrollStoreSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Uninstall TrollStore"
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
uninstallTrollStoreSpecifier.identifier = @"uninstallTrollStore";
[uninstallTrollStoreSpecifier setProperty:@YES forKey:@"enabled"];
[uninstallTrollStoreSpecifier setProperty:NSClassFromString(@"PSDeleteButtonCell") forKey:@"cellClass"];
uninstallTrollStoreSpecifier.buttonAction = @selector(uninstallTrollStorePressed);
[_specifiers addObject:uninstallTrollStoreSpecifier];
2022-09-02 23:19:48 +08:00
}
else
{
PSSpecifier* installTrollStoreSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Install TrollStore"
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
installTrollStoreSpecifier.identifier = @"installTrollStore";
[installTrollStoreSpecifier setProperty:@YES forKey:@"enabled"];
installTrollStoreSpecifier.buttonAction = @selector(installTrollStorePressed);
[_specifiers addObject:installTrollStoreSpecifier];
}
if(![NSBundle.mainBundle.bundleIdentifier hasPrefix:@"com.opa334."])
{
[_specifiers addObject:[PSSpecifier emptyGroupSpecifier]];
PSSpecifier* uninstallPersistenceHelperSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Uninstall Persistence Helper"
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
uninstallPersistenceHelperSpecifier.identifier = @"uninstallPersistenceHelper";
[uninstallPersistenceHelperSpecifier setProperty:@YES forKey:@"enabled"];
[uninstallPersistenceHelperSpecifier setProperty:NSClassFromString(@"PSDeleteButtonCell") forKey:@"cellClass"];
uninstallPersistenceHelperSpecifier.buttonAction = @selector(uninstallPersistenceHelperPressed);
[_specifiers addObject:uninstallPersistenceHelperSpecifier];
}
}
[(UINavigationItem *)self.navigationItem setTitle:@"TrollStore Helper"];
return _specifiers;
}
- (NSString*)getTrollStoreInfoString
{
2022-09-22 23:38:58 +08:00
NSString* version = [self getTrollStoreVersion];
if(!version)
2022-09-02 23:19:48 +08:00
{
return @"Not Installed";
}
else
{
return [NSString stringWithFormat:@"Installed, %@", version];
}
}
2022-09-22 23:38:58 +08:00
- (void)handleUninstallation
2022-09-04 06:48:40 +08:00
{
2022-09-22 23:38:58 +08:00
_newerVersion = nil;
[super handleUninstallation];
2022-09-02 23:19:48 +08:00
}
@end