Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions IoTuring/Configurator/ConfiguratorIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
from IoTuring.MyApp.SystemConsts import OperatingSystemDetection as OsD

# macOS dep (in PyObjC)
try:
from AppKit import * # type:ignore
from Foundation import * # type:ignore
macos_support = True
except:
macos_support = False
if OsD.IsMacos():
from AppKit import *
from Foundation import *

CONFIG_PATH_ENV_VAR = "IOTURING_CONFIG_DIR"

Expand Down Expand Up @@ -80,7 +77,7 @@ def getFolderPath(self) -> Path:
if envvarPath and len(envvarPath) > 0:
folderPath = Path(envvarPath)
else:
if OsD.IsMacos() and macos_support:
if OsD.IsMacos() and 'AppKit' in sys.modules and 'Foundation' in sys.modules:
folderPath = self.macOSFolderPath().joinpath(self.directoryName)
elif OsD.IsWindows():
folderPath = self.windowsFolderPath().joinpath(self.directoryName)
Expand Down
27 changes: 12 additions & 15 deletions IoTuring/Entity/Deployments/ActiveWindow/ActiveWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
from IoTuring.MyApp.SystemConsts import OperatingSystemDetection as OsD
from IoTuring.MyApp.SystemConsts import DesktopEnvironmentDetection as De

import sys

# Windows dep
try:
from win32gui import GetWindowText, GetForegroundWindow # type: ignore
windows_support = True
except BaseException:
windows_support = False
if OsD.IsWindows():
from win32gui import GetWindowText, GetForegroundWindow

# macOS dep
try:
from AppKit import NSWorkspace # type: ignore
macos_support = True
except BaseException:
macos_support = False
if OsD.IsMacos():
from AppKit import NSWorkspace


KEY = 'active_window'

Expand Down Expand Up @@ -85,11 +81,12 @@ def CheckSystemSupport(cls):
elif not OsD.CommandExists("xprop"):
raise Exception("No xprop command found!")

elif OsD.IsWindows() or OsD.IsMacos():

if (OsD.IsWindows() and not windows_support) or\
(OsD.IsMacos() and not macos_support):
raise Exception("Unsatisfied dependencies for this entity")
elif OsD.IsWindows():
if 'win32gui' not in sys.modules:
raise Exception("Unsatisfied dependencies (win32gui) for this entity")

elif OsD.IsMacos():
if 'AppKit' not in sys.modules:
raise Exception("Unsatisfied dependencies (AppKit) for this entity")
else:
raise cls.UnsupportedOsException()
11 changes: 5 additions & 6 deletions IoTuring/Entity/Deployments/Notify/Notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

import os
import json
import sys

supports_win = True
try:
import tinyWinToast.tinyWinToast as twt # type: ignore
except:
supports_win = False

if OsD.IsWindows():
import tinyWinToast.tinyWinToast as twt

commands = {
OsD.LINUX: 'notify-send "{}" "{}" --icon="{}"', # title, message, icon path
Expand Down Expand Up @@ -137,7 +136,7 @@ def ConfigurationPreset(cls) -> MenuPreset:
@classmethod
def CheckSystemSupport(cls):
if OsD.IsWindows():
if not supports_win:
if 'tinyWinToast' not in sys.modules:
raise Exception(
'Notify not available, have you installed \'tinyWinToast\' on pip ?')

Expand Down
12 changes: 5 additions & 7 deletions IoTuring/Settings/Deployments/LogSettings/LogSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
from IoTuring.Logger.LogLevel import LogLevel
from IoTuring.Logger import consts

import sys

# macOS dep (in PyObjC)
try:
from AppKit import * # type:ignore
from Foundation import * # type:ignore
macos_support = True
except:
macos_support = False
if OsD.IsMacos():
from AppKit import *
from Foundation import *


CONFIG_KEY_CONSOLE_LOG_LEVEL = "console_log_level"
Expand Down Expand Up @@ -91,7 +89,7 @@ def GetDefaultLogPath() -> str:
"Logger").joinpath(consts.LOGS_FOLDER)
base_path = None

if OsD.IsMacos() and macos_support:
if OsD.IsMacos() and 'AppKit' in sys.modules and 'Foundation' in sys.modules:
base_path = \
Path(NSSearchPathForDirectoriesInDomains( # type: ignore
NSLibraryDirectory, # type: ignore
Expand Down