-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Why this exists
After installing the rather excellent dark theme, I was frustrated that updates temporarily broke the theme until JDownloader 2 was restarted again. So, I looked up the API calls, and created a script for the Event Scripter plugin to work around the bug. This Event Scripter script will check for updates periodically, apply them if JDownloader 2 if it is idle, and then automatically restart JDownloader2 again to fix the dark theme.
To use this, enable Event Scripter from Settings -> Plugins. Then, add a new script with an Interval trigger. Set the trigger to a much longer delay, enable synchronous execution by checking the box, and paste the script from below. Scroll down for detailed instructions.
/*
Name: Update and Re-Apply Theme
Version: 1.0.1
Author: https://github.com/andrewjmetzger
Description: Check for and apply updates periodically if JDownloader 2 is idle,
and then restart JDownloader 2 one more time to apply the dark theme properly.
Trigger Required: "Interval" (Recommended: 600000 (10 mins.) or more)
Synchronous execution: Yes (checked)
*/
if (
callAPI("update", "isUpdateAvailable") && // an update is available, and
!callAPI("linkcrawler", "isCrawling") && // LinkCrawler is idle, and
!callAPI("linkgrabberv2", "isCollecting") && // LinkGrabber is idle, and
!callAPI("extraction", "getQueue").length && // nothing is being extracted, then
isDownloadControllerIdle() // if no downloads are running...
) {
callAPI("update", "restartAndUpdate"); // Check for and apply an update, then
callAPI("system", "restartJD"); // restart JDownloader 2 again to fix the theme
}Headless users only -- here is the same script with no line breaks:
[ {
"eventTrigger" : "INTERVAL",
"enabled" : true,
"name" : "Update: Reapply Theme",
"script" : "/*\n Name: Update and Re-Apply Theme\n \n Version: 1.0.1\n \n Author: https://github.com/andrewjmetzger\n \n Description: Check for and apply updates periodically if JDownloader 2 is idle, \n and then restart JDownloader 2 one more time to apply the dark theme properly.\n \n Trigger Required: \"Interval\" (Recommended: 600000 (10 mins.) or more)\n \n Synchronous execution: Yes (checked)\n*/\n\nif (\n callAPI(\"update\", \"isUpdateAvailable\") && // an update is available, and\n !callAPI(\"linkcrawler\", \"isCrawling\") && // LinkCrawler is idle, and\n !callAPI(\"linkgrabberv2\", \"isCollecting\") && // LinkGrabber is idle, and\n !callAPI(\"extraction\", \"getQueue\").length && // nothing is being extracted, then\n isDownloadControllerIdle() // if no downloads are running...\n) {\n callAPI(\"update\", \"restartAndUpdate\"); // Check for and apply an update, then\n callAPI(\"system\", \"restartJD\"); // restart JDownloader 2 again to fix the theme\n}",
"eventTriggerSettings" : {
"lastFire" : 1616161911463,
"interval" : 600000,
"isSynchronous" : true
},
"id" : 1616156482823
} ]Detailed Instructions
IMPORTANT: For the first time run, you must allow the script to use the Interval permission. Afterwards, the script will run automatically.
- In the Event Scripter settings, click Add to create a blank script
- Give the script a name, such as
Update and Re-apply theme - Change the Trigger for the script to Interval
- Open the blank script by clicking Edit
- Change the script interval to something long, like
600000milliseconds (10 minutes) - Check the box to Enable Synchronous execution
- Copy the first block of code above, and paste it in the Editor
- Save the script, then in the Event Scripter list click Edit again.
- Click Test Compile, and dismiss the "Success" message. (Note: If you do not see "Success", make sure to copy/paste the whole script.)
- Click Test Run to display a permission dialog
- In the permission dialog, make sure to check Don't show this again, then click Allow
- To apply the new permissions and close the script editor, click Save
@Vinylwalk3r if you like this script and want to include it in the repo, the JSON "headless" script can be added to ./cfg/org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json under the JDownloader 2 installation directory. Note that this still requires the user to install and enable Event Scripter beforehand. Let me know and I'm happy to create a PR.
Hope this helps!
@andrewjmetzger
Changelog:
Version 1.0.1 - 2021-03-19:
- Updated informational comments
- Added top-level heading ("Why this exists")
Version 1.0.0 - 2021-03-19:
- Initial release