mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-21 06:59:17 -04:00
* log to disk * remove some unwraps * panicless * some p2p error handling * clippy moment * Fix `<ErrorBoundary />` * open logs button * 39 to 0 * fix types * update deps and comment out broken tests * clippy * more clippy * upgrade rimraf - https://github.com/isaacs/rimraf/issues/259 * regen broken lockfile * update `notify` and update `commands.ts` * more clippy (pls work) * allow deprecated for p2p (hopefully temporary) * a * upgrade deps for p2p * do betterer * do it correctly * remove unused import * improve core startup error + bc keypair --------- Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com> Co-authored-by: brxken128 <77554505+brxken128@users.noreply.github.com>
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { PropsWithChildren, createContext, useContext, useState } from 'react';
|
|
|
|
export type OperatingSystem = 'browser' | 'linux' | 'macOS' | 'windows' | 'unknown';
|
|
|
|
// Platform represents the underlying native layer the app is running on.
|
|
// This could be Tauri or web.
|
|
export type Platform = {
|
|
platform: 'web' | 'tauri'; // This represents the specific platform implementation
|
|
getThumbnailUrlById: (casId: string) => string;
|
|
getFileUrl: (
|
|
libraryId: string,
|
|
locationLocalId: number,
|
|
filePathId: number,
|
|
_linux_workaround?: boolean
|
|
) => string;
|
|
openLink: (url: string) => void;
|
|
demoMode?: boolean; // TODO: Remove this in favour of demo mode being handled at the React Query level
|
|
getOs?(): Promise<OperatingSystem>;
|
|
openDirectoryPickerDialog?(): Promise<null | string | string[]>;
|
|
openFilePickerDialog?(): Promise<null | string | string[]>;
|
|
saveFilePickerDialog?(): Promise<string | null>;
|
|
showDevtools?(): void;
|
|
openPath?(path: string): void;
|
|
openLogsDir?(): void;
|
|
// Opens a file path with a given ID
|
|
openFilePath?(library: string, id: number): any;
|
|
getFilePathOpenWithApps?(library: string, id: number): any;
|
|
openFilePathWith?(library: string, id: number, appUrl: string): any;
|
|
};
|
|
|
|
// Keep this private and use through helpers below
|
|
const context = createContext<Platform>(undefined!);
|
|
|
|
// is a hook which allows you to fetch information about the current platform from the React context.
|
|
export function usePlatform(): Platform {
|
|
const ctx = useContext(context);
|
|
if (!ctx)
|
|
throw new Error(
|
|
"The 'PlatformProvider' has not been mounted above the current 'usePlatform' call."
|
|
);
|
|
|
|
return ctx;
|
|
}
|
|
|
|
// provides the platform context to the rest of the app through React context.
|
|
// Mount it near the top of your component tree.
|
|
export function PlatformProvider({
|
|
platform,
|
|
children
|
|
}: PropsWithChildren<{ platform: Platform }>) {
|
|
return <context.Provider value={platform}>{children}</context.Provider>;
|
|
}
|