Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
refactor(web-app): drop unused Cowork exports and share the background flush
thinhlpg8bd4453353be
diff --git a/web-app/src/containers/CoworkSessionNotice.tsx b/web-app/src/containers/CoworkSessionNotice.tsxindex 48cc3e9cb..f1ca4dc75 100644--- a/web-app/src/containers/CoworkSessionNotice.tsx+++ b/web-app/src/containers/CoworkSessionNotice.tsx@@ -10,11 +10,10 @@ import { getServiceHub } from '@/hooks/useServiceHub'import { backendStorage } from '@/lib/backendStorage'import { exportCoworkSession } from '@/lib/coworkExport'import { retryCoworkImport } from '@/lib/coworkSync'+import type { CopyLeftOut } from '@/lib/migrateCoworkSessions'/** Ids whose "files left out" notice the user closed (JSON array). */-export const COWORK_LEFT_OUT_DISMISSED_KEY = 'cowork_left_out_dismissed'--type LeftOut = { skipped: number; unreadable: number }+const COWORK_LEFT_OUT_DISMISSED_KEY = 'cowork_left_out_dismissed'const readDismissed = async (): Promise<string[]> => {try {@@ -52,7 +51,7 @@ export function CoworkSessionNotice({(session &&(s.threads[session.id]?.metadata?.migratedFrom as- | { leftOut?: LeftOut }+ | { leftOut?: CopyLeftOut }| undefined)?.leftOut) ||undefineddiff --git a/web-app/src/lib/coworkExport.ts b/web-app/src/lib/coworkExport.tsindex 99ef1ed2c..d582b3ca5 100644--- a/web-app/src/lib/coworkExport.ts+++ b/web-app/src/lib/coworkExport.ts@@ -3,7 +3,7 @@ import { getServiceHub } from '@/hooks/useServiceHub'import type { Invoke } from '@/lib/migrateCoworkSessions'/** Data-folder-relative directory exports land in. */-export const COWORK_EXPORT_DIR = 'cowork-exports'+const COWORK_EXPORT_DIR = 'cowork-exports'/*** Save one Cowork session, exactly as the app holds it, todiff --git a/web-app/src/lib/coworkPersistence.ts b/web-app/src/lib/coworkPersistence.tsindex 215057ea9..c13753ef4 100644--- a/web-app/src/lib/coworkPersistence.ts+++ b/web-app/src/lib/coworkPersistence.ts@@ -200,14 +200,14 @@ export function sessionFromThread(* (`sessionToSidecar`, what the migration and older builds write) still holds* the transcript arrays itself.*/-export type CoworkStateSidecar = {+type CoworkStateSidecar = {version: 2subagents?: CoworkSession['subagents']lastUsage?: CoworkSession['lastUsage']todos?: CoworkSession['todos']}-export function sessionToStateSidecar(s: CoworkSession): CoworkStateSidecar {+function sessionToStateSidecar(s: CoworkSession): CoworkStateSidecar {return {version: 2,...(s.subagents !== undefined && { subagents: s.subagents }),diff --git a/web-app/src/lib/coworkSync.ts b/web-app/src/lib/coworkSync.tsindex 137dcd8e2..3f718a897 100644--- a/web-app/src/lib/coworkSync.ts+++ b/web-app/src/lib/coworkSync.ts@@ -502,7 +502,7 @@ async function finishLateMigration(}}-export type CoworkImportRetry =+type CoworkImportRetry =| { imported: true }| { imported: false; error: string }@@ -587,30 +587,29 @@ async function hidesOnClose(): Promise<boolean> {}}+/** Save every pending write without holding anything up; failures are logged. */+function flushInBackground(failureMessage: string) {+ void flushAllWrites().then((writes) => {+ const failed = writes.find((r) => r.status === 'rejected')+ if (failed?.status === 'rejected') {+ console.warn(`[cowork] ${failureMessage}:`, failed.reason)+ }+ })+}+async function installCloseHandlers() {if (closeListenersInstalled) returncloseListenersInstalled = trueif (typeof document !== 'undefined') {document.addEventListener('visibilitychange', () => {- if (document.visibilityState === 'hidden') {- void flushAllWrites().then((writes) => {- const failed = writes.find((r) => r.status === 'rejected')- if (failed?.status === 'rejected') {- console.warn('[cowork] background flush failed:', failed.reason)- }- })- }+ if (document.visibilityState === 'hidden')+ flushInBackground('background flush failed')})}if (typeof window === 'undefined') return- window.addEventListener('beforeunload', () => {- void flushAllWrites().then((writes) => {- const failed = writes.find((r) => r.status === 'rejected')- if (failed?.status === 'rejected') {- console.warn('[cowork] unload flush failed:', failed.reason)- }- })- })+ window.addEventListener('beforeunload', () =>+ flushInBackground('unload flush failed')+ )try {const { getCurrentWindow } = await import('@tauri-apps/api/window')const appWindow = getCurrentWindow()@@ -620,12 +619,7 @@ async function installCloseHandlers() {// the background, and prevent the destroy() that would quit the app.if (await hidesOnClose()) {event.preventDefault()- void flushAllWrites().then((writes) => {- const failed = writes.find((r) => r.status === 'rejected')- if (failed?.status === 'rejected') {- console.warn('[cowork] flush on hide failed:', failed.reason)- }- })+ flushInBackground('flush on hide failed')return}// A real close quits the app. Awaiting here holds it until every queueddiff --git a/web-app/src/lib/migrateCoworkSessions.ts b/web-app/src/lib/migrateCoworkSessions.tsindex e23158540..22e29dee4 100644--- a/web-app/src/lib/migrateCoworkSessions.ts+++ b/web-app/src/lib/migrateCoworkSessions.ts@@ -107,7 +107,7 @@ export type CopyLeftOut = { skipped: number; unreadable: number }* migration writes anything: it holds the only copy of the old sessions, and* the file is rewritten whole on every settings change.*/-export const COWORK_SETTINGS_BACKUP_LABEL = 'pre-cowork-migration'+const COWORK_SETTINGS_BACKUP_LABEL = 'pre-cowork-migration'type MigrationDeps = { copyWorkspace?: CopyWorkspace }