Skip to content

Commit

Permalink
Merge pull request #46 from casualsnek/testing
Browse files Browse the repository at this point in the history
Merge commits from testing branch
  • Loading branch information
casualsnek authored Feb 14, 2022
2 parents 5ffe98f + 1572a26 commit 65bca5b
Show file tree
Hide file tree
Showing 22 changed files with 436 additions and 114 deletions.
133 changes: 86 additions & 47 deletions app-linux/src/cassowary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .gui.components.main_ui import MainWindow
from .client import Client
import threading
import re



Expand Down Expand Up @@ -179,60 +180,98 @@ def start_bg_client(reconnect=True):
print(path_translate_to_guest(args.cmdline[0]))
elif args.command == "guest-run":
translated_paths = [path_translate_to_guest(argument) for argument in args.cmdline]
print(translated_paths)
# Check and translated every argument if it is a path
cmd = BASE_RDP_CMD.format(rdflag=cfgvars.config["rdp_flags"],
domain=cfgvars.config["winvm_hostname"],
user=cfgvars.config["winvm_username"],
passd=cfgvars.config["winvm_password"],
ip=cfgvars.config["host"], scale=cfgvars.config["rdp_scale"],
mflag="multimon" if multimon_enable else "span", wmclass=wm_class,
rdc=cfgvars.config["app_session_client"],
share_root=cfgvars.config["rdp_share_root"],
execu=args.cmdline[0], icon=icon)

