Skip to content

Commit

Permalink
feat: add experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Oct 25, 2024
1 parent 2cd2357 commit a15a493
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions repo/plugin.video.midarr/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import json
import urllib.request
from urllib.parse import urlencode, parse_qsl
import xbmc
import threading
import time

# Get the plugin url in plugin:// notation.
URL = sys.argv[0]
Expand Down Expand Up @@ -333,6 +336,28 @@ def search():
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(HANDLE)

# Function to simulate a long-running task with a background progress bar
def simulate_long_task_bg():
# Create a background progress dialog
progress_dialog = xbmcgui.DialogProgressBG()
progress_dialog.create("Simulating Task in Background", "Working...")

for i in range(101): # Simulate progress from 0% to 100%
if progress_dialog.isFinished(): # Check if the progress should be canceled (optional)
progress_dialog.close()
return

progress_dialog.update(i, f"Progress: {i}%") # Update the progress bar
time.sleep(0.1) # Simulate work being done (100ms per step)

# Task finished, close the progress dialog
progress_dialog.close()
xbmcgui.Dialog().ok("Task Completed", "The task has been successfully completed!")

# Asynchronous wrapper to run the task in a separate thread
def run_task_async():
threading.Thread(target=simulate_long_task_bg).start()


def router(param_string):
# Parse a URL-encoded param_string to the dictionary of
Expand Down Expand Up @@ -375,6 +400,9 @@ def router(param_string):
elif params['action'] == 'search':
search()

elif params['action'] == 'experimental':
run_task_async()

else:
# If the provided param_string does not contain a supported action
# we raise an exception. This helps to catch coding errors,
Expand Down
2 changes: 1 addition & 1 deletion repo/plugin.video.midarr/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<group id="2">
<setting id="test33" type="action" label="30004">
<level>0</level>
<data>RunScript(script.globalsearch)</data>
<data>RunPlugin(plugin://plugin.video.midarr/?action=experimental)</data>
<control type="button" format="action">
<close>true</close>
</control>
Expand Down

0 comments on commit a15a493

Please sign in to comment.