-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtrigger-snippet-load.ts
More file actions
100 lines (81 loc) · 3.34 KB
/
trigger-snippet-load.ts
File metadata and controls
100 lines (81 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { connectToSuperhuman, disconnect, openCompose, closeCompose } from "./src/superhuman-api";
async function main() {
const conn = await connectToSuperhuman(9333);
if (!conn) { console.log("No connection"); process.exit(1); }
console.log("Checking snippets before triggering...\n");
let beforeResult = await conn.Runtime.evaluate({
expression: `window.ViewState?.account?.settings?.get?.('snippets')`,
returnByValue: true,
});
console.log("Before:", JSON.stringify(beforeResult.result.value, null, 2));
// Open compose and trigger snippet picker
console.log("\nOpening compose and triggering g ; ...");
const draftKey = await openCompose(conn);
// Wait a moment
await new Promise(r => setTimeout(r, 500));
// Press g
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: "g", code: "KeyG", text: "g" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: "g", code: "KeyG" });
await new Promise(r => setTimeout(r, 100));
// Press ;
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: ";", code: "Semicolon", text: ";" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: ";", code: "Semicolon" });
// Wait for snippet picker to load
await new Promise(r => setTimeout(r, 2000));
console.log("Checking snippets after triggering...\n");
let afterResult = await conn.Runtime.evaluate({
expression: `
(() => {
const account = window.ViewState?.account;
const settings = account?.settings;
const snippets = settings?.get?.('snippets');
// Also check for snippet picker state
const vs = window.ViewState;
const snippetPicker = vs?._snippetPicker || vs?.snippetPicker;
// Check compose controller for snippet data
const cfc = vs?._composeFormController;
const draftKey = cfc ? Object.keys(cfc)[0] : null;
const ctrl = draftKey ? cfc[draftKey] : null;
// Look for snippets in controller props
let ctrlSnippets = null;
if (ctrl?.props?.snippets) {
ctrlSnippets = {
count: Object.keys(ctrl.props.snippets).length,
names: Object.values(ctrl.props.snippets).map(s => s.shortcut || s.name)
};
}
// Check if snippets are in a different property
let foundSnippets = null;
if (ctrl) {
const ctrlKeys = Object.keys(ctrl);
const snippetKeys = ctrlKeys.filter(k => k.toLowerCase().includes('snippet'));
if (snippetKeys.length > 0) {
foundSnippets = snippetKeys.map(k => ({
key: k,
type: typeof ctrl[k],
preview: JSON.stringify(ctrl[k])?.slice(0, 200)
}));
}
}
return {
email: account?.emailAddress,
snippetsFromSettings: snippets,
snippetPickerExists: !!snippetPicker,
ctrlSnippets,
foundSnippets
};
})()
`,
returnByValue: true,
});
console.log("After:", JSON.stringify(afterResult.result.value, null, 2));
// Press Escape to close picker
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: "Escape", code: "Escape" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: "Escape", code: "Escape" });
// Close compose
if (draftKey) {
await closeCompose(conn, draftKey);
}
await disconnect(conn);
}
main().catch(console.error);