if len(translated_paths) > 1:
rd_app_args = ""
for path in translated_paths[1:]:
if " " in path:
# This looks ugly because windows uses "" for escaping " instead of \" and this is the
# only way i found so far
path = '\\"\\"\\"{}\\"\\"\\"'.format(path)
rd_app_args = rd_app_args + path + " "
# Now problem for path with spaces is solved, but the path pointing to drive's root
# | DO NOT REMOVE THIS SPACE or else path pointing to drive letter
# |--------| (C:| or D:| ) will not launch due to \ at end escaping the
# V | ending quote
cmd = cmd + '/app-cmd:"{} "'.format(rd_app_args.strip())
#cmd = cmd + " 1> /dev/null 2>&1 &"
app = QApplication(sys.argv)
process = subprocess.check_output(["ps", "auxfww"])
vm_wake()
fix_black_window()
logger.debug("guest-run with commandline: "+cmd)
process = subprocess.Popen(["sh", "-c", "{}".format(cmd)])
process.wait()
if cfgvars.config["soft_launch"] and \
len(re.findall(r"freerdp.*\/wm-class:.*cassowaryApp", process.decode())) >= 1:
# Use soft launch:
command_and_args = ""
for argument in translated_paths:
if " " in argument:
command_and_args = command_and_args+'"{}" '.format(argument)
else:
command_and_args = command_and_args + argument + " "
logger.debug("Using soft launch as other RDP application is active")
client__ = Client(cfgvars.config["host"], cfgvars.config["port"])
client__.init_connection()
response = client__.send_wait_response(
['run-app', 'cmd.exe /c start "" {}'.format(command_and_args)],
timeout=10
)
logger.debug("Got soft launch response: %s", str(response))
print(response)
else:
cmd = BASE_RDP_CMD.format(rdflag=cfgvars.config["rdp_flags"],
domain=cfgvars.config["winvm_hostname"],
user=cfgvars.config["winvm_username"],
passd=cfgvars.config["winvm_password"],
ip=cfgvars.config["host"], scale=cfgvars.config["rdp_scale"],
mflag="multimon" if multimon_enable else "span", wmclass=wm_class,
rdc=cfgvars.config["app_session_client"],
share_root=cfgvars.config["rdp_share_root"],
execu=args.cmdline[0], icon=icon)
if len(translated_paths) > 1:
rd_app_args = ""
for path in translated_paths[1:]:
if " " in path:
# This looks ugly because windows uses "" for escaping " instead of \" and this is
# the only way I found so far
path = '\\"\\"\\"{}\\"\\"\\"'.format(path)
rd_app_args = rd_app_args + path + " "
# Now problem for path with spaces is solved, but the path pointing to drive's root
# | DO NOT REMOVE THIS SPACE or else path pointing to drive letter
# |---| (C:| or D:| ) will not launch due to \ at end escaping the
# V | ending quote
cmd = cmd + '/app-cmd:"{} "'.format(rd_app_args.strip())
# cmd = cmd + " 1> /dev/null 2>&1 &"
fix_black_window()
logger.debug("guest-run with commandline: "+cmd)
process = subprocess.Popen(["sh", "-c", "{}".format(cmd)])
process.wait()
elif args.command == "guest-open":
path = path_translate_to_guest(args.cmdline[0])
if " " in path:
# This looks ugly because windows uses "" for escaping " instead of \" and this is the
# only way i found so far
path = '\\"\\"\\"{}\\"\\"\\"'.format(path)
cmd = BASE_RDP_CMD.format(rdflag=cfgvars.config["rdp_flags"],
domain=cfgvars.config["winvm_hostname"],
user=cfgvars.config["winvm_username"],
passd=cfgvars.config["winvm_password"],
ip=cfgvars.config["host"], scale=cfgvars.config["rdp_scale"],
mflag="multimon" if multimon_enable else "span", wmclass=wm_class,
rdc=cfgvars.config["app_session_client"],
share_root=cfgvars.config["rdp_share_root"],
execu="cmd.exe", icon=icon)
cmd = cmd + '/app-cmd:"/c start {} "'.format(path)
app = QApplication(sys.argv)
process = subprocess.check_output(["ps", "auxfww"])
vm_wake()
fix_black_window()
logger.debug("guest-open with commandline: " + cmd)
process = subprocess.Popen(["sh", "-c", "{}".format(cmd)])
process.wait()
if cfgvars.config["soft_launch"] and \
len(re.findall(r"freerdp.*\/wm-class:.*cassowaryApp", process.decode())) >= 1:
# Use soft launch
if " " in path:
path = '"{}"'.format(path)
logger.debug("Using soft launch as other RDP application is active")
client__ = Client(cfgvars.config["host"], cfgvars.config["port"])
client__.init_connection()
response = client__.send_wait_response(
['run-app', 'cmd.exe /c start "" {} '.format(path)],
timeout=10
)
logger.debug("Got soft launch response: %s", str(response))
print(response)
else:
if " " in path:
# This looks ugly because windows uses "" for escaping " instead of \" and this is the
# only way I found so far
path = '\\"\\"\\"{}\\"\\"\\"'.format(path)
cmd = BASE_RDP_CMD.format(rdflag=cfgvars.config["rdp_flags"],
domain=cfgvars.config["winvm_hostname"],
user=cfgvars.config["winvm_username"],
passd=cfgvars.config["winvm_password"],
ip=cfgvars.config["host"], scale=cfgvars.config["rdp_scale"],
mflag="multimon" if multimon_enable else "span", wmclass=wm_class,
rdc=cfgvars.config["app_session_client"],
share_root=cfgvars.config["rdp_share_root"],
execu="cmd.exe", icon=icon)
# |--- This is ugly too but without this path with spaces wont work
# |----------------|
# V V
cmd = cmd + '/app-cmd:"/c start \\"\\"\\"\\"\\"\\" {} "'.format(path)
# cmd = cmd + " 1> /dev/null 2>&1 &"
fix_black_window()
logger.debug("guest-open with commandline: " + cmd)
process = subprocess.Popen(["sh", "-c", "{}".format(cmd)])
process.wait()
elif args.command == "raw-cmd":
vm_wake()
client__ = Client(cfgvars.config["host"], cfgvars.config["port"])
Expand Down
1 change: 1 addition & 0 deletions app-linux/src/cassowary/base/cfgvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self):
"winshare_mount_root": os.path.join("/", "mnt", self.app_name),
"eom": "~~!enm!~~",
"logfile": os.path.join(self.config_dir, self.app_name + ".log"),
"soft_launch": 1
}
self.refresh_config()
self.__check_config()
Expand Down
2 changes: 2 additions & 0 deletions app-linux/src/cassowary/base/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import os


class DuplicateFilter(logging.Filter):
def filter(self, record):
# add other fields if you need more granular comparison, depends on your app
Expand All @@ -13,6 +14,7 @@ def filter(self, record):
return True
return False


def get_logger(name):
log_level = int(os.environ.get("LOG_LEVEL", 1))
log_levels = [logging.NOTSET, logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]
Expand Down
2 changes: 2 additions & 0 deletions app-linux/src/cassowary/gui/components/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def __save_vminfo(self):
cfgvars.config["winshare_mount_root"] = os.path.abspath(self.inp_mountroot.text())
cfgvars.config["vm_suspend_delay"] = self.inp_sleepd.value()
cfgvars.config["vm_auto_suspend"] = 1 if self.inp_enbsuspend.isChecked() else 0
cfgvars.config["soft_launch"] = 1 if self.inp_softlaunch.isChecked() else 0
cfgvars.config["send_suspend_notif"] = 1 if self.inp_susnotif.isChecked() else 0
cfgvars.config["app_session_client"] = self.inp_apprdc.currentText()
cfgvars.config["full_session_client"] = self.inp_fullrdc.currentText()
Expand All @@ -277,6 +278,7 @@ def populate_general(self):
self.inp_sleepd.setValue(cfgvars.config["vm_suspend_delay"])
self.inp_enbsuspend.setChecked(bool(cfgvars.config["vm_auto_suspend"]))
self.inp_susnotif.setChecked(bool(cfgvars.config["send_suspend_notif"]))
self.inp_softlaunch.setChecked(bool(cfgvars.config["soft_launch"]))
self.inp_rdpscale.setValue({100: 0, 140: 1, 180: 2}[cfgvars.config["rdp_scale"]])
self.inp_rdpmultimon.setChecked(bool(cfgvars.config["rdp_multimon"]))

Expand Down
37 changes: 36 additions & 1 deletion app-linux/src/cassowary/gui/qtui_files/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,15 @@
<string>Launch on Host</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>The files extensions set here are opened with your linux host applications if they are opened
or double click on host system.
If you add &quot;jpg&quot; here, it will use your linux image viewer instead of windows image viewer even if it wa opened in windows</string>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tbl_associations">
<property name="editTriggers">
Expand Down Expand Up @@ -937,7 +946,7 @@ App like Windows 10's Photoviewer will generate a lot of glitches.</string>
<property name="geometry">
<rect>
<x>20</x>
<y>320</y>
<y>310</y>
<width>261</width>
<height>17</height>
</rect>
Expand Down Expand Up @@ -1280,6 +1289,32 @@ App like Windows 10's Photoviewer will generate a lot of glitches.</string>
<string>:</string>
</property>
</widget>
<widget class="QLabel" name="lb_enablesoftlaunch">
<property name="geometry">
<rect>
<x>20</x>
<y>380</y>
<width>281</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Prefer using server to launch applications</string>
</property>
</widget>
<widget class="QCheckBox" name="inp_softlaunch">
<property name="geometry">
<rect>
<x>300</x>
<y>380</y>
<width>251</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
</widget>
</item>
<item>
Expand Down
5 changes: 4 additions & 1 deletion app-win/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pyinstaller package.spec --noconfirm
echo ==^> Copying to setup directory
mkdir ..\bin
Xcopy /E /I /F /Y dist\cassowary ..\bin\cassowary
Xcopy /Y extras\* ..\bin\
Xcopy /Y /I /F /Y extras\* ..\bin\
del ..\bin\app.svg
rmdir /s /q build
rmdir /s /q dist
cd ..\
echo ==^> Done...
1 change: 0 additions & 1 deletion app-win/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ checksum=""
min_build_for=${MIN_WIN_VER:-win7}
checksum_verification=${VERITY_DOWNLOADS:-0}
export WINEPREFIX=/tmp/cassowary-build
rm -rf /tmp/cassowary-build
mkdir -p /tmp/cassowary-build
download_python()
{
Expand Down
9 changes: 7 additions & 2 deletions app-win/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import logging
import os
import sys
from base.command import register_all
Expand Down Expand Up @@ -76,14 +75,20 @@
if args.command_help:
print(about+"\n"+action_help)
if args.server:
# Clear temp file directory
for root, dirs, files in os.walk(cfgvars.tempdir):
for name in files:
os.remove(os.path.join(root, name))
while True:
try:
start_server(cfgvars.config["host"], cfgvars.config["port"])
sys.exit(0)
except OSError as e:
if "[WinError 10048]" in str(e):
if not args.nokill:
pid = os.popen("netstat -ano | findstr :{}".format(cfgvars.config["port"])).read().strip().split()[-1]
pid = os.popen("netstat -ano | findstr :{}".format(
cfgvars.config["port"])
).read().strip().split()[-1]
os.popen("taskkill /pid {} /f".format(pid))
else:
break
Expand Down
5 changes: 3 additions & 2 deletions app-win/src/base/command/cmd_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __get_exe_info(path_to_exe):
except:
description = "unknown"
version = "unknown"
# TODO: Remove None and use different function to get app icons !
logger.warning("Failed to get version information for '%s' : %s", path_to_exe, traceback.format_exc())
return [description, version]

@staticmethod
Expand All @@ -42,6 +42,7 @@ def __get_exe_image(exe_path):
except:
img_str = ""
return img_str

@staticmethod
def __find_installed():
logger.debug("Getting list of installed applications")
Expand All @@ -54,7 +55,7 @@ def __find_installed():
except FileNotFoundError:
# If the Key does not exist instead of throwing an exception safely ignore it
pass
# Open the directories on App Path -Accessing requires a defined integer, so we loop Until we get WinError 259
# Open the directories on App Path -Accessing requires a defined integer, we loop Until we get WinError 259
for n in range(1000):
try:
app_entry = winreg.OpenKey(app_path_key, winreg.EnumKey(app_path_key, n))
Expand Down
Loading

0 comments on commit 65bca5b

Please sign in to comment.