mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-08 07:12:49 +00:00
* beginnings of app directory * settings mostly good * colocate way more components * flatten components folder * reexport QueryClientProvider from client * move CodeBlock back to interface * colocate Explorer, KeyManager + more * goddamn captialisation * get toasts out of components * please eslint * no more src directory * $ instead of : * added back RowHeader component * fix settings modal padding * more spacing, less margin * fix sidebar locations button * fix tags sidebar link * clean up back button * added margin to explorer context menu to prevent contact with edge of viewport * don't export QueryClientProvider from @sd/client * basic guidelines * import interface correctly * remove old demo data * fix onboarding layout * fix onboarding navigation * fix key manager settings button --------- Co-authored-by: Jamie Pine <ijamespine@me.com>
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import { PropsWithChildren, createContext, useContext } 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) => 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;
|
|
};
|
|
|
|
// 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>;
|
|
}
|