Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Fix Windows shortcut #205

Merged
merged 9 commits into from
Jan 11, 2021
4 changes: 2 additions & 2 deletions guiscrcpy/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def bootstrap_mapper(self):
print()
_, identifier = self.current_device_identifier()
executable = get_self()
from .lib.utils import shellify as sx
from .lib.utils import shellify as sx, open_process

subprocess.Popen(
open_process(
sx("{} mapper".format(executable)),
stdout=sys.stdout,
stdin=sys.stdin,
Expand Down
20 changes: 10 additions & 10 deletions guiscrcpy/lib/bridge/adb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import sys
from subprocess import Popen, PIPE, TimeoutExpired, call
from subprocess import PIPE, TimeoutExpired, call

from .base import Bridge
from ..check import _get_dimension_raw_noexcept, get
from ..utils import decode_process, _
from ..utils import decode_process, open_process, _


class AndroidDebugBridge(Bridge):
Expand All @@ -21,13 +21,13 @@ def get_target_android_version(self, device_id=None):
def shell_input(self, command, device_id=None):
path = self.path
if device_id:
Popen(
open_process(
_("{} -s {} shell input {}".format(path, device_id, command)),
stdout=PIPE,
stderr=PIPE,
)
else:
Popen(
open_process(
_("{} shell input {}".format(path, command)),
stdout=PIPE,
stderr=PIPE,
Expand Down Expand Up @@ -77,26 +77,26 @@ def get_dimensions(self, device_id=None):

def shell(self, command, device_id=None):
if device_id:
po = Popen(
po = open_process(
_("{} -s {} shell {}".format(self.path, device_id, command)),
stdout=PIPE,
stderr=PIPE,
)
else:
po = Popen(
po = open_process(
_("{} shell {}".format(self.path, command)), stdout=PIPE, stderr=PIPE
)
return po

def command(self, command, device_id=None):
if device_id:
adb_shell_output = Popen(
adb_shell_output = open_process(
_("{} -s {} {}".format(self.path, device_id, command)),
stdout=PIPE,
stderr=PIPE,
)
else:
adb_shell_output = Popen(
adb_shell_output = open_process(
_("{} {}".format(self.path, command)), stdout=PIPE, stderr=PIPE
)
return adb_shell_output
Expand All @@ -114,7 +114,7 @@ def tcpip(self, port=5555, identifier=""):
return exit_code

def devices(self):
proc = Popen(_(self.path + " devices"), stdout=PIPE)
proc = open_process(_(self.path + " devices"), stdout=PIPE)
output = [[y.strip() for y in x.split("\t")] for x in decode_process(proc)[1:]][
:-1
]
Expand All @@ -123,7 +123,7 @@ def devices(self):
return output

def devices_detailed(self):
proc = Popen(_(self.path + " devices -l"), stdout=PIPE)
proc = open_process(_(self.path + " devices -l"), stdout=PIPE)
output = [[y.strip() for y in x.split()] for x in decode_process(proc)[1:]][:-1]
devices_found = []
for device in output:
Expand Down
4 changes: 2 additions & 2 deletions guiscrcpy/lib/bridge/audio/sndcpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time

from .base import AudioBridge
from ...utils import shellify as _, show_message_box
from ...utils import shellify as _, show_message_box, open_process


class SndcpyBridge(AudioBridge):
Expand All @@ -14,7 +14,7 @@ def run(self, device_id=None):
command = "{sndcpy}"
else:
command = "{sndcpy} {device_id}"
_proc = subprocess.Popen(
_proc = open_process(
_(command.format(sndcpy=self.get_path(), device_id=device_id)),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
4 changes: 2 additions & 2 deletions guiscrcpy/lib/bridge/audio/usbaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


from .base import AudioBridge
from ...utils import shellify as _
from ...utils import shellify as _, open_process


class USBAudioBridge(AudioBridge):
Expand All @@ -14,7 +14,7 @@ def run(self, device_id=None):
command = "{usbaudio}"
else:
command = "{usbaudio} --serial {device_id}"
subprocess.Popen(
open_process(
_(command.format(usbaudio=self.get_path(), device_id=device_id)),
stdout=sys.stdout,
stderr=sys.stderr,
Expand Down
6 changes: 3 additions & 3 deletions guiscrcpy/lib/bridge/scrcpy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from subprocess import Popen, PIPE
from subprocess import PIPE

from .base import Bridge
from ...lib.utils import shellify as _
from ...lib.utils import shellify as _, open_process


class ScrcpyBridge(Bridge):
Expand All @@ -16,7 +16,7 @@ def post_init(self):
os.environ["LD_LIBRARY_PATH"] = os.getenv("SCRCPY_LDD")

def start(self, args, stdout=PIPE, stderr=PIPE):
proc = Popen(
proc = open_process(
_("{} {}".format(self.path, args)),
stdout=stdout,
stderr=stderr,
Expand Down
10 changes: 6 additions & 4 deletions guiscrcpy/lib/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from subprocess import Popen, PIPE
from subprocess import PIPE

from ..lib.utils import shellify as _
from ..lib.utils import shellify as _, open_process


def get(ls, idx, default=""):
Expand All @@ -31,11 +31,13 @@ def get(ls, idx, default=""):

def _get_dimension_raw_noexcept(path, device_id=None):
if device_id:
shell_adb = Popen(
shell_adb = open_process(
_("{} -s {} shell wm size".format(path, device_id)),
stdout=PIPE,
stderr=PIPE,
)
else:
shell_adb = Popen(_("{} shell wm size".format(path)), stdout=PIPE, stderr=PIPE)
shell_adb = open_process(
_("{} shell wm size".format(path)), stdout=PIPE, stderr=PIPE
)
return shell_adb
16 changes: 16 additions & 0 deletions guiscrcpy/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import shlex
import shutil
import sys
import subprocess

from qtpy.QtGui import QPixmap
from colorama import Fore
Expand Down Expand Up @@ -162,3 +163,18 @@ def show_message_box(text, info_text="", buttons=QMessageBox.Ok):
message_box.setInformativeText(info_text)
message_box.setStandardButtons(buttons)
return message_box


def open_process(*args, **kwargs):
if (
environment.system() == "Windows"
and sys.version_info.major >= 3
and sys.version_info.minor >= 7
):
return subprocess.Popen(
*args,
**kwargs,
creationflags=subprocess.CREATE_NO_WINDOW,
)
else:
return subprocess.Popen(*args, **kwargs)
2 changes: 1 addition & 1 deletion guiscrcpy/platform/windows_tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def make_shortcut():
dest = os.path.join(folder, "guiscrcpy.lnk")

wscript = _WSHELL.CreateShortCut(dest)
wscript.Targetpath = "guiscrcpy.exe"
wscript.Targetpath = "guiscrcpy-noconsole.exe"
wscript.WorkingDirectory = userfolders.home
wscript.WindowStyle = 0
wscript.Description = "An Open Source Android Screen Mirroring System"
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
('share/applications', ['guiscrcpy.desktop']),
('share/icons/hicolor/scalable/apps', ['appimage/guiscrcpy.png']),
]
guiscrcpy_main = 'guiscrcpy.cli:cli'

setup(
name="guiscrcpy",
Expand All @@ -62,9 +63,15 @@
url="https://srevinsaju.github.io/guiscrcpy",
download_url="https://github.com/srevinsaju/guiscrcpy/archive/master.zip",
include_package_data=True,
package_data={
"guiscrcpy": ["ui/icons/guiscrcpy_logo_SRj_icon.ico"]
},
install_requires=requirements,
scripts=["scripts/guiscrcpy"],
entry_points={'console_scripts': ['guiscrcpy = guiscrcpy.cli:cli']}, # noqa: E501
entry_points={
'console_scripts': ['guiscrcpy = ' + guiscrcpy_main],
'gui_scripts': ['guiscrcpy-noconsole = ' + guiscrcpy_main]
}, # noqa: E501
classifiers=[
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.7',
Expand Down