mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-19 14:08:45 -04:00
* Some initial drafts * Finising the first draft on non-indexed locations * Minor tweaks * Fix warnings * Adding date_created and date_modified to non indexed path entries * Add id and path properties to NonIndexedPathItem * Working ephemeral location (hardcoded home for now) * Fix UI for ephemeral locations * Fix windows * Passing ephemeral thumbnails to thumbnails remover * Indexing rules for ephemeral paths walking * Animate Location button when path text overflow it's size * Fix Linux not showing all volumes * Fix Linux - Add some missing no_os_protected rules for macOS - Improve ephemeral location names * Remove unecessary import * Fix Mobile * Improve resizing behaviour for ephemeral location topbar path button - Improve Search View (Replace custom empty component with Explorer's emptyNotice ) - Improve how TopBar children positioning * Hide EphemeralSection if there is no volume or home - Disable Ephemeral topbar path button animation when text is not overflowing * minor fixes * Introducing ordering for ephemeral paths * TS Format * Ephemeral locations UI fixes - Fix indexed Locations having no metadata - Remove date indexed/accessed options for sorting Ephemeral locations - Remove empty three dots from SideBar element when no settings is linked * Add tooltip to add location button in ephemeral locations * Fix indexed Locations selecting other folder/files in Ephemeral location * Minor fixes * Fix app breaking due to wrong logic to get item full path in Explorer * Revert some recent changes to Thumb.tsx * Fix original not loading for overview items - Fix QuickPreview name broken for overview items * Improve imports * Revert replace useEffect with useLayoutEffect for locked logic in ListView It was causing the component to full reload when clicking a header to sort per column * Changes from feedback * Hide some unused Inspector metadata fields on NonIndexedPaths - Merge formatDate functions while retaining original behaviour * Use tauri api for getting user home * Change ThumbType to a string enum to allow for string comparisons * Improve ObjectKind typing --------- Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { type 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
|
|
getThumbnailUrlByThumbKey: (thumbKey: string[]) => string;
|
|
getFileUrl: (
|
|
libraryId: string,
|
|
locationLocalId: number,
|
|
filePathId: number,
|
|
_linux_workaround?: boolean
|
|
) => string;
|
|
openLink: (url: string) => void;
|
|
// Tauri patches `window.confirm` to return `Promise` not `bool`
|
|
confirm(msg: string, cb: (result: boolean) => void): void;
|
|
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;
|
|
userHomeDir?(): Promise<string>;
|
|
// Opens a file path with a given ID
|
|
openFilePaths?(library: string, ids: number[]): any;
|
|
revealItems?(
|
|
library: string,
|
|
items: ({ Location: { id: number } } | { FilePath: { id: number } })[]
|
|
): Promise<unknown>;
|
|
getFilePathOpenWithApps?(library: string, ids: number[]): Promise<unknown>;
|
|
openFilePathWith?(library: string, fileIdsAndAppUrls: [number, string][]): Promise<unknown>;
|
|
lockAppTheme?(themeType: 'Auto' | 'Light' | 'Dark'): 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>;
|
|
}
|