Skip to content

Commit 460becb

Browse files
committed
fix self-exec
1 parent 99b8fcf commit 460becb

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

flake.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,25 @@
109109
];
110110

111111
nativeInputs = [ pkgs.qt5.wrapQtAppsHook ];
112+
dontWrapGApps = true;
112113
dontWrapQtApps = true;
113114

114115
src = ./.;
115116

116117
# Arguments to be passed to `makeWrapper`, only used by buildPython*
117118
preFixup = ''
118-
for app in "$out/bin/"*; do
119-
wrapQtApp "$app"
120-
done
119+
makeWrapperArgs+=("''${qtWrapperArgs[@]}")
121120
'';
121+
122+
desktopItems = [
123+
(pkgs.makeDesktopItem {
124+
name = "pre_workbench";
125+
desktopName = "PRE Workbench";
126+
icon = ./pre_workbench/icons/appicon.png;
127+
exec = "prewb";
128+
})
129+
];
130+
122131
meta = {
123132
mainProgram = "prewb";
124133
homepage = "https://luelista.net/pre_workbench/";

pre_workbench/mainwindow.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from pre_workbench import windows
4141
from pre_workbench.configs import getIcon, SettingsSection, SettingsField, icon_searchpaths
4242
from pre_workbench.datawidgets import DynamicDataWidget
43-
from pre_workbench.util import get_app_version, SimpleThread
43+
from pre_workbench.util import get_app_version, SimpleThread, get_exe_for_reloading
4444
from pre_workbench.windows.content.objectwindow import ObjectWindow
4545
from pre_workbench.windows.dialogs.manageannotationsets import ManageAnnotationSetsDialog
4646
# noinspection PyUnresolvedReferences
@@ -581,14 +581,7 @@ def onProjectOpenAction(self):
581581

582582
def openProjectInNewWindow(self, projectPath = "--choose-project"):
583583
import subprocess
584-
self_script = sys.argv[0]
585-
# weird Windows magic
586-
if self_script == sys.executable: # PyInstaller on Windows
587-
cmd_line = [self_script, projectPath]
588-
elif not os.path.exists(self_script) and os.path.exists(self_script + '.exe'): # PIP entry_points on Windows
589-
cmd_line = [sys.executable, self_script + '.exe', projectPath]
590-
else: # everything else
591-
cmd_line = [sys.executable, self_script, projectPath]
584+
cmd_line = get_exe_for_reloading() + [projectPath]
592585
logging.info('Starting new instance with cmd line: %r', cmd_line)
593586
subprocess.Popen(cmd_line, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
594587

pre_workbench/util.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import logging
1818
import time
19+
import sys, os.path
1920

2021
from PyQt5.QtCore import QThread, pyqtSignal
2122

@@ -55,3 +56,32 @@ def run(self) -> None:
5556
self.resultReturned.emit(self.thread_fn())
5657
except:
5758
logging.exception("Exception in SimpleThread")
59+
60+
61+
# from here: https://github.com/samdroid-apps/werkzeug/blob/268cad0016bcbccff8a8bb9190d39fdd12dc13d2/werkzeug/_reloader.py#L59
62+
def get_exe_for_reloading():
63+
"""Returns the executable. This contains a workaround for windows
64+
if the executable is incorrectly reported to not have the .exe
65+
extension which can cause bugs on reloading. This also contains
66+
a workaround for linux where the file is executable (possibly with
67+
a program other than python)
68+
"""
69+
rv = [sys.executable]
70+
py_script = os.path.abspath(sys.argv[0])
71+
72+
if os.name == 'nt' and not os.path.exists(py_script) and \
73+
os.path.exists(py_script + '.exe'):
74+
py_script += '.exe'
75+
76+
windows_workaround = (
77+
os.path.splitext(rv[0])[1] == '.exe'
78+
and os.path.splitext(py_script)[1] == '.exe'
79+
)
80+
nix_workaround = os.path.isfile(py_script) and os.access(py_script, os.X_OK)
81+
82+
if windows_workaround or nix_workaround:
83+
rv.pop(0)
84+
85+
rv.append(py_script)
86+
return rv
87+

0 commit comments

Comments
 (0)