From bcf9e95c00c35eb76beac31c923a3bb0bea0a6dc Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Sat, 21 Jun 2025 22:08:28 +0800 Subject: [PATCH] Add Windows session integration Signed-off-by: Loren Eteval --- Furious/Utility/Win32Session.py | 77 +++++++++++++++++++++++++++++++++ Furious/Utility/__init__.py | 1 + requirements.txt | 1 + 3 files changed, 79 insertions(+) create mode 100644 Furious/Utility/Win32Session.py diff --git a/Furious/Utility/Win32Session.py b/Furious/Utility/Win32Session.py new file mode 100644 index 0000000..61c8f6d --- /dev/null +++ b/Furious/Utility/Win32Session.py @@ -0,0 +1,77 @@ +# Copyright (C) 2024 Loren Eteval +# +# 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 . + +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() diff --git a/Furious/Utility/__init__.py b/Furious/Utility/__init__.py index 899445a..45e39da 100644 --- a/Furious/Utility/__init__.py +++ b/Furious/Utility/__init__.py @@ -26,3 +26,4 @@ from .AppMainProcess import * from .AppSettings import * from .AppSettingsFn import * from .Utility import * +from .Win32Session import * diff --git a/requirements.txt b/requirements.txt index 66caedc..07df7a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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"