Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

953 B
Raw Blame
import { StirlingFileStub } from "@editor/types/fileContext";
import { fileOpenService } from "@editor/services/fileOpenService";
import { useMultiWindowSupported } from "@editor/hooks/useMultiWindowSupported";
import type { OpenInNewWindowApi } from "@editor-core/extensions/openInNewWindow";

/**
 * Desktop build: open a stored file in a new Tauri window. The new window loads
 * the file by id from the shared IndexedDB store (see useOpenWindowFiles), which
 * only works where windows share one persistent web store - so this is gated on
 * useMultiWindowSupported (disabled on Linux).
 */
export function useOpenInNewWindow(): OpenInNewWindowApi {
  const supported = useMultiWindowSupported();

  return {
    canOpenInNewWindow: (file: StirlingFileStub) =>
      supported && Boolean(file.id),
    openInNewWindow: (file: StirlingFileStub) => {
      if (file.id) {
        fileOpenService.openFilesInNewWindow([file.id]);
      }
    },
  };
}