aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extensions-builtin/mobile/javascript/mobile.js26
-rw-r--r--modules/cache.py29
2 files changed, 52 insertions, 3 deletions
diff --git a/extensions-builtin/mobile/javascript/mobile.js b/extensions-builtin/mobile/javascript/mobile.js
new file mode 100644
index 00000000..12cae4b7
--- /dev/null
+++ b/extensions-builtin/mobile/javascript/mobile.js
@@ -0,0 +1,26 @@
+var isSetupForMobile = false;
+
+function isMobile() {
+ for (var tab of ["txt2img", "img2img"]) {
+ var imageTab = gradioApp().getElementById(tab + '_results');
+ if (imageTab && imageTab.offsetParent && imageTab.offsetLeft == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+function reportWindowSize() {
+ var currentlyMobile = isMobile();
+ if (currentlyMobile == isSetupForMobile) return;
+ isSetupForMobile = currentlyMobile;
+
+ for (var tab of ["txt2img", "img2img"]) {
+ var button = gradioApp().getElementById(tab + '_generate_box');
+ var target = gradioApp().getElementById(currentlyMobile ? tab + '_results' : tab + '_actions_column');
+ target.insertBefore(button, target.firstElementChild);
+ }
+}
+
+window.addEventListener("resize", reportWindowSize);
diff --git a/modules/cache.py b/modules/cache.py
index ddf44637..71fe6302 100644
--- a/modules/cache.py
+++ b/modules/cache.py
@@ -1,6 +1,7 @@
import json
import os.path
import threading
+import time
from modules.paths import data_path, script_path
@@ -8,15 +9,37 @@ cache_filename = os.path.join(data_path, "cache.json")
cache_data = None
cache_lock = threading.Lock()
+dump_cache_after = None
+dump_cache_thread = None
+
def dump_cache():
"""
- Saves all cache data to a file.
+ Marks cache for writing to disk. 5 seconds after no one else flags the cache for writing, it is written.
"""
+ global dump_cache_after
+ global dump_cache_thread
+
+ def thread_func():
+ global dump_cache_after
+ global dump_cache_thread
+
+ while dump_cache_after is not None and time.time() < dump_cache_after:
+ time.sleep(1)
+
+ with cache_lock:
+ with open(cache_filename, "w", encoding="utf8") as file:
+ json.dump(cache_data, file, indent=4)
+
+ dump_cache_after = None
+ dump_cache_thread = None
+
with cache_lock:
- with open(cache_filename, "w", encoding="utf8") as file:
- json.dump(cache_data, file, indent=4)
+ dump_cache_after = time.time() + 5
+ if dump_cache_thread is None:
+ dump_cache_thread = threading.Thread(name='cache-writer', target=thread_func)
+ dump_cache_thread.start()
def cache(subsection):