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()
|
bundle = NSBundle.mainBundle()
|
||||||
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
|
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
|
||||||
info["CFBundleName"] = "novelWriter"
|
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")
|
logger.error("Failed to set application name")
|
||||||
logException()
|
logException()
|
||||||
|
|
||||||
|
|||||||
@@ -33,34 +33,46 @@ def testBaseInit_Launch(caplog, monkeypatch, tmpDir):
|
|||||||
"""
|
"""
|
||||||
monkeypatch.setattr("nw.guimain.GuiMain", MockGuiMain)
|
monkeypatch.setattr("nw.guimain.GuiMain", MockGuiMain)
|
||||||
|
|
||||||
# Testmode launch
|
# TestMode Launch
|
||||||
nwGUI = nw.main(
|
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||||
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
|
|
||||||
)
|
|
||||||
assert isinstance(nwGUI, MockGuiMain)
|
assert isinstance(nwGUI, MockGuiMain)
|
||||||
|
|
||||||
# Darwin launch
|
# Darwin Launch
|
||||||
monkeypatch.setitem(sys.modules, "Foundation", None)
|
caplog.clear()
|
||||||
osDarwin = nw.CONFIG.osDarwin
|
osDarwin = nw.CONFIG.osDarwin
|
||||||
nw.CONFIG.osDarwin = True
|
nw.CONFIG.osDarwin = True
|
||||||
nwGUI = nw.main(
|
with monkeypatch.context() as mp:
|
||||||
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
|
mp.setitem(sys.modules, "Foundation", None)
|
||||||
)
|
nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||||
assert isinstance(nwGUI, MockGuiMain)
|
assert isinstance(nwGUI, MockGuiMain)
|
||||||
assert "Foundation" in caplog.messages[1]
|
assert "Failed" in caplog.text
|
||||||
|
|
||||||
nw.CONFIG.osDarwin = osDarwin
|
nw.CONFIG.osDarwin = osDarwin
|
||||||
|
|
||||||
# Normal launch
|
# Windows Launch
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *args: None)
|
caplog.clear()
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationName", lambda *args: None)
|
osWindows = nw.CONFIG.osWindows
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationVersion", lambda *args: None)
|
nw.CONFIG.osWindows = True
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setWindowIcon", lambda *args: None)
|
with monkeypatch.context() as mp:
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *args: None)
|
mp.setitem(sys.modules, "ctypes", None)
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *args: 0)
|
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:
|
with pytest.raises(SystemExit) as ex:
|
||||||
nw.main(["--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
nw.main(["--config=%s" % tmpDir, "--data=%s" % tmpDir])
|
||||||
|
assert ex.value.code == 0
|
||||||
assert ex.value.code == 0
|
|
||||||
|
|
||||||
# END Test testBaseInit_Launch
|
# END Test testBaseInit_Launch
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user