@vicinae/api 0.21.1 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,11 +11,18 @@ export type Image = {
11
11
  tintColor?: ColorLike | undefined | null;
12
12
  mask?: Image.Mask | undefined | null;
13
13
  };
14
+ /**
15
+ * Renders the system icon associated with the given file path.
16
+ * @category Image
17
+ */
18
+ type FileIcon = {
19
+ fileIcon: string;
20
+ };
14
21
  /**
15
22
  * @category Image
16
23
  */
17
24
  export type ImageLike = Image.ImageLike;
18
- export type SerializedImageLike = URL | Image.Asset | Icon | api.Image | Image.ThemedImage;
25
+ export type SerializedImageLike = URL | Image.Asset | Icon | api.Image | Image.ThemedImage | FileIcon;
19
26
  /**
20
27
  * @category Image
21
28
  */
@@ -31,10 +38,11 @@ export declare namespace Image {
31
38
  light: URL | Asset;
32
39
  dark: URL | Asset;
33
40
  };
34
- type ImageLike = URL | Image.Asset | Icon | Image | Image.ThemedImage;
41
+ type ImageLike = URL | Image.Asset | Icon | Image | Image.ThemedImage | FileIcon;
35
42
  enum Mask {
36
43
  Circle = "circle",
37
44
  RoundedRectangle = "roundedRectangle"
38
45
  }
39
46
  }
40
47
  export declare const serializeProtoImage: (image: ImageLike) => api.Image;
48
+ export {};
package/dist/api/image.js CHANGED
@@ -14,6 +14,9 @@ var Image;
14
14
  Mask["RoundedRectangle"] = "roundedRectangle";
15
15
  })(Mask = Image.Mask || (Image.Mask = {}));
16
16
  })(Image || (exports.Image = Image = {}));
17
+ const isFileIcon = (v) => typeof v === "object" &&
18
+ v !== null &&
19
+ typeof v.fileIcon === "string";
17
20
  const maskMap = {
18
21
  [Image.Mask.Circle]: "Circle",
19
22
  [Image.Mask.RoundedRectangle]: "RoundedRectangle",
@@ -31,6 +34,9 @@ const serializeProtoImage = (image) => {
31
34
  if (image instanceof URL || typeof image === "string") {
32
35
  return { source: { raw: image.toString() } };
33
36
  }
37
+ if (isFileIcon(image)) {
38
+ return { fileIcon: image.fileIcon };
39
+ }
34
40
  const img = image;
35
41
  // img.source should technically not be null, but it somehow still happens at times with some
36
42
  // raycast extensions
@@ -19,6 +19,7 @@ export type ImageMask = "None" | "Circle" | "RoundedRectangle";
19
19
  export type ToastStyle = "Success" | "Info" | "Warning" | "Error" | "Dynamic";
20
20
  export type PopToRootType = "Default" | "Immediate" | "Suspended";
21
21
  export type ConfirmAlertActionStyle = "Default" | "Destructive" | "Cancel";
22
+ export type NotificationUrgency = "Low" | "Normal" | "High";
22
23
  export type Application = {
23
24
  id: string;
24
25
  name: string;
@@ -50,10 +51,11 @@ export type ColorLike = {
50
51
  dynamic?: DynamicColor;
51
52
  };
52
53
  export type Image = {
53
- source: ImageSource;
54
+ source?: ImageSource;
54
55
  fallback?: ImageSource;
55
56
  mask?: ImageMask;
56
57
  tintColor?: ColorLike;
58
+ fileIcon?: string;
57
59
  };
58
60
  export type ConfirmAlertAction = {
59
61
  title: string;
@@ -67,6 +69,12 @@ export type ConfirmAlertPayload = {
67
69
  rememberUserChoice: boolean;
68
70
  icon?: Image;
69
71
  };
72
+ export type DesktopNotificationPayload = {
73
+ title: string;
74
+ body: string;
75
+ icon?: Image;
76
+ urgency: NotificationUrgency;
77
+ };
70
78
  export type Rect = {
71
79
  x: number;
72
80
  y: number;
@@ -167,6 +175,7 @@ declare class UIService {
167
175
  popView(): Promise<void>;
168
176
  setSearchText(text: string): Promise<void>;
169
177
  getSelectedText(): Promise<string>;
178
+ sendDesktopNotification(data: DesktopNotificationPayload): Promise<void>;
170
179
  viewPoped(handler: () => void): EventSubscription;
171
180
  viewPushed(handler: () => void): EventSubscription;
172
181
  }
@@ -133,6 +133,9 @@ class UIService {
133
133
  getSelectedText() {
134
134
  return this.transport.request("UI/getSelectedText", {});
135
135
  }
136
+ sendDesktopNotification(data) {
137
+ return this.transport.request("UI/sendDesktopNotification", { data });
138
+ }
136
139
  viewPoped(handler) {
137
140
  return this.transport.subscribe("UI/viewPoped", (msg) => handler());
138
141
  }
@@ -1,5 +1,6 @@
1
1
  import type { PathLike } from "node:fs";
2
- import type { Application } from "./proto/api";
2
+ import type { Application, NotificationUrgency } from "./proto/api";
3
+ import { ImageLike } from "./image";
3
4
  /**
4
5
  @ignore - we should probably move this to raycast compat, I don't think we want that.
5
6
  */
@@ -84,4 +85,33 @@ export declare const getDefaultApplication: (path: string) => Promise<Applicatio
84
85
  * @category System
85
86
  */
86
87
  export declare const showInFileBrowser: (path: PathLike, options?: ShowInFileBrowserOptions) => Promise<void>;
88
+ export type DesktopNotificationOptions = {
89
+ /**
90
+ * The title of the notification, usually shown at the very top.
91
+ */
92
+ title: string;
93
+ /**
94
+ * The content of the notification.
95
+ * How much you can fit in there highly depends on the capabilities of the running notification server.
96
+ * Similarly, your notification server may accept the use of some markup language to further style the content.
97
+ */
98
+ body: string;
99
+ /**
100
+ * Icon used to represent the notification, usually positionned on the left.
101
+ */
102
+ icon?: ImageLike;
103
+ /**
104
+ * Urgency level associated with the notification.
105
+ */
106
+ urgency?: NotificationUrgency;
107
+ };
108
+ /**
109
+ * @category System
110
+ */
111
+ export declare const sendDesktopNotification: (payload: {
112
+ title: string;
113
+ body: string;
114
+ icon?: ImageLike;
115
+ urgency?: NotificationUrgency;
116
+ }) => Promise<void>;
87
117
  export type { Application } from "./proto/api";
package/dist/api/utils.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.showInFileBrowser = exports.getDefaultApplication = exports.getApplications = exports.getFrontmostApplication = exports.open = exports.runInTerminal = exports.trash = void 0;
3
+ exports.sendDesktopNotification = exports.showInFileBrowser = exports.getDefaultApplication = exports.getApplications = exports.getFrontmostApplication = exports.open = exports.runInTerminal = exports.trash = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const window_management_1 = require("./window-management");
6
6
  const client_1 = require("./client");
7
+ const image_1 = require("./image");
7
8
  /**
8
9
  @ignore - we should probably move this to raycast compat, I don't think we want that.
9
10
  */
@@ -87,3 +88,13 @@ const showInFileBrowser = async (path, options = {}) => {
87
88
  await (0, client_1.getClient)().Application.showInFileBrowser(path.toString(), options.select ?? true);
88
89
  };
89
90
  exports.showInFileBrowser = showInFileBrowser;
91
+ /**
92
+ * @category System
93
+ */
94
+ const sendDesktopNotification = (payload) => (0, client_1.getClient)().UI.sendDesktopNotification({
95
+ title: payload.title,
96
+ body: payload.body,
97
+ icon: payload.icon ? (0, image_1.serializeProtoImage)(payload.icon) : undefined,
98
+ urgency: payload.urgency ?? "Normal",
99
+ });
100
+ exports.sendDesktopNotification = sendDesktopNotification;
@@ -1,3 +1,45 @@
1
+ export type Format = (string?: string) => string;
2
+ export declare const reset: Format;
3
+ export declare const bold: Format;
4
+ export declare const dim: Format;
5
+ export declare const italic: Format;
6
+ export declare const underline: Format;
7
+ export declare const overline: Format;
8
+ export declare const inverse: Format;
9
+ export declare const hidden: Format;
10
+ export declare const strikethrough: Format;
11
+ export declare const black: Format;
12
+ export declare const red: Format;
13
+ export declare const green: Format;
14
+ export declare const yellow: Format;
15
+ export declare const blue: Format;
16
+ export declare const magenta: Format;
17
+ export declare const cyan: Format;
18
+ export declare const white: Format;
19
+ export declare const gray: Format;
20
+ export declare const bgBlack: Format;
21
+ export declare const bgRed: Format;
22
+ export declare const bgGreen: Format;
23
+ export declare const bgYellow: Format;
24
+ export declare const bgBlue: Format;
25
+ export declare const bgMagenta: Format;
26
+ export declare const bgCyan: Format;
27
+ export declare const bgWhite: Format;
28
+ export declare const bgGray: Format;
29
+ export declare const redBright: Format;
30
+ export declare const greenBright: Format;
31
+ export declare const yellowBright: Format;
32
+ export declare const blueBright: Format;
33
+ export declare const magentaBright: Format;
34
+ export declare const cyanBright: Format;
35
+ export declare const whiteBright: Format;
36
+ export declare const bgRedBright: Format;
37
+ export declare const bgGreenBright: Format;
38
+ export declare const bgYellowBright: Format;
39
+ export declare const bgBlueBright: Format;
40
+ export declare const bgMagentaBright: Format;
41
+ export declare const bgCyanBright: Format;
42
+ export declare const bgWhiteBright: Format;
1
43
  export declare class Logger {
2
44
  prefixes: {
3
45
  error: string;
@@ -1,13 +1,92 @@
1
1
  "use strict";
2
+ // https://github.com/sindresorhus/yoctocolors
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = void 0;
4
- const yoctocolors_1 = require("./yoctocolors");
7
+ exports.Logger = exports.bgWhiteBright = exports.bgCyanBright = exports.bgMagentaBright = exports.bgBlueBright = exports.bgYellowBright = exports.bgGreenBright = exports.bgRedBright = exports.whiteBright = exports.cyanBright = exports.magentaBright = exports.blueBright = exports.yellowBright = exports.greenBright = exports.redBright = exports.bgGray = exports.bgWhite = exports.bgCyan = exports.bgMagenta = exports.bgBlue = exports.bgYellow = exports.bgGreen = exports.bgRed = exports.bgBlack = exports.gray = exports.white = exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = exports.black = exports.strikethrough = exports.hidden = exports.inverse = exports.overline = exports.underline = exports.italic = exports.dim = exports.bold = exports.reset = void 0;
8
+ const node_tty_1 = __importDefault(require("node:tty"));
9
+ // eslint-disable-next-line no-warning-comments
10
+ // TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
11
+ // Lots of optionals here to support Deno.
12
+ const hasColors = node_tty_1.default?.WriteStream?.prototype?.hasColors?.() ?? false;
13
+ const format = (open, close) => {
14
+ if (!hasColors) {
15
+ return (input) => input ?? "";
16
+ }
17
+ const openCode = `\u001B[${open}m`;
18
+ const closeCode = `\u001B[${close}m`;
19
+ return (input = "") => {
20
+ let index = input.indexOf(closeCode);
21
+ if (index === -1) {
22
+ // Note: Intentionally not using string interpolation for performance reasons.
23
+ return openCode + input + closeCode;
24
+ }
25
+ // Handle nested colors.
26
+ // We could have done this, but it's too slow (as of Node.js 22).
27
+ // return openCode + string.replaceAll(closeCode, (close === 22 ? closeCode : '') + openCode) + closeCode;
28
+ let result = openCode;
29
+ let lastIndex = 0;
30
+ // SGR 22 resets both bold (1) and dim (2). When we encounter a nested
31
+ // close for styles that use 22, we need to re-open the outer style.
32
+ const reopenOnNestedClose = close === 22;
33
+ const replaceCode = (reopenOnNestedClose ? closeCode : "") + openCode;
34
+ while (index !== -1) {
35
+ result += input.slice(lastIndex, index) + replaceCode;
36
+ lastIndex = index + closeCode.length;
37
+ index = input.indexOf(closeCode, lastIndex);
38
+ }
39
+ result += input.slice(lastIndex) + closeCode;
40
+ return result;
41
+ };
42
+ };
43
+ exports.reset = format(0, 0);
44
+ exports.bold = format(1, 22);
45
+ exports.dim = format(2, 22);
46
+ exports.italic = format(3, 23);
47
+ exports.underline = format(4, 24);
48
+ exports.overline = format(53, 55);
49
+ exports.inverse = format(7, 27);
50
+ exports.hidden = format(8, 28);
51
+ exports.strikethrough = format(9, 29);
52
+ exports.black = format(30, 39);
53
+ exports.red = format(31, 39);
54
+ exports.green = format(32, 39);
55
+ exports.yellow = format(33, 39);
56
+ exports.blue = format(34, 39);
57
+ exports.magenta = format(35, 39);
58
+ exports.cyan = format(36, 39);
59
+ exports.white = format(37, 39);
60
+ exports.gray = format(90, 39);
61
+ exports.bgBlack = format(40, 49);
62
+ exports.bgRed = format(41, 49);
63
+ exports.bgGreen = format(42, 49);
64
+ exports.bgYellow = format(43, 49);
65
+ exports.bgBlue = format(44, 49);
66
+ exports.bgMagenta = format(45, 49);
67
+ exports.bgCyan = format(46, 49);
68
+ exports.bgWhite = format(47, 49);
69
+ exports.bgGray = format(100, 49);
70
+ exports.redBright = format(91, 39);
71
+ exports.greenBright = format(92, 39);
72
+ exports.yellowBright = format(93, 39);
73
+ exports.blueBright = format(94, 39);
74
+ exports.magentaBright = format(95, 39);
75
+ exports.cyanBright = format(96, 39);
76
+ exports.whiteBright = format(97, 39);
77
+ exports.bgRedBright = format(101, 49);
78
+ exports.bgGreenBright = format(102, 49);
79
+ exports.bgYellowBright = format(103, 49);
80
+ exports.bgBlueBright = format(104, 49);
81
+ exports.bgMagentaBright = format(105, 49);
82
+ exports.bgCyanBright = format(106, 49);
83
+ exports.bgWhiteBright = format(107, 49);
5
84
  class Logger {
6
85
  prefixes = {
7
- error: `${(0, yoctocolors_1.red)("error")}${(0, yoctocolors_1.reset)()}`,
8
- event: `${(0, yoctocolors_1.magenta)("event")}${(0, yoctocolors_1.reset)()}`,
9
- info: `${(0, yoctocolors_1.blue)("info")}${(0, yoctocolors_1.reset)()}`,
10
- ready: `${(0, yoctocolors_1.green)("ready")}${(0, yoctocolors_1.reset)()}`,
86
+ error: `${(0, exports.red)("error")}${(0, exports.reset)()}`,
87
+ event: `${(0, exports.magenta)("event")}${(0, exports.reset)()}`,
88
+ info: `${(0, exports.blue)("info")}${(0, exports.reset)()}`,
89
+ ready: `${(0, exports.green)("ready")}${(0, exports.reset)()}`,
11
90
  };
12
91
  logError(message) {
13
92
  console.log(`${this.prefixes.error.padEnd(15)} - ${message}`);
@@ -25,7 +104,7 @@ class Logger {
25
104
  this.logTimestamp(s);
26
105
  }
27
106
  logExtensionError(s) {
28
- this.logTimestamp(`${(0, yoctocolors_1.red)(s)}${(0, yoctocolors_1.reset)()}`);
107
+ this.logTimestamp(`${(0, exports.red)(s)}${(0, exports.reset)()}`);
29
108
  }
30
109
  logTimestamp(s) {
31
110
  const ts = new Date().toJSON();
@@ -34,7 +113,7 @@ class Logger {
34
113
  const line = lines[i];
35
114
  if (i === lines.length - 1 && line.length === 0)
36
115
  continue;
37
- console.log(`${(0, yoctocolors_1.gray)(ts.padEnd(20))}${(0, yoctocolors_1.reset)()} - ${line}`);
116
+ console.log(`${(0, exports.gray)(ts.padEnd(20))}${(0, exports.reset)()} - ${line}`);
38
117
  }
39
118
  }
40
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vicinae/api",
3
- "version": "0.21.1",
3
+ "version": "0.21.3",
4
4
  "description": "TypeScript SDK to build Vicinae extensions",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,42 +0,0 @@
1
- export type Format = (string?: string) => string;
2
- export declare const reset: Format;
3
- export declare const bold: Format;
4
- export declare const dim: Format;
5
- export declare const italic: Format;
6
- export declare const underline: Format;
7
- export declare const overline: Format;
8
- export declare const inverse: Format;
9
- export declare const hidden: Format;
10
- export declare const strikethrough: Format;
11
- export declare const black: Format;
12
- export declare const red: Format;
13
- export declare const green: Format;
14
- export declare const yellow: Format;
15
- export declare const blue: Format;
16
- export declare const magenta: Format;
17
- export declare const cyan: Format;
18
- export declare const white: Format;
19
- export declare const gray: Format;
20
- export declare const bgBlack: Format;
21
- export declare const bgRed: Format;
22
- export declare const bgGreen: Format;
23
- export declare const bgYellow: Format;
24
- export declare const bgBlue: Format;
25
- export declare const bgMagenta: Format;
26
- export declare const bgCyan: Format;
27
- export declare const bgWhite: Format;
28
- export declare const bgGray: Format;
29
- export declare const redBright: Format;
30
- export declare const greenBright: Format;
31
- export declare const yellowBright: Format;
32
- export declare const blueBright: Format;
33
- export declare const magentaBright: Format;
34
- export declare const cyanBright: Format;
35
- export declare const whiteBright: Format;
36
- export declare const bgRedBright: Format;
37
- export declare const bgGreenBright: Format;
38
- export declare const bgYellowBright: Format;
39
- export declare const bgBlueBright: Format;
40
- export declare const bgMagentaBright: Format;
41
- export declare const bgCyanBright: Format;
42
- export declare const bgWhiteBright: Format;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- // https://github.com/sindresorhus/yoctocolors
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.bgWhiteBright = exports.bgCyanBright = exports.bgMagentaBright = exports.bgBlueBright = exports.bgYellowBright = exports.bgGreenBright = exports.bgRedBright = exports.whiteBright = exports.cyanBright = exports.magentaBright = exports.blueBright = exports.yellowBright = exports.greenBright = exports.redBright = exports.bgGray = exports.bgWhite = exports.bgCyan = exports.bgMagenta = exports.bgBlue = exports.bgYellow = exports.bgGreen = exports.bgRed = exports.bgBlack = exports.gray = exports.white = exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = exports.black = exports.strikethrough = exports.hidden = exports.inverse = exports.overline = exports.underline = exports.italic = exports.dim = exports.bold = exports.reset = void 0;
8
- const node_tty_1 = __importDefault(require("node:tty"));
9
- // eslint-disable-next-line no-warning-comments
10
- // TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
11
- // Lots of optionals here to support Deno.
12
- const hasColors = node_tty_1.default?.WriteStream?.prototype?.hasColors?.() ?? false;
13
- const format = (open, close) => {
14
- if (!hasColors) {
15
- return (input) => input ?? "";
16
- }
17
- const openCode = `\u001B[${open}m`;
18
- const closeCode = `\u001B[${close}m`;
19
- return (input = "") => {
20
- let index = input.indexOf(closeCode);
21
- if (index === -1) {
22
- // Note: Intentionally not using string interpolation for performance reasons.
23
- return openCode + input + closeCode;
24
- }
25
- // Handle nested colors.
26
- // We could have done this, but it's too slow (as of Node.js 22).
27
- // return openCode + string.replaceAll(closeCode, (close === 22 ? closeCode : '') + openCode) + closeCode;
28
- let result = openCode;
29
- let lastIndex = 0;
30
- // SGR 22 resets both bold (1) and dim (2). When we encounter a nested
31
- // close for styles that use 22, we need to re-open the outer style.
32
- const reopenOnNestedClose = close === 22;
33
- const replaceCode = (reopenOnNestedClose ? closeCode : "") + openCode;
34
- while (index !== -1) {
35
- result += input.slice(lastIndex, index) + replaceCode;
36
- lastIndex = index + closeCode.length;
37
- index = input.indexOf(closeCode, lastIndex);
38
- }
39
- result += input.slice(lastIndex) + closeCode;
40
- return result;
41
- };
42
- };
43
- exports.reset = format(0, 0);
44
- exports.bold = format(1, 22);
45
- exports.dim = format(2, 22);
46
- exports.italic = format(3, 23);
47
- exports.underline = format(4, 24);
48
- exports.overline = format(53, 55);
49
- exports.inverse = format(7, 27);
50
- exports.hidden = format(8, 28);
51
- exports.strikethrough = format(9, 29);
52
- exports.black = format(30, 39);
53
- exports.red = format(31, 39);
54
- exports.green = format(32, 39);
55
- exports.yellow = format(33, 39);
56
- exports.blue = format(34, 39);
57
- exports.magenta = format(35, 39);
58
- exports.cyan = format(36, 39);
59
- exports.white = format(37, 39);
60
- exports.gray = format(90, 39);
61
- exports.bgBlack = format(40, 49);
62
- exports.bgRed = format(41, 49);
63
- exports.bgGreen = format(42, 49);
64
- exports.bgYellow = format(43, 49);
65
- exports.bgBlue = format(44, 49);
66
- exports.bgMagenta = format(45, 49);
67
- exports.bgCyan = format(46, 49);
68
- exports.bgWhite = format(47, 49);
69
- exports.bgGray = format(100, 49);
70
- exports.redBright = format(91, 39);
71
- exports.greenBright = format(92, 39);
72
- exports.yellowBright = format(93, 39);
73
- exports.blueBright = format(94, 39);
74
- exports.magentaBright = format(95, 39);
75
- exports.cyanBright = format(96, 39);
76
- exports.whiteBright = format(97, 39);
77
- exports.bgRedBright = format(101, 49);
78
- exports.bgGreenBright = format(102, 49);
79
- exports.bgYellowBright = format(103, 49);
80
- exports.bgBlueBright = format(104, 49);
81
- exports.bgMagentaBright = format(105, 49);
82
- exports.bgCyanBright = format(106, 49);
83
- exports.bgWhiteBright = format(107, 49);