pyloid 0.23.8__py3-none-any.whl → 0.23.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyloid/browser_window.py +17 -2
- pyloid/pyloid.py +11 -9
- pyloid/rpc.py +47 -7
- {pyloid-0.23.8.dist-info → pyloid-0.23.10.dist-info}/METADATA +1 -1
- {pyloid-0.23.8.dist-info → pyloid-0.23.10.dist-info}/RECORD +7 -7
- {pyloid-0.23.8.dist-info → pyloid-0.23.10.dist-info}/LICENSE +0 -0
- {pyloid-0.23.8.dist-info → pyloid-0.23.10.dist-info}/WHEEL +0 -0
pyloid/browser_window.py
CHANGED
@@ -42,6 +42,7 @@ from PySide6.QtWebEngineCore import (
|
|
42
42
|
QWebEngineSettings,
|
43
43
|
QWebEngineDesktopMediaRequest,
|
44
44
|
)
|
45
|
+
import threading
|
45
46
|
|
46
47
|
# from .url_interceptor import CustomUrlInterceptor
|
47
48
|
from .rpc import PyloidRPC
|
@@ -346,8 +347,22 @@ class _BrowserWindow:
|
|
346
347
|
self.shortcuts = {}
|
347
348
|
self.close_on_load = True
|
348
349
|
self.splash_screen = None
|
349
|
-
###########################################################################################
|
350
|
-
|
350
|
+
###########################################################################################
|
351
|
+
# RPC 서버가 없으면 추가하지 않음
|
352
|
+
if not self.rpc:
|
353
|
+
return;
|
354
|
+
|
355
|
+
# RPC 서버 중복 방지
|
356
|
+
if self.rpc in self.app.rpc_servers:
|
357
|
+
return;
|
358
|
+
|
359
|
+
# RPC 서버 추가
|
360
|
+
self.app.rpc_servers.add(self.rpc)
|
361
|
+
|
362
|
+
# Start unique RPC servers
|
363
|
+
server_thread = threading.Thread(target=self.rpc.start, daemon=True)
|
364
|
+
server_thread.start()
|
365
|
+
|
351
366
|
def _set_custom_frame(
|
352
367
|
self,
|
353
368
|
use_custom: bool,
|
pyloid/pyloid.py
CHANGED
@@ -160,6 +160,8 @@ class _Pyloid(QApplication):
|
|
160
160
|
self.styleHints().colorSchemeChanged.connect(self._handle_color_scheme_change)
|
161
161
|
|
162
162
|
self.dirs = PlatformDirs(self.app_name, appauthor=False)
|
163
|
+
|
164
|
+
self.rpc_servers: Set[PyloidRPC] = set()
|
163
165
|
|
164
166
|
# def set_theme(self, theme: Literal["system", "dark", "light"]):
|
165
167
|
# """
|
@@ -328,16 +330,16 @@ class _Pyloid(QApplication):
|
|
328
330
|
```
|
329
331
|
"""
|
330
332
|
|
331
|
-
# Collect and deduplicate RPC servers
|
332
|
-
rpc_servers: Set[PyloidRPC] = set()
|
333
|
-
for window in self.windows_dict.values():
|
334
|
-
|
335
|
-
|
333
|
+
# # Collect and deduplicate RPC servers
|
334
|
+
# rpc_servers: Set[PyloidRPC] = set()
|
335
|
+
# for window in self.windows_dict.values():
|
336
|
+
# if window._window.rpc is not None:
|
337
|
+
# rpc_servers.add(window._window.rpc)
|
336
338
|
|
337
|
-
#
|
338
|
-
for rpc in rpc_servers:
|
339
|
-
|
340
|
-
|
339
|
+
# # Start unique RPC servers
|
340
|
+
# for rpc in rpc_servers:
|
341
|
+
# server_thread = threading.Thread(target=rpc.start, daemon=True)
|
342
|
+
# server_thread.start()
|
341
343
|
|
342
344
|
|
343
345
|
if is_production():
|
pyloid/rpc.py
CHANGED
@@ -1,18 +1,38 @@
|
|
1
1
|
import asyncio
|
2
2
|
import json
|
3
3
|
import logging
|
4
|
+
import inspect
|
4
5
|
from functools import wraps
|
5
6
|
from typing import Any, Callable, Coroutine, Dict, List, Optional, Union
|
6
7
|
from .utils import get_free_port
|
7
8
|
from aiohttp import web
|
8
9
|
import threading
|
9
10
|
import time
|
10
|
-
import aiohttp_cors
|
11
|
+
import aiohttp_cors
|
12
|
+
from typing import TYPE_CHECKING
|
13
|
+
if TYPE_CHECKING:
|
14
|
+
from .pyloid import Pyloid
|
15
|
+
from .browser_window import BrowserWindow
|
11
16
|
|
12
17
|
# Configure logging
|
13
18
|
logging.basicConfig(level=logging.INFO)
|
14
19
|
log = logging.getLogger("pyloid.rpc")
|
15
20
|
|
21
|
+
class RPCContext:
|
22
|
+
"""
|
23
|
+
Class that provides context information when calling RPC methods.
|
24
|
+
|
25
|
+
Attributes
|
26
|
+
----------
|
27
|
+
pyloid : Pyloid
|
28
|
+
Pyloid application instance.
|
29
|
+
window : BrowserWindow
|
30
|
+
Current browser window instance.
|
31
|
+
"""
|
32
|
+
def __init__(self, pyloid: "Pyloid", window: "BrowserWindow"):
|
33
|
+
self.pyloid: "Pyloid" = pyloid
|
34
|
+
self.window: "BrowserWindow" = window
|
35
|
+
|
16
36
|
class RPCError(Exception):
|
17
37
|
"""
|
18
38
|
Custom exception for RPC-related errors.
|
@@ -109,6 +129,9 @@ class PyloidRPC:
|
|
109
129
|
self._functions: Dict[str, Callable[..., Coroutine[Any, Any, Any]]] = {}
|
110
130
|
self._app = web.Application()
|
111
131
|
|
132
|
+
self.pyloid: Optional["Pyloid"] = None
|
133
|
+
self.window: Optional["BrowserWindow"] = None
|
134
|
+
|
112
135
|
# CORS 설정 추가
|
113
136
|
cors = aiohttp_cors.setup(self._app, defaults={
|
114
137
|
"*": aiohttp_cors.ResourceOptions(
|
@@ -129,13 +152,15 @@ class PyloidRPC:
|
|
129
152
|
|
130
153
|
def method(self, name: Optional[str] = None) -> Callable:
|
131
154
|
"""
|
132
|
-
|
155
|
+
Use a decorator to register an async function as an RPC method.
|
156
|
+
|
157
|
+
If there is a 'ctx' parameter, an RPCContext object is automatically injected.
|
158
|
+
This object allows access to the pyloid application and current window.
|
133
159
|
|
134
160
|
Parameters
|
135
161
|
----------
|
136
162
|
name : Optional[str], optional
|
137
|
-
|
138
|
-
function's name is used. Defaults to None.
|
163
|
+
Name to register the RPC method. If None, the function name is used. Default is None.
|
139
164
|
|
140
165
|
Returns
|
141
166
|
-------
|
@@ -157,7 +182,10 @@ class PyloidRPC:
|
|
157
182
|
rpc = PyloidRPC()
|
158
183
|
|
159
184
|
@rpc.method()
|
160
|
-
async def add(a: int, b: int) -> int:
|
185
|
+
async def add(ctx, a: int, b: int) -> int:
|
186
|
+
# Access the application and window through ctx.pyloid and ctx.window
|
187
|
+
if ctx.window:
|
188
|
+
print(f"Window title: {ctx.window.title}")
|
161
189
|
return a + b
|
162
190
|
```
|
163
191
|
"""
|
@@ -168,13 +196,25 @@ class PyloidRPC:
|
|
168
196
|
if rpc_name in self._functions:
|
169
197
|
raise ValueError(f"RPC function name '{rpc_name}' is already registered.")
|
170
198
|
|
199
|
+
# Analyze function signature
|
200
|
+
sig = inspect.signature(func)
|
201
|
+
has_ctx_param = 'ctx' in sig.parameters
|
202
|
+
|
203
|
+
# Store the original function
|
171
204
|
self._functions[rpc_name] = func
|
172
205
|
log.info(f"RPC function registered: {rpc_name}")
|
173
206
|
|
174
207
|
@wraps(func)
|
175
208
|
async def wrapper(*args, **kwargs):
|
176
|
-
|
177
|
-
|
209
|
+
# If the function has a 'ctx' parameter and it's not provided, inject the context object
|
210
|
+
if has_ctx_param and 'ctx' not in kwargs:
|
211
|
+
ctx = RPCContext(
|
212
|
+
pyloid=self.pyloid,
|
213
|
+
window=self.window
|
214
|
+
)
|
215
|
+
kwargs['ctx'] = ctx
|
216
|
+
|
217
|
+
# Call the original function
|
178
218
|
return await func(*args, **kwargs)
|
179
219
|
return wrapper
|
180
220
|
return decorator
|
@@ -1,15 +1,15 @@
|
|
1
1
|
pyloid/__init__.py,sha256=YKwMCSOds1QVi9N7EGfY0Z7BEjJn8j6HGqRblZlZClA,235
|
2
2
|
pyloid/api.py,sha256=A61Kmddh8BlpT3LfA6NbPQNzFmD95vQ4WKX53oKsGYU,2419
|
3
3
|
pyloid/autostart.py,sha256=K7DQYl4LHItvPp0bt1V9WwaaZmVSTeGvadkcwG-KKrI,3899
|
4
|
-
pyloid/browser_window.py,sha256=
|
4
|
+
pyloid/browser_window.py,sha256=h0BehbCg8oUW5QGAyG1i1XjAQ020U9VWDTftDrMdwpI,100261
|
5
5
|
pyloid/custom/titlebar.py,sha256=itzK9pJbZMQ7BKca9kdbuHMffurrw15UijR6OU03Xsk,3894
|
6
6
|
pyloid/filewatcher.py,sha256=3M5zWVUf1OhlkWJcDFC8ZA9agO4Q-U8WdgGpy6kaVz0,4601
|
7
7
|
pyloid/js_api/base.py,sha256=XD3sqWYAb1nw6VgY3xXsU4ls5xLGrxpOqmLRJm_vBso,8669
|
8
8
|
pyloid/js_api/event_api.py,sha256=w0z1DcmwcmseqfcoZWgsQmFC2iBCgTMVJubTaHeXI1c,957
|
9
9
|
pyloid/js_api/window_api.py,sha256=-isphU3m2wGB5U0yZrSuK_4XiBz2mG45HsjYTUq7Fxs,7348
|
10
10
|
pyloid/monitor.py,sha256=1mXvHm5deohnNlTLcRx4sT4x-stnOIb0dUQnnxN50Uo,28295
|
11
|
-
pyloid/pyloid.py,sha256=
|
12
|
-
pyloid/rpc.py,sha256=
|
11
|
+
pyloid/pyloid.py,sha256=gO1wrO_5JX5mUMGGhZ-EKK0K54t9jgfJHrXagjkB9VA,85665
|
12
|
+
pyloid/rpc.py,sha256=y62hr2uqkyhwdASDvjryGqY8Bga9Cw6Hda_D6XaU0nQ,17092
|
13
13
|
pyloid/serve.py,sha256=wJIBqiLr1-8FvBdV3yybeBtVXsu94FfWYKjHL0eQ68s,1444
|
14
14
|
pyloid/store.py,sha256=p0plJj52hQjjtNMVJhy20eNLXfQ3Qmf7LtGHQk7FiPg,4471
|
15
15
|
pyloid/thread_pool.py,sha256=fKOBb8jMfZn_7crA_fJCno8dObBRZE31EIWaNQ759aw,14616
|
@@ -17,7 +17,7 @@ pyloid/timer.py,sha256=RqMsChFUd93cxMVgkHWiIKrci0QDTBgJSTULnAtYT8M,8712
|
|
17
17
|
pyloid/tray.py,sha256=D12opVEc2wc2T4tK9epaN1oOdeziScsIVNM2uCN7C-A,1710
|
18
18
|
pyloid/url_interceptor.py,sha256=AFjPANDELc9-E-1TnVvkNVc-JZBJYf0677dWQ8LDaqw,726
|
19
19
|
pyloid/utils.py,sha256=NqB8W-irXDtTGb74rrJ2swU6tgzU0HSE8lGewrStOKc,5685
|
20
|
-
pyloid-0.23.
|
21
|
-
pyloid-0.23.
|
22
|
-
pyloid-0.23.
|
23
|
-
pyloid-0.23.
|
20
|
+
pyloid-0.23.10.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
|
21
|
+
pyloid-0.23.10.dist-info/METADATA,sha256=NQvORTInEGRJqpmqAh_PYZINIHVI7zpM5qsZ679oR88,3198
|
22
|
+
pyloid-0.23.10.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
23
|
+
pyloid-0.23.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|