Skip to content

The only downloader you need. 下载器的集大成者。

feat(browser): distinguish silent wake from active launch via protocol URL

XiaoYouChRf3bc18ef25bb
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index a3c6dce7..7bf7e3fc 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -140,7 +140,7 @@ def startApp(application, isSilent=False):
else:
window = MainWindow(taskService, featureService, browserService, categoryService, speedMeter, coroutineRunner, plan, updateService)
- if not isSilent:
+ if not isSilent and sys.platform != "darwin":
from qfluentwidgets import SplashScreen
splash = SplashScreen(window.windowIcon(), window, enableShadow=False)
splash.raise_()
@@ -150,7 +150,7 @@ def startApp(application, isSilent=False):
window.setupPacks()
startEngine(taskService, speedMeter, featureService, coroutineRunner)
- if not isSilent:
+ if not isSilent and sys.platform != "darwin":
splash.finish()
from app.platform.windows import emptyWorkingSet
@@ -185,7 +185,8 @@ def startApp(application, isSilent=False):
window.destroyed.connect(onWindowDestroyed)
window.addTasks(tasks)
- signalBus.activationRequested.connect(show)
+ if sys.platform != "darwin":
+ signalBus.activationRequested.connect(show)
signalBus.openUriRequested.connect(lambda uris: show().addUrls(uris))
signalBus.exceptionCaught.connect(lambda msg: show().alertException(msg))
browserService.taskDraftRequested.connect(onBrowserDraft)
@@ -236,6 +237,19 @@ def startApp(application, isSilent=False):
if isSilent:
emptyWorkingSetIfIdle()
+ if sys.platform == "darwin":
+ if isSilent:
+ signalBus.activationRequested.connect(show)
+ else:
+ from PySide6.QtCore import QTimer
+
+ def _onColdStartDecide():
+ signalBus.activationRequested.connect(show)
+ if not application._isWakeLaunch:
+ show()
+
+ QTimer.singleShot(0, _onColdStartDecide)
+
from app.services.update_service import UpdateState
def onUpdateChanged(info):
if info.targetId == "app" and info.state == UpdateState.AVAILABLE:
@@ -261,8 +275,10 @@ def startApp(application, isSilent=False):
if __name__ == "__main__":
from app.config.constants import DESKTOP_ID
from app.platform.application import SingletonApplication
+ from app.platform.url_scheme import isWakeUri
setupEnvironment()
app = SingletonApplication(sys.argv, DESKTOP_ID)
- startApp(app, isSilent="--silence" in sys.argv)
+ isSilent = "--silence" in sys.argv or any(isWakeUri(arg) for arg in sys.argv[1:])
+ startApp(app, isSilent=isSilent)
sys.exit(app.exec())
diff --git a/app/platform/application.py b/app/platform/application.py
index 56628d6c..cf48e13c 100644
--- a/app/platform/application.py
+++ b/app/platform/application.py
@@ -11,7 +11,7 @@ from loguru import logger
from app.config.constants import DESKTOP_ID, DESKTOP_OBJECT_PATH
from app.platform.android import IS_ANDROID
-from app.platform.url_scheme import isLaunchUri
+from app.platform.url_scheme import isLaunchUri, isWakeUri
from app.signal_bus import signalBus
@@ -37,6 +37,7 @@ class SingletonApplication(QApplication):
self._key = key
self.isFileDragActive = False
self.clipboardListener = None
+ self._isWakeLaunch = False
self._memory: QSharedMemory | None = None
self._lockSingleInstance()
@@ -64,7 +65,10 @@ class SingletonApplication(QApplication):
if isinstance(e, QFileOpenEvent):
uri = e.url().toString() if not e.url().isEmpty() else Path(e.file()).as_uri()
if uri and isLaunchUri(uri):
- signalBus.activationRequested.emit()
+ if isWakeUri(uri):
+ self._isWakeLaunch = True
+ else:
+ signalBus.activationRequested.emit()
elif uri:
signalBus.openUriRequested.emit([uri])
return True
@@ -89,10 +93,11 @@ class SingletonApplication(QApplication):
self._memory.setKey(self._key)
if self._memory.attach():
- if sys.platform == "win32":
- _sendToRunningWindows()
- elif sys.platform == "linux":
- _sendToRunningLinux()
+ if not any(isWakeUri(arg) for arg in sys.argv[1:]):
+ if sys.platform == "win32":
+ _sendToRunningWindows()
+ elif sys.platform == "linux":
+ _sendToRunningLinux()
sys.exit(-1)
if not self._memory.create(1):
@@ -206,6 +211,8 @@ if sys.platform == "linux":
class _DesktopBusReceiver(QObject):
@Slot("QStringList", "QVariantMap")
def Open(self, uris, platformData):
+ if any(isWakeUri(u) for u in uris):
+ return
if any(isLaunchUri(u) for u in uris):
signalBus.activationRequested.emit()
return
diff --git a/app/platform/url_scheme.py b/app/platform/url_scheme.py
index 4984c33e..8fbf2e00 100644
--- a/app/platform/url_scheme.py
+++ b/app/platform/url_scheme.py
@@ -32,6 +32,10 @@ def isLaunchUri(uri: str) -> bool:
return uri.startswith(f"{URL_SCHEME}://")
+def isWakeUri(uri: str) -> bool:
+ return uri == f"{URL_SCHEME}://wake"
+
+
if sys.platform == "win32":
import winreg
diff --git a/browser_extension/app/src/background.ts b/browser_extension/app/src/background.ts
index 68295f85..84384994 100644
--- a/browser_extension/app/src/background.ts
+++ b/browser_extension/app/src/background.ts
@@ -58,6 +58,7 @@ async function sendTaskOrEnqueue<T extends CommandResult>(payload: Record<string
}
}
await enqueue(payload);
+ autoLaunchPending = true;
return { ok: true, message: chrome.i18n.getMessage("taskQueued") } as T;
}
@@ -421,8 +422,6 @@ async function takeBrowserDownload(
if (totalBytes >= 0 && totalBytes < minTakeSizeKB * 1024) { return; }
}
- const wasReady = desktopBridge.isReady();
-
try {
await cancelDownload(downloadItem.id);
if (options.eraseFromHistory) {
@@ -432,10 +431,6 @@ async function takeBrowserDownload(
// Cleanup failed but the browser will still finish the download as fallback.
}
- if (!wasReady) {
- autoLaunchPending = true;
- }
-
await resourceBridge.routeBrowserDownload(downloadItem);
}
diff --git a/browser_extension/app/src/popup/App.tsx b/browser_extension/app/src/popup/App.tsx
index 0d6f8c7f..3bf78172 100644
--- a/browser_extension/app/src/popup/App.tsx
+++ b/browser_extension/app/src/popup/App.tsx
@@ -9,7 +9,7 @@ import {ImagesPage} from "./pages/ImagesPage";
import {ResourcesPage} from "./pages/ResourcesPage";
import {SettingsPage} from "./pages/SettingsPage";
import {ToastHost} from "./components/ToastHost";
-import {launchDesktop} from "./launch-desktop";
+import {launchDesktop, wakeDesktop} from "./launch-desktop";
import {usePopupBridge} from "./usePopupBridge";
const useStyles = makeStyles({
@@ -44,7 +44,7 @@ export function App({
chrome.runtime.sendMessage({ type: "popup_mounted" }, (response) => {
void chrome.runtime.lastError;
if (response?.autoLaunch) {
- launchDesktop();
+ wakeDesktop();
}
});
}, []);
diff --git a/browser_extension/app/src/popup/launch-desktop.ts b/browser_extension/app/src/popup/launch-desktop.ts
index 49d13378..3824cf5a 100644
--- a/browser_extension/app/src/popup/launch-desktop.ts
+++ b/browser_extension/app/src/popup/launch-desktop.ts
@@ -1,3 +1,7 @@
export function launchDesktop(): void {
window.location.href = "ghostdownloader://launch";
}
+
+export function wakeDesktop(): void {
+ window.location.href = "ghostdownloader://wake";
+}