mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-03 04:17:58 +03:00
Add Windows session integration
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
# Copyright (C) 2024 Loren Eteval <loren.eteval@proton.me>
|
||||
#
|
||||
# This file is part of Furious.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Utility.Constants import *
|
||||
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from typing import Callable
|
||||
|
||||
__all__ = ['Win32Session']
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class _Win32Session:
|
||||
def __init__(self):
|
||||
self._daemonThread = None
|
||||
|
||||
@staticmethod
|
||||
def set(callback: Callable[[], None]) -> bool:
|
||||
if PLATFORM == 'Windows':
|
||||
import win32session
|
||||
|
||||
win32session.set(callback)
|
||||
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def off(self) -> bool:
|
||||
if PLATFORM == 'Windows':
|
||||
import win32session
|
||||
|
||||
if win32session.off():
|
||||
self._daemonThread.join()
|
||||
# Reset it
|
||||
self._daemonThread = None
|
||||
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
def run(self) -> bool:
|
||||
if PLATFORM == 'Windows':
|
||||
import win32session
|
||||
|
||||
if self._daemonThread is None:
|
||||
self._daemonThread = threading.Thread(
|
||||
target=lambda: win32session.run(), daemon=True
|
||||
)
|
||||
self._daemonThread.start()
|
||||
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
Win32Session = _Win32Session()
|
||||
@@ -26,3 +26,4 @@ from .AppMainProcess import *
|
||||
from .AppSettings import *
|
||||
from .AppSettingsFn import *
|
||||
from .Utility import *
|
||||
from .Win32Session import *
|
||||
|
||||
@@ -6,6 +6,7 @@ pyqrcode
|
||||
pypng
|
||||
icmplib
|
||||
sysproxy; sys_platform == "win32"
|
||||
win32session; sys_platform == "win32"
|
||||
darkdetect; sys_platform != "darwin"
|
||||
darkdetect[macos-listener]; sys_platform == "darwin"
|
||||
pyobjc-core; sys_platform == "darwin"
|
||||
|
||||
Reference in New Issue
Block a user