|
30 | 30 | update_queue = queue.Queue() |
31 | 31 | is_closing = False |
32 | 32 | scanner_thread = None |
| 33 | +scanner_pause_event = threading.Event() |
33 | 34 | debug_scan_count = 0 |
34 | 35 |
|
35 | 36 | webview.settings["ALLOW_DOWNLOADS"] = True |
@@ -122,6 +123,9 @@ def get_supported_bands(): |
122 | 123 | def start_scanner(interval_ms: int) -> threading.Thread: |
123 | 124 | def loop(): |
124 | 125 | while not is_closing: |
| 126 | + if scanner_pause_event.is_set(): |
| 127 | + sleep(0.1) |
| 128 | + continue |
125 | 129 | try: |
126 | 130 | name, nws = scan() |
127 | 131 | update_queue.put((name, nws)) |
@@ -149,6 +153,8 @@ def to_series(nws): |
149 | 153 | def update(window, supported_bands): |
150 | 154 | if is_closing: |
151 | 155 | return |
| 156 | + if scanner_pause_event.is_set(): |
| 157 | + return |
152 | 158 |
|
153 | 159 | try: |
154 | 160 | # If there are multiple queued updates, take the most recent snapshot |
@@ -248,6 +254,19 @@ def show_dialog(self): |
248 | 254 | AppKit.NSApplication.sharedApplication().terminate_(None) |
249 | 255 |
|
250 | 256 |
|
| 257 | +class Api: |
| 258 | + def pause_scan(self): |
| 259 | + scanner_pause_event.set() |
| 260 | + return {"paused": True} |
| 261 | + |
| 262 | + def resume_scan(self): |
| 263 | + scanner_pause_event.clear() |
| 264 | + return {"paused": False} |
| 265 | + |
| 266 | + def get_scan_state(self): |
| 267 | + return {"paused": scanner_pause_event.is_set()} |
| 268 | + |
| 269 | + |
251 | 270 | def request_location_permission(): |
252 | 271 | location_manager = CoreLocation.CLLocationManager.alloc().init().retain() |
253 | 272 | delegate = LocationManagerDelegate.alloc().init().retain() |
@@ -276,7 +295,7 @@ def main(): |
276 | 295 | AppKit.NSApplication.sharedApplication().activateIgnoringOtherApps_(True) |
277 | 296 |
|
278 | 297 | index_html = os.path.join(os.path.dirname(__file__), "view/index.html") |
279 | | - window = webview.create_window("Tiny Wi-Fi Analyzer", index_html) |
| 298 | + window = webview.create_window("Tiny Wi-Fi Analyzer", index_html, js_api=Api()) |
280 | 299 | window.events.closing += on_closing |
281 | 300 | window.events.loaded += setup_client |
282 | 301 | webview.start(startup, window, debug=True) |
|
0 commit comments