From 23574f49fc3ef42eed451f69c2679a4169d96eb4 Mon Sep 17 00:00:00 2001 From: Supremekirb <99102603+Supremekirb@users.noreply.github.com> Date: Mon, 29 Apr 2024 20:54:23 +0930 Subject: [PATCH 1/2] add support for CLI in executable binary --- CoilSnake.spec | 4 ++-- script/gui.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CoilSnake.spec b/CoilSnake.spec index f690ae2d..2046d454 100644 --- a/CoilSnake.spec +++ b/CoilSnake.spec @@ -87,10 +87,10 @@ exe = EXE( upx=True, upx_exclude=[], runtime_tmpdir=None, - console=debug, + hide_console='hide-early', icon='coilsnake/assets/images/CoilSnake.ico', manifest=None, - windowed=True + console=True ) if platform.system() != 'Darwin': diff --git a/script/gui.py b/script/gui.py index c4a8fb94..7d2747ee 100755 --- a/script/gui.py +++ b/script/gui.py @@ -4,6 +4,11 @@ sys.path.append(".") from coilsnake.ui.gui import main +from coilsnake.ui.cli import main as cli_main if __name__ == '__main__': - main() + # if we recieve arguments, run the cli instead + if len(sys.argv) > 1: + sys.exit(cli_main()) + else: + main() From 412b1bb8ca63d23652aa4d93050f0bd91b503cf0 Mon Sep 17 00:00:00 2001 From: Supremekirb <99102603+Supremekirb@users.noreply.github.com> Date: Tue, 25 Feb 2025 11:41:55 +1030 Subject: [PATCH 2/2] Improvements from comment --- script/gui.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/script/gui.py b/script/gui.py index 7d2747ee..ecb6ce49 100755 --- a/script/gui.py +++ b/script/gui.py @@ -1,14 +1,24 @@ #!/usr/bin/env python +import os +import subprocess import sys sys.path.append(".") from coilsnake.ui.gui import main from coilsnake.ui.cli import main as cli_main +def perform_windows_noconsole_workaround(argv): + return os.name == 'nt' and len(argv) == 1 and argv[0].endswith('.exe') + if __name__ == '__main__': - # if we recieve arguments, run the cli instead - if len(sys.argv) > 1: + if len(sys.argv) == 2 and sys.argv[1] == '--gui': + main() + elif perform_windows_noconsole_workaround(sys.argv): + # We're on Windows. Start ourselves but with no console window, and then exit. + subprocess.Popen([sys.argv[0], '--gui'], creationflags=subprocess.CREATE_NO_WINDOW) + sys.exit(0) + elif len(sys.argv) > 1: sys.exit(cli_main()) else: - main() + main() \ No newline at end of file