Initial commit: file-browser-picker Paseo plugin
This commit is contained in:
commit
069e1d2082
15 files changed
+5599
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import { defineRpc } from "@getpaseo/plugin";
|
||||
import { z } from "zod";
|
||||
|
||||
const pickInput = z.object({
|
||||
// Folder the file browser starts in. Falls back to the start folder in
|
||||
// plugin settings, then the home folder on the host.
|
||||
initialDir: z.string().optional(),
|
||||
});
|
||||
|
||||
export const openOutput = z.discriminatedUnion("status", [
|
||||
z.object({
|
||||
status: z.literal("opened"),
|
||||
path: z.string(),
|
||||
name: z.string(),
|
||||
workspaceId: z.string(),
|
||||
projectId: z.string().nullable(),
|
||||
picker: z.string(),
|
||||
}),
|
||||
z.object({ status: z.literal("cancelled"), picker: z.string() }),
|
||||
z.object({ status: z.literal("error"), message: z.string() }),
|
||||
]);
|
||||
|
||||
export const pickAndOpenRpc = defineRpc({
|
||||
name: "picker.pick_and_open",
|
||||
input: pickInput,
|
||||
output: openOutput,
|
||||
});
|
||||
|
||||
export const openFolderRpc = defineRpc({
|
||||
name: "picker.open_folder",
|
||||
input: z.object({ path: z.string() }),
|
||||
output: openOutput,
|
||||
});
|
||||
|
||||
export const pickRpc = defineRpc({
|
||||
name: "picker.pick",
|
||||
input: pickInput,
|
||||
output: z.discriminatedUnion("status", [
|
||||
z.object({ status: z.literal("picked"), path: z.string(), picker: z.string() }),
|
||||
z.object({ status: z.literal("cancelled"), picker: z.string() }),
|
||||
z.object({ status: z.literal("error"), message: z.string() }),
|
||||
]),
|
||||
});
|
||||
|
||||
export const detectRpc = defineRpc({
|
||||
name: "picker.detect",
|
||||
input: z.object({}),
|
||||
output: z.object({
|
||||
platform: z.string(),
|
||||
desktop: z.string().nullable(),
|
||||
pickers: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
label: z.string(),
|
||||
available: z.boolean(),
|
||||
detail: z.string(),
|
||||
}),
|
||||
),
|
||||
recommended: z.string().nullable(),
|
||||
effectivePicker: z.string().nullable(),
|
||||
defaultStartDir: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const listDirRpc = defineRpc({
|
||||
name: "picker.list_dir",
|
||||
input: z.object({
|
||||
path: z.string().optional(),
|
||||
showHidden: z.boolean().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("status", [
|
||||
z.object({
|
||||
status: z.literal("ok"),
|
||||
path: z.string(),
|
||||
parent: z.string().nullable(),
|
||||
home: z.string(),
|
||||
entries: z.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
path: z.string(),
|
||||
isGitRepo: z.boolean(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
z.object({
|
||||
status: z.literal("error"),
|
||||
message: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { defineSettings } from "@getpaseo/plugin";
|
||||
import { z } from "zod";
|
||||
|
||||
export const pickerSchema = z.object({
|
||||
// Which program draws the folder picker on the host. "auto" tries the
|
||||
// desktop's own picker first, then the XDG portal dialog.
|
||||
picker: z
|
||||
.enum(["auto", "kdialog", "zenity", "yad", "portal", "osascript", "powershell", "custom"])
|
||||
.default("auto"),
|
||||
// Used only when picker is "custom". The command runs in a shell on the
|
||||
// host and must print the chosen folder to stdout. {dir} is replaced with
|
||||
// the start folder.
|
||||
customCommand: z.string().default(""),
|
||||
// Folder the picker starts in. Empty means the home folder on the host.
|
||||
startDir: z.string().default(""),
|
||||
// Title shown by the file browser dialog.
|
||||
prompt: z.string().default("Select project folder"),
|
||||
});
|
||||
|
||||
export type PickerSettings = z.output<typeof pickerSchema>;
|
||||
|
||||
// Host scope: the picker runs on the machine running the daemon, so the
|
||||
// choice belongs to that host, not to each connected client.
|
||||
export const pickerSettings = defineSettings({
|
||||
id: "picker",
|
||||
scope: "host",
|
||||
version: 1,
|
||||
schema: pickerSchema,
|
||||
});
|
||||
|
||||
export const defaultPickerSettings: PickerSettings = {
|
||||
picker: "auto",
|
||||
customCommand: "",
|
||||
startDir: "",
|
||||
prompt: "Select project folder",
|
||||
};
|
||||
Reference in new issue
Block a user