pyloid 0.24.9__py3-none-any.whl → 0.25.0__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 CHANGED
@@ -45,7 +45,6 @@ from PySide6.QtWebEngineCore import (
45
45
  import threading
46
46
 
47
47
  # from .url_interceptor import CustomUrlInterceptor
48
- from .rpc import PyloidRPC
49
48
 
50
49
  if TYPE_CHECKING:
51
50
  from .pyloid import _Pyloid, Pyloid
@@ -316,7 +315,6 @@ class _BrowserWindow:
316
315
  context_menu: bool = False,
317
316
  dev_tools: bool = False,
318
317
  # js_apis: List[PyloidAPI] = [],
319
- rpc: Optional[PyloidRPC] = None,
320
318
  transparent: bool = False,
321
319
  ):
322
320
  ###########################################################################################
@@ -324,15 +322,9 @@ class _BrowserWindow:
324
322
  self._window = QMainWindow()
325
323
  self.web_view = CustomWebEngineView(self)
326
324
 
327
- if rpc:
328
- self.rpc = rpc
329
- self.rpc_url = rpc.url
330
- else:
331
- self.rpc = None
332
- self.rpc_url = None
325
+
333
326
 
334
327
  # interceptor ( all url request )
335
- # self.interceptor = CustomUrlInterceptor(rpc_url=self.rpc_url)
336
328
  # self.web_view.page().setUrlRequestInterceptor(self.interceptor)
337
329
 
338
330
  self._window.closeEvent = self.closeEvent # Override closeEvent method
@@ -349,7 +341,7 @@ class _BrowserWindow:
349
341
  self.context_menu = context_menu
350
342
  self.dev_tools = dev_tools
351
343
 
352
- self.js_apis = [BaseAPI(self.id, self.app.data, self.app, self.rpc_url)]
344
+ self.js_apis = [BaseAPI(self.id, self.app.data, self.app, self.app.server.url)]
353
345
 
354
346
  # for js_api in js_apis:
355
347
  # self.js_apis.append(js_api)
@@ -357,25 +349,6 @@ class _BrowserWindow:
357
349
  self.shortcuts = {}
358
350
  self.close_on_load = True
359
351
  self.splash_screen = None
360
- ###########################################################################################
361
- # if the RPC server is not present, do not add it
362
- if not self.rpc:
363
- return
364
-
365
- self.rpc.pyloid = self.app.pyloid_wrapper
366
- # self.rpc.window = self.window_wrapper
367
-
368
- # prevent duplicate RPC servers
369
- if self.rpc in self.app.rpc_servers:
370
- return
371
-
372
- # add the RPC server
373
- self.app.rpc_servers.add(self.rpc)
374
-
375
- # Start unique RPC servers
376
- server_thread = threading.Thread(target=self.rpc.start, daemon=True)
377
- server_thread.start()
378
- ###########################################################################################
379
352
 
380
353
  def _set_custom_frame(
381
354
  self,
@@ -2125,7 +2098,6 @@ class BrowserWindow(QObject):
2125
2098
  frame: bool = True,
2126
2099
  context_menu: bool = False,
2127
2100
  dev_tools: bool = False,
2128
- rpc: Optional[PyloidRPC] = None,
2129
2101
  transparent: bool = False,
2130
2102
  ):
2131
2103
  super().__init__()
@@ -2140,7 +2112,6 @@ class BrowserWindow(QObject):
2140
2112
  frame,
2141
2113
  context_menu,
2142
2114
  dev_tools,
2143
- rpc,
2144
2115
  transparent,
2145
2116
  )
2146
2117
  self.command_signal.connect(self._handle_command)
pyloid/pyloid.py CHANGED
@@ -32,7 +32,6 @@ from PySide6.QtCore import QEventLoop
32
32
  from typing import Any, Set
33
33
  from platformdirs import PlatformDirs
34
34
  from .store import Store
35
- from .rpc import PyloidRPC
36
35
  import threading
37
36
  import signal
38
37
 
@@ -100,6 +99,7 @@ class _Pyloid(QApplication):
100
99
  pyloid_wrapper: "Pyloid",
101
100
  app_name,
102
101
  single_instance=True,
102
+ server=None,
103
103
  data=None,
104
104
  ):
105
105
  """
@@ -132,7 +132,6 @@ class _Pyloid(QApplication):
132
132
  self.data = data
133
133
 
134
134
  self.windows_dict: Dict[str, BrowserWindow] = {} # 윈도우 ID를 키로 사용하는 딕셔너리
135
- self.server = None
136
135
 
137
136
  self.app_name = app_name
138
137
  self.icon = None
@@ -171,7 +170,14 @@ class _Pyloid(QApplication):
171
170
 
172
171
  self.dirs = PlatformDirs(self.app_name, appauthor=False)
173
172
 
174
- self.rpc_servers: Set[PyloidRPC] = set()
173
+
174
+ ###################################################
175
+ # Pyloid Server Integration
176
+ if server:
177
+ self.server = server
178
+ else:
179
+ self.server = None
180
+ ###################################################
175
181
 
176
182
  # def set_theme(self, theme: Literal["system", "dark", "light"]):
177
183
  # """
@@ -242,7 +248,6 @@ class _Pyloid(QApplication):
242
248
  frame: bool = True,
243
249
  context_menu: bool = False,
244
250
  dev_tools: bool = False,
245
- rpc: Optional[PyloidRPC] = None,
246
251
  transparent: bool = False,
247
252
  ) -> BrowserWindow:
248
253
  """
@@ -266,8 +271,6 @@ class _Pyloid(QApplication):
266
271
  Whether to use the context menu (default is False)
267
272
  dev_tools : bool, optional
268
273
  Whether to use developer tools (default is False)
269
- rpc : PyloidRPC, optional
270
- The RPC server instance to be used in the window
271
274
  transparent : bool, optional
272
275
  Whether the window is transparent (default is False)
273
276
 
@@ -292,7 +295,6 @@ class _Pyloid(QApplication):
292
295
  frame,
293
296
  context_menu,
294
297
  dev_tools,
295
- rpc,
296
298
  transparent,
297
299
  )
298
300
  self.windows_dict[window._window.id] = window
@@ -315,17 +317,9 @@ class _Pyloid(QApplication):
315
317
  ```
316
318
  """
317
319
 
318
- # # Collect and deduplicate RPC servers
319
- # rpc_servers: Set[PyloidRPC] = set()
320
- # for window in self.windows_dict.values():
321
- # if window._window.rpc is not None:
322
- # rpc_servers.add(window._window.rpc)
323
-
324
- # # Start unique RPC servers
325
- # for rpc in rpc_servers:
326
- # server_thread = threading.Thread(target=rpc.start, daemon=True)
327
- # server_thread.start()
328
-
320
+ # Start Pyloid Integrated Server
321
+ if self.server:
322
+ self.server.run()
329
323
 
330
324
  if is_production():
331
325
  sys.exit(self.exec())
@@ -341,10 +335,10 @@ class _Pyloid(QApplication):
341
335
  # Another instance is already running
342
336
  sys.exit(1)
343
337
 
344
- # Create a new server
345
- self.server = QLocalServer()
346
- self.server.listen(self.app_name)
347
- self.server.newConnection.connect(self._handle_new_connection)
338
+ # Create a new Single Instance server
339
+ self.single_instance_server = QLocalServer()
340
+ self.single_instance_server.listen(self.app_name)
341
+ self.single_instance_server.newConnection.connect(self._handle_new_connection)
348
342
 
349
343
  def _handle_new_connection(self):
350
344
  """Handles new connections for the single instance server."""
@@ -1616,6 +1610,7 @@ class Pyloid(QObject):
1616
1610
  self,
1617
1611
  app_name: str,
1618
1612
  single_instance: bool = True,
1613
+ server = None,
1619
1614
  # data: Optional[Dict[str, Any]] = None,
1620
1615
  ):
1621
1616
  """
@@ -1631,12 +1626,14 @@ class Pyloid(QObject):
1631
1626
  The name of the application.
1632
1627
  single_instance : bool, optional
1633
1628
  Determines whether to run as a single instance. (Default is True)
1629
+ server : optional
1630
+ The pyloid server instance to be used in the application
1634
1631
  """
1635
1632
  super().__init__()
1636
1633
 
1637
1634
  self.data = None # 나중에 데이터 필요 시 수정
1638
1635
 
1639
- self.app = _Pyloid(self, app_name, single_instance, self.data)
1636
+ self.app = _Pyloid(self, app_name, single_instance, server, self.data)
1640
1637
 
1641
1638
  self.command_signal.connect(self._handle_command)
1642
1639
 
@@ -1657,7 +1654,6 @@ class Pyloid(QObject):
1657
1654
  frame=params.get("frame", True),
1658
1655
  context_menu=params.get("context_menu", False),
1659
1656
  dev_tools=params.get("dev_tools", False),
1660
- rpc=params.get("rpc", None),
1661
1657
  transparent=params.get("transparent", False),
1662
1658
  )
1663
1659
  result = window
@@ -1833,7 +1829,6 @@ class Pyloid(QObject):
1833
1829
  frame: bool = True,
1834
1830
  context_menu: bool = False,
1835
1831
  dev_tools: bool = False,
1836
- rpc: Optional[PyloidRPC] = None,
1837
1832
  transparent: bool = False,
1838
1833
  ) -> BrowserWindow:
1839
1834
  """
@@ -1857,8 +1852,6 @@ class Pyloid(QObject):
1857
1852
  Whether to use the context menu (default is False)
1858
1853
  dev_tools : bool, optional
1859
1854
  Whether to use developer tools (default is False)
1860
- rpc : PyloidRPC, optional
1861
- The RPC server instance to be used in the window
1862
1855
  transparent : bool, optional
1863
1856
  Whether the window is transparent (default is False)
1864
1857
 
@@ -1881,7 +1874,6 @@ class Pyloid(QObject):
1881
1874
  "frame": frame,
1882
1875
  "context_menu": context_menu,
1883
1876
  "dev_tools": dev_tools,
1884
- "rpc": rpc,
1885
1877
  "transparent": transparent,
1886
1878
  }
1887
1879
  return self.execute_command("create_window", params)
pyloid/rpc.py CHANGED
@@ -220,7 +220,7 @@ class PyloidRPC:
220
220
 
221
221
  # Store the original function
222
222
  self._functions[rpc_name] = func
223
- log.info(f"RPC function registered: {rpc_name}")
223
+ # log.info(f"RPC function registered: {rpc_name}")
224
224
 
225
225
  @wraps(func)
226
226
  async def wrapper(*args, _pyloid_window_id=None, **kwargs):
@@ -518,3 +518,31 @@ class PyloidRPC:
518
518
  except Exception as e:
519
519
  log.exception(f"Failed to start or run the server: {e}")
520
520
  raise
521
+
522
+ def run(self):
523
+ """
524
+ Runs start_async in a separate thread.
525
+
526
+ This method is useful when you want to start the aiohttp server in the background
527
+ without blocking the main thread. It creates a new thread, sets up a new asyncio event loop
528
+ in that thread, and starts the asynchronous server. The thread is marked as daemon so that
529
+ it will not prevent the program from exiting if only daemon threads remain.
530
+ """
531
+ import asyncio
532
+
533
+ def _run_asyncio():
534
+ # Create a new event loop for this thread.
535
+ loop = asyncio.new_event_loop()
536
+ # Set the newly created event loop as the current event loop for this thread.
537
+ asyncio.set_event_loop(loop)
538
+ # Start the asynchronous server; this coroutine will set up the server.
539
+ loop.run_until_complete(self.start_async())
540
+ # Keep the event loop running forever to handle incoming requests.
541
+ loop.run_forever()
542
+
543
+ # Create a new thread to run the event loop and server in the background.
544
+ # The thread is set as a daemon so it will not block program exit.
545
+ server_thread = threading.Thread(target=_run_asyncio, daemon=True)
546
+ # Start the background server thread.
547
+ server_thread.start()
548
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyloid
3
- Version: 0.24.9
3
+ Version: 0.25.0
4
4
  Summary:
5
5
  Author: aesthetics-of-record
6
6
  Author-email: 111675679+aesthetics-of-record@users.noreply.github.com
@@ -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=brCNmrQB-sTUvIC8VR5glpg-__DYmkrpVlIN0jf29Sw,104377
4
+ pyloid/browser_window.py,sha256=u9DfdlPHUZFpwdVprPs_Vhkj1aV3K_16KIub0vLCrLc,103284
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=Z3ID-4AJ0eHusmljRltlSaK4m2RKvRNfmqX76NLF77o,8585
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=DSHpMRDW4WvZgAAo2nJMesMJuOkNTVEEsDhCFIvjB5w,84509
12
- pyloid/rpc.py,sha256=OnF1sRGok9OJ-Q5519eQARD4oZTohyPhsPAT2Mg4_Gg,20377
11
+ pyloid/pyloid.py,sha256=Ioq_jmyaKTvW3KsmqZX3uhSUc3xRW9FgOtWcH96cVfo,84152
12
+ pyloid/rpc.py,sha256=6UzQc-CDA72VYeF3Xy-7AbBculE-T0MIokR39jVdlcg,21726
13
13
  pyloid/serve.py,sha256=KOs9984J2qboEXsquorkXgcQvvao_C2c9F6N2gSLfiA,8122
14
14
  pyloid/store.py,sha256=8PnBxtkUgbF8Lxh-iYlEuhbLE76bGBF8t5KV5u5NzoQ,4831
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=J6owgVE1YDOEfcOPmoP9m9Q6nbYDyNEo9uqPsJs5p5g,6644
20
- pyloid-0.24.9.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
21
- pyloid-0.24.9.dist-info/METADATA,sha256=aUI7SwfcwgFgAoAfRfm1nfzgrtYX2vtH2BupDHqc8eo,2298
22
- pyloid-0.24.9.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
23
- pyloid-0.24.9.dist-info/RECORD,,
20
+ pyloid-0.25.0.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
21
+ pyloid-0.25.0.dist-info/METADATA,sha256=289p55TOz7kF41q9lyHqgB9h0fRlxCyR1zZSF9OTDYw,2298
22
+ pyloid-0.25.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
23
+ pyloid-0.25.0.dist-info/RECORD,,