Search code examples
plistcydiatweak

How can I make a Cydia tweak that modifies files on install and reverts changes on uninstall?


I have been developing a Cydia tweak called BrightnessControl (I am very new to developing). For now, all it does is use Winterboard to patch var/stash/Applications/Brightness.plist with my modified version. Is there a way, maybe with Theos, that I can patch this file without Winterboard? I am wanting to back this file up somehow and replace it with my modified .plist upon imstall, and then upon un-install delete my modified .plist and restore the original .plist. I have seen something like this done with other tweaks, but I don't know how this is done. May anyone please push me in the right direction?


Solution

  • You don't even need to know programming to do this. The trick is inside the Debian packages' postinst and prerm scripts.

    Edit: as per @Nate's comments: beware, because these scripts also run upon updating a package. So, for example, a package with one update which is then removed would do this:

    1st installation:
    run preinst
    (APT installs your package)
    run postinst
    
    update:
    run prerm of the old version
    (APT removes old version)
    run postrm of old version
    
    run preinst of new version
    (APT installs new version)
    run postinst of new version
    
    removal:
    run prerm of new version
    (APT removes the new version... you no longer have the package)
    run postrm of new version