Taskbar icon on windows (#861)
* Give app an unique ID when launching on Windows * Improve test coverage
This commit is contained in:
committed by
GitHub
parent
95c79e1c23
commit
7958cb530f
+10
-1
@@ -262,7 +262,16 @@ def main(sysArgs=None):
|
||||
bundle = NSBundle.mainBundle()
|
||||
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
|
||||
info["CFBundleName"] = "novelWriter"
|
||||
except ImportError:
|
||||
except Exception:
|
||||
logger.error("Failed to set application name")
|
||||
logException()
|
||||
|
||||
elif CONFIG.osWindows:
|
||||
try:
|
||||
import ctypes
|
||||
appID = "io.novelwriter.%s" % __version__
|
||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(appID)
|
||||
except Exception:
|
||||
logger.error("Failed to set application name")
|
||||
logException()
|
||||
|
||||
|
||||
@@ -33,34 +33,46 @@ def testBaseInit_Launch(caplog, monkeypatch, tmpDir):
|
||||
"""
|
||||
monkeypatch.setattr("nw.guimain.GuiMain", MockGuiMain)
|
||||
|
||||
# Testmode launch
|
||||
nwGUI = nw.main(
|
||||
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
|
||||
)
|
||||
# TestMode Launch
|
||||
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||
assert isinstance(nwGUI, MockGuiMain)
|
||||
|
||||
# Darwin launch
|
||||
monkeypatch.setitem(sys.modules, "Foundation", None)
|
||||
# Darwin Launch
|
||||
caplog.clear()
|
||||
osDarwin = nw.CONFIG.osDarwin
|
||||
nw.CONFIG.osDarwin = True
|
||||
nwGUI = nw.main(
|
||||
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
|
||||
)
|
||||
assert isinstance(nwGUI, MockGuiMain)
|
||||
assert "Foundation" in caplog.messages[1]
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setitem(sys.modules, "Foundation", None)
|
||||
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||
assert isinstance(nwGUI, MockGuiMain)
|
||||
assert "Failed" in caplog.text
|
||||
|
||||
nw.CONFIG.osDarwin = osDarwin
|
||||
|
||||
# Normal launch
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *args: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationName", lambda *args: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationVersion", lambda *args: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setWindowIcon", lambda *args: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *args: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *args: 0)
|
||||
# Windows Launch
|
||||
caplog.clear()
|
||||
osWindows = nw.CONFIG.osWindows
|
||||
nw.CONFIG.osWindows = True
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setitem(sys.modules, "ctypes", None)
|
||||
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||
assert isinstance(nwGUI, MockGuiMain)
|
||||
if not sys.platform.startswith("darwin"):
|
||||
# For some reason, the test doesn't work on macOS
|
||||
assert "Failed" in caplog.text
|
||||
|
||||
nw.CONFIG.osWindows = osWindows
|
||||
|
||||
# Normal Launch
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *a: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationName", lambda *a: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationVersion", lambda *a: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setWindowIcon", lambda *a: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *a: None)
|
||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0)
|
||||
with pytest.raises(SystemExit) as ex:
|
||||
nw.main(["--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||
|
||||
assert ex.value.code == 0
|
||||
assert ex.value.code == 0
|
||||
|
||||
# END Test testBaseInit_Launch
|
||||
|
||||
|
||||
Reference in New Issue
Block a user