import type { copyFile, create, exists, lstat, mkdir, readDir, readFile, readTextFile, remove, rename, stat, truncate, writeFile, writeTextFile } from "@tauri-apps/plugin-fs" import type { IShell as IShell1, IPath as ITauriPath } from "tauri-api-adapter" import type { Child, ChildProcess, CommandEvents, hasCommand, InternalSpawnOptions, IOPayload, likelyOnWindows, OutputEvents, SpawnOptions } from "tauri-plugin-shellx-api" import { EventEmitter, open as shellxOpen } from "tauri-plugin-shellx-api" import * as v from "valibot" import { KV, type JarvisExtDB } from "../commands/db" import type { fileSearch } from "../commands/fileSearch" import { type AppInfo } from "../models/apps" import type { LightMode, Position, Radius, ThemeColor } from "../models/styles" import type { DenoSysOptions } from "../permissions/schema" import type { MarkdownSchema } from "./worker" import { type IComponent } from "./worker/components/interfaces" import type { Markdown } from "./worker/components/markdown" import * as FormSchema from "./worker/schema/form" import * as ListSchema from "./worker/schema/list" type PromiseWrap any> = ( ...args: Parameters ) => Promise> export type IPath = ITauriPath & { extensionDir: () => Promise extensionSupportDir: () => Promise } export interface IPlist { // build: PromiseWrap parse: (plistContent: string) => Promise } export interface IUtils { plist: IPlist } export interface ISystem { openTrash(): Promise emptyTrash(): Promise shutdown(): Promise reboot(): Promise sleep(): Promise toggleSystemAppearance(): Promise showDesktop(): Promise quitAllApps(): Promise sleepDisplays(): Promise setVolume(percentage: number): Promise setVolumeTo0(): Promise setVolumeTo25(): Promise setVolumeTo50(): Promise setVolumeTo75(): Promise setVolumeTo100(): Promise turnVolumeUp(): Promise turnVolumeDown(): Promise toggleStageManager(): Promise toggleBluetooth(): Promise toggleHiddenFiles(): Promise ejectAllDisks(): Promise logoutUser(): Promise toggleMute(): Promise mute(): Promise unmute(): Promise getFrontmostApp(): Promise hideAllAppsExceptFrontmost(): Promise getSelectedFilesInFileExplorer(): Promise } export type GeneralToastParams = { description?: string duration?: number closeButton?: boolean position?: | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top-center" | "bottom-center" actionLabel?: string } export type GeneralToast = ( message: string, options?: GeneralToastParams, action?: () => void ) => Promise export interface IToast { message: GeneralToast info: GeneralToast success: GeneralToast warning: GeneralToast error: GeneralToast } export interface IUiWorker { render: (view: IComponent) => Promise goBack: () => Promise showLoadingBar: (loading: boolean) => Promise setScrollLoading: (loading: boolean) => Promise setSearchTerm: (term: string) => Promise setSearchBarPlaceholder: (placeholder: string) => Promise setProgressBar: (progress: number | null) => Promise } export interface IUiIframe { // goHome: () => Promise goBack: () => Promise hideBackButton: () => Promise hideMoveButton: () => Promise hideRefreshButton: () => Promise /** * position can be "top-left" | "top-right" | "bottom-left" | "bottom-right" | CustomPosition * `CustomPosition` is an object with optional `top`, `right`, `bottom`, `left` properties * Each property is a number, with `rem` unit, and will be applied to css `top`, `right`, `bottom`, `left` properties * @param position "top-left" | "top-right" | "bottom-left" | "bottom-right" | CustomPosition * @example * ```ts * ui.showBackButton({ top: 2, left: 2 }) * ui.showBackButton('top-right') * ``` * @returns */ showBackButton: (position?: Position) => Promise /** * position can be "top-left" | "top-right" | "bottom-left" | "bottom-right" | CustomPosition * `CustomPosition` is an object with optional `top`, `right`, `bottom`, `left` properties * Each property is a number, with `rem` unit, and will be applied to css `top`, `right`, `bottom`, `left` properties * @param position "top-left" | "top-right" | "bottom-left" | "bottom-right" | CustomPosition * @example * ```ts * ui.showBackButton({ top: 2, left: 2 }) * ui.showBackButton('top-right') * ``` * @returns */ showMoveButton: (position?: Position) => Promise showRefreshButton: (position?: Position) => Promise getTheme: () => Promise<{ theme: ThemeColor radius: Radius lightMode: LightMode }> reloadPage: () => Promise startDragging: () => Promise toggleMaximize: () => Promise internalToggleMaximize: () => Promise setTransparentWindowBackground: (transparent: boolean) => Promise registerDragRegion: () => Promise } export interface IDb { add: typeof JarvisExtDB.prototype.add delete: typeof JarvisExtDB.prototype.delete search: typeof JarvisExtDB.prototype.search retrieveAll: typeof JarvisExtDB.prototype.retrieveAll retrieveAllByType: typeof JarvisExtDB.prototype.retrieveAllByType deleteAll: typeof JarvisExtDB.prototype.deleteAll update: typeof JarvisExtDB.prototype.update } export interface IKV { get: typeof KV.prototype.get set: typeof KV.prototype.set exists: typeof KV.prototype.exists delete: typeof KV.prototype.delete } export interface IFs { readDir: typeof readDir readFile: typeof readFile readTextFile: typeof readTextFile stat: typeof stat lstat: typeof lstat exists: typeof exists mkdir: typeof mkdir create: typeof create copyFile: typeof copyFile remove: typeof remove rename: typeof rename truncate: typeof truncate writeFile: typeof writeFile writeTextFile: typeof writeTextFile fileSearch: typeof fileSearch } export interface IOpen { url: (url: string) => Promise file: (path: string) => Promise folder: (path: string) => Promise } /* -------------------------------------------------------------------------- */ /* Event API */ /* -------------------------------------------------------------------------- */ export type DragDropPayload = { paths: string[] position: { x: number; y: number } } export type DragEnterPayload = DragDropPayload export type DragOverPayload = { position: { x: number; y: number } } export interface IEvent { /** * Get files dropped on the window */ onDragDrop: (callback: (payload: DragDropPayload) => void) => void /** * Listen to drag enter event, when mouse drag enters the window */ onDragEnter: (callback: (payload: DragEnterPayload) => void) => void /** * Listen to drag leave event, when mouse drag leaves the window */ onDragLeave: (callback: () => void) => void /** * Get the position of the dragged item */ onDragOver: (callback: (payload: DragOverPayload) => void) => void /** * Listen to window blur (defocus) event */ onWindowBlur: (callback: () => void) => void /** * Listen to window close request event */ onWindowCloseRequested: (callback: () => void) => void /** * Listen to window on focus event */ onWindowFocus: (callback: () => void) => void } /** * https://docs.deno.com/runtime/fundamentals/security/ */ export interface DenoRunConfig { allowNet?: string[] allowAllNet?: boolean allowRead?: string[] allowAllRead?: boolean allowWrite?: string[] allowAllWrite?: boolean allowRun?: string[] allowAllRun?: boolean allowEnv?: string[] allowAllEnv?: boolean allowFfi?: string[] allowAllFfi?: boolean allowSys?: DenoSysOptions[] allowAllSys?: boolean denyNet?: string[] denyAllNet?: boolean denyRead?: string[] denyAllRead?: boolean denyWrite?: string[] denyAllWrite?: boolean denyRun?: string[] denyAllRun?: boolean denyEnv?: string[] denyAllEnv?: boolean denyFfi?: string[] denyAllFfi?: boolean denySys?: DenoSysOptions[] denyAllSys?: boolean } export interface IApp { language: () => Promise<"en" | "zh"> } export const MacSecurityOptions = v.union([ v.literal("ScreenCapture"), v.literal("Camera"), v.literal("Microphone"), v.literal("Accessibility"), v.literal("AllFiles") ]) export type MacSecurityOptions = v.InferOutput export interface ISecurity { mac: { revealSecurityPane: (privacyOption?: MacSecurityOptions) => Promise resetPermission: (privacyOption: MacSecurityOptions) => Promise verifyFingerprint: () => Promise requestScreenCapturePermission: () => Promise checkScreenCapturePermission: () => Promise } }