Question

I created my first flipswitch today using theos.

The switch edit a .plist file of a tweak to turn it on

the switch works and turn the tweak on but in order for the tweak to take effect on the application, the application must be relaunched

so i need to make the switch kill a specific application everytime its turned on and off

Btw i'm new to objective-c and your help is much appreciated, Thanks!

my switch.x

#import "FSSwitchDataSource.h"
#import "FSSwitchPanel.h"
#import <notify.h>
static NSString * const PREF_PATH = @"/var/mobile/Library/Preferences/file.plist";
static NSString * const kSwitchKey = @"enabled";


@interface waplastseenSwitch : NSObject <FSSwitchDataSource>
@end

@implementation waplastseenSwitch

- (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier
{
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
    id existEnable = [dict objectForKey:kSwitchKey];
    BOOL isenabled = existEnable ? [existEnable boolValue] : YES;
    return isenabled ? FSSwitchStateOn : FSSwitchStateOff;
}

- (void)applyState:(FSSwitchState)newState forSwitchIdentifier:(NSString *)switchIdentifier
{
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
    NSMutableDictionary *mutableDict = dict ? [[dict mutableCopy] autorelease] : [NSMutableDictionary dictionary];
    switch (newState) {
        case FSSwitchStateIndeterminate:
            return;
        case FSSwitchStateOn:
            [mutableDict setValue:@YES forKey:kSwitchKey];
            break;
        case FSSwitchStateOff:
            [mutableDict setValue:@NO forKey:kSwitchKey];
            break;
    }
    [mutableDict writeToFile:PREF_PATH atomically:YES];
    notify_post("Flipswitch.settingschanged");
}

@end
Was it helpful?

Solution

i solve it by using

 system("killall -9 AppName");

like this

case FSSwitchStateOn:
    [mutableDict setValue:@YES forKey:kSwitchKey];
     system("killall -9 AppName");
    break;
case FSSwitchStateOff:
    [mutableDict setValue:@NO forKey:kSwitchKey];
    system("killall -9 AppName");
    break;

Cheers!

OTHER TIPS

Sorry, I am not allowed to comment so I had to ask this in an answer. What is your hook code? I only ask because you shouldn't need to restart the app for your tweak to work.

Make sure the hooked code checks the plist at each stage rather than just at app launch.

So test at each method you are hooking whether or not to run your code.

If your tweak relies on something in startup, maybe store this value in memory so if you decide to turn on your tweak, you have what you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top