Files
spacedrive/interface/util/Platform.tsx
ameer2468 7cbbaefee8 [ENG-1413] Full disk access perms (#1791)
* fda wip

* clippy

* add tauri invoke fns for FDA

* fda wip

* clippy

* add tauri invoke fns for FDA

* wip

* fda wip

* clippy

* add tauri invoke fns for FDA

* wip

* wip

* wip fda

* remove imports

* hopefully improve FDA

* execute only on macos

* ts

* ts

* Update Platform.tsx

* Update AddLocationButton.tsx

* remove console log

* fix: fda and add unit tests

* temp commit for Jake

* add fda state and keybind handling (so the frontend is kept up to date)

* update FDA

* update imports

* testing purposes

* Jakes work

* fix fda checks

* work in progress (but not working)

* remove dead files

* attempt #2

* !!!temporarily enable devtools in prod

* remove alert

* show FDA screen but don't require it

* add an FDA button to general client settings

* Update AddLocationButton.tsx

* remove dead code

* unused dep

* old errors

* remove import

* dead code

* dead code + typesafety

* eslint

* remove fda dialog references

* remove mp4 vid

* hopefully fix onboarding for non-macos OSes

* shorter nav

---------

Co-authored-by: jake <77554505+brxken128@users.noreply.github.com>
2023-11-23 20:54:45 +00:00

89 lines
3.3 KiB
TypeScript

import { createContext, useContext, type PropsWithChildren } from 'react';
import { auth } from '@sd/client';
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) => string;
getFileUrlByPath: (path: string) => 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?(opts?: { title?: string; multiple: false }): Promise<null | string>;
openDirectoryPickerDialog?(opts?: {
title?: string;
multiple?: boolean;
}): Promise<null | string | string[]>;
openFilePickerDialog?(): Promise<null | string | string[]>;
saveFilePickerDialog?(opts?: { title?: string; defaultPath?: string }): 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;
openEphemeralFiles?(paths: string[]): any;
revealItems?(
library: string,
items: (
| { Location: { id: number } }
| { FilePath: { id: number } }
| { Ephemeral: { path: string } }
)[]
): Promise<unknown>;
requestFdaMacos?(): void;
getFilePathOpenWithApps?(library: string, ids: number[]): Promise<unknown>;
reloadWebview?(): Promise<unknown>;
getEphemeralFilesOpenWithApps?(paths: string[]): Promise<unknown>;
openFilePathWith?(library: string, fileIdsAndAppUrls: [number, string][]): Promise<unknown>;
openEphemeralFileWith?(pathsAndUrls: [string, string][]): Promise<unknown>;
refreshMenuBar?(): Promise<unknown>;
setMenuBarItemState?(id: string, enabled: boolean): Promise<unknown>;
lockAppTheme?(themeType: 'Auto' | 'Light' | 'Dark'): any;
updater?: {
useSnapshot: () => UpdateStore;
checkForUpdate(): Promise<Update | null>;
installUpdate(): Promise<any>;
runJustUpdatedCheck(onViewChangelog: () => void): Promise<void>;
};
auth: auth.ProviderConfig;
landingApiOrigin: string;
};
export type Update = { version: string; body: string | null };
export type UpdateStore =
| { status: 'idle' }
| { status: 'loading' }
| { status: 'error' }
| { status: 'updateAvailable'; update: Update }
| { status: 'noUpdateAvailable' }
| { status: 'installing' };
// 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>;
}