feat(publish): add tenant publish management with desktop deep-link

Expose tenant-authenticated publish task list and retry endpoints so the
admin web can show desktop publish state without an Electron bridge, and
register a `shengxintui://` deep-link so the page can hand off to the
desktop client workbench.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 12:07:28 +08:00
parent c347f583a4
commit c1e7c5e90c
15 changed files with 1429 additions and 56 deletions
+94 -8
View File
@@ -76,6 +76,7 @@ if (process.platform === 'win32') {
}
const isDevelopmentRuntime = !app.isPackaged
const desktopDeepLinkScheme = 'shengxintui'
function silencePackagedConsole(): void {
if (isDevelopmentRuntime) {
@@ -119,6 +120,8 @@ let mainWindowCreatePromise: Promise<ElectronBrowserWindow> | null = null
let loginWindowCreatePromise: Promise<ElectronBrowserWindow> | null = null
let settingsWindowCreatePromise: Promise<ElectronBrowserWindow> | null = null
let windowModeSwitchQueue: Promise<void> = Promise.resolve()
let canHandleDesktopDeepLinks = false
const pendingDesktopDeepLinks: string[] = []
const forceCloseWindows = new WeakSet<ElectronBrowserWindow>()
const appWindowModes = new WeakMap<ElectronBrowserWindow, RendererWindowMode>()
@@ -489,19 +492,19 @@ function queueWindowModeSwitch(
}
async function openSettingsWindow(): Promise<void> {
const window = await ensureSettingsWindow();
const parent = settingsWindowParent();
const window = await ensureSettingsWindow()
const parent = settingsWindowParent()
if (parent && window.getParentWindow() !== parent) {
window.setParentWindow(parent);
window.setParentWindow(parent)
}
await revealWindow(window);
await revealWindow(window)
}
function settingsWindowParent(): ElectronBrowserWindow | undefined {
if (process.platform !== "win32") {
return undefined;
if (process.platform !== 'win32') {
return undefined
}
return currentMainWindow() ?? undefined;
return currentMainWindow() ?? undefined
}
function rendererURL(): string | null {
@@ -713,6 +716,79 @@ function isSafeExternalUrl(url: string): boolean {
}
}
function registerDesktopProtocolClient(): void {
if (app.isDefaultProtocolClient(desktopDeepLinkScheme)) {
return
}
if (process.defaultApp && process.execPath) {
app.setAsDefaultProtocolClient(desktopDeepLinkScheme, process.execPath, [
process.argv[1] ?? '',
])
return
}
app.setAsDefaultProtocolClient(desktopDeepLinkScheme)
}
function extractDesktopDeepLink(argv: string[]): string | null {
return argv.find((item) => item.startsWith(`${desktopDeepLinkScheme}://`)) ?? null
}
function queueDesktopDeepLink(rawUrl: string | null | undefined): void {
if (!rawUrl) {
return
}
if (!canHandleDesktopDeepLinks) {
pendingDesktopDeepLinks.push(rawUrl)
return
}
handleDesktopDeepLink(rawUrl)
}
function flushPendingDesktopDeepLinks(): void {
canHandleDesktopDeepLinks = true
const links = pendingDesktopDeepLinks.splice(0)
for (const link of links) {
handleDesktopDeepLink(link)
}
}
function handleDesktopDeepLink(rawUrl: string): void {
let parsed: URL
try {
parsed = new URL(rawUrl)
} catch {
return
}
if (parsed.protocol !== `${desktopDeepLinkScheme}:` || parsed.hostname !== 'desktop') {
return
}
if (
parsed.pathname === '/workbench' ||
parsed.searchParams.get('action') === 'open-publish-account-console'
) {
const account = {
id: parsed.searchParams.get('account_id') ?? '',
platform: parsed.searchParams.get('platform') ?? '',
platformUid: parsed.searchParams.get('platform_uid') ?? '',
displayName: parsed.searchParams.get('display_name') ?? '',
}
if (!account.id || !account.platform) {
return
}
void openPublishAccountConsole(account).catch((error) => {
console.warn('[desktop-deeplink] open publish account console failed', {
accountId: account.id,
platform: account.platform,
message: error instanceof Error ? error.message : String(error),
})
})
}
}
function registerBridgeHandlers(): void {
ipcMain.handle('desktop:ping', () => 'pong')
ipcMain.handle('desktop:device-info', () => resolveDesktopDeviceInfo())
@@ -830,8 +906,9 @@ function registerBridgeHandlers(): void {
})
}
const hasSingleInstanceLock = initSingleInstance(() => {
const hasSingleInstanceLock = initSingleInstance((argv) => {
revealActiveWindowSafely('single-instance')
queueDesktopDeepLink(extractDesktopDeepLink(argv))
})
if (!hasSingleInstanceLock) {
@@ -842,6 +919,7 @@ if (!hasSingleInstanceLock) {
.whenReady()
.then(async () => {
suppressNativeWindowMenu()
registerDesktopProtocolClient()
currentWindowMode = readPersistedWindowMode()
initDesktopAppSettings()
registerBridgeHandlers()
@@ -864,6 +942,8 @@ if (!hasSingleInstanceLock) {
revealActiveWindowSafely('tray')
})
startDesktopHealthIndicator(() => currentMainWindow())
queueDesktopDeepLink(extractDesktopDeepLink(process.argv))
flushPendingDesktopDeepLinks()
})
.catch((error) => {
console.error('[desktop-main] app.whenReady failed', error)
@@ -873,6 +953,12 @@ if (!hasSingleInstanceLock) {
revealActiveWindowSafely('activate')
})
app.on('open-url', (event, url) => {
event.preventDefault()
revealActiveWindowSafely('deep-link')
queueDesktopDeepLink(url)
})
app.on('window-all-closed', () => {
if (getDesktopAppSettings().keepRunningInBackground) {
return