@todesktop/plugin-recall 1.0.2 → 1.0.4

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.
package/src/store.ts CHANGED
@@ -2,7 +2,9 @@
2
2
  * Recall Desktop SDK plugin state management and storage
3
3
  */
4
4
 
5
- import { RecallSdkConfig, MeetingWindow, PermissionType } from './shared';
5
+ import type { PluginContext, RecallSdkConfig } from './shared';
6
+
7
+ let pluginContext: PluginContext | undefined;
6
8
 
7
9
  class RecallSdkStore {
8
10
  private config: RecallSdkConfig = {
@@ -13,22 +15,6 @@ class RecallSdkStore {
13
15
 
14
16
  private initialized = false;
15
17
  private sdkInitialized = false;
16
- private currentSdkState: 'recording' | 'idle' | 'paused' = 'idle';
17
-
18
- // Active meetings and recordings
19
- private activeMeetings = new Map<string, MeetingWindow>();
20
- private activeRecordings = new Map<string, { window: MeetingWindow; uploadToken: string }>();
21
-
22
- // Permission status
23
- private permissions = {
24
- accessibility: false,
25
- screenCapture: false,
26
- microphone: false,
27
- systemAudio: false,
28
- };
29
-
30
- // Event listeners for SDK events
31
- private eventListeners = new Set<(event: any) => void>();
32
18
 
33
19
  /**
34
20
  * Initialize the plugin store
@@ -64,7 +50,7 @@ class RecallSdkStore {
64
50
  /**
65
51
  * Load configuration from ToDesktop preferences
66
52
  */
67
- loadFromPreferences(preferences: Record<string, any>): void {
53
+ loadFromPreferences(preferences: Partial<RecallSdkConfig>): void {
68
54
  if (preferences.enabled !== undefined) {
69
55
  this.config.enabled = preferences.enabled;
70
56
  }
@@ -106,161 +92,50 @@ class RecallSdkStore {
106
92
  return this.sdkInitialized;
107
93
  }
108
94
 
109
- /**
110
- * Set current SDK state
111
- */
112
- setSdkState(state: 'recording' | 'idle' | 'paused'): void {
113
- this.currentSdkState = state;
114
- }
115
-
116
- /**
117
- * Get current SDK state
118
- */
119
- getSdkState(): 'recording' | 'idle' | 'paused' {
120
- return this.currentSdkState;
121
- }
122
-
123
- /**
124
- * Add an active meeting
125
- */
126
- addMeeting(meeting: MeetingWindow): void {
127
- this.activeMeetings.set(meeting.id, meeting);
128
- console.log(`RecallSdkStore: Added meeting ${meeting.id}:`, meeting);
129
- }
130
-
131
- /**
132
- * Remove a meeting
133
- */
134
- removeMeeting(windowId: string): void {
135
- this.activeMeetings.delete(windowId);
136
- console.log(`RecallSdkStore: Removed meeting ${windowId}`);
137
- }
138
-
139
- /**
140
- * Get active meeting by window ID
141
- */
142
- getMeeting(windowId: string): MeetingWindow | undefined {
143
- return this.activeMeetings.get(windowId);
144
- }
145
-
146
- /**
147
- * Get all active meetings
148
- */
149
- getAllMeetings(): MeetingWindow[] {
150
- return Array.from(this.activeMeetings.values());
151
- }
152
-
153
- /**
154
- * Start a recording
155
- */
156
- startRecording(windowId: string, uploadToken: string): void {
157
- const window = this.activeMeetings.get(windowId);
158
- if (window) {
159
- this.activeRecordings.set(windowId, { window, uploadToken });
160
- console.log(`RecallSdkStore: Started recording for ${windowId}`);
161
- }
162
- }
163
-
164
- /**
165
- * Stop a recording
166
- */
167
- stopRecording(windowId: string): void {
168
- this.activeRecordings.delete(windowId);
169
- console.log(`RecallSdkStore: Stopped recording for ${windowId}`);
170
- }
171
-
172
- /**
173
- * Get active recording by window ID
174
- */
175
- getRecording(windowId: string): { window: MeetingWindow; uploadToken: string } | undefined {
176
- return this.activeRecordings.get(windowId);
177
- }
178
-
179
- /**
180
- * Get all active recordings
181
- */
182
- getAllRecordings(): { window: MeetingWindow; uploadToken: string }[] {
183
- return Array.from(this.activeRecordings.values());
184
- }
185
-
186
- /**
187
- * Update permission status
188
- */
189
- setPermissionStatus(permission: PermissionType, status: string): void {
190
- const granted = status === 'granted' || status === 'authorized' || status === 'ALLOWED';
191
- if (permission === 'screen-capture') {
192
- this.permissions.screenCapture = granted;
193
- } else if (permission === 'system-audio') {
194
- this.permissions.systemAudio = granted;
195
- } else {
196
- // permission is 'accessibility' | 'microphone'
197
- // @ts-ignore - index by key
198
- this.permissions[permission] = granted;
199
- }
200
- console.log(`RecallSdkStore: Permission ${permission} status: ${status}`);
201
- }
202
-
203
- /**
204
- * Get permission status
205
- */
206
- getPermissions(): { accessibility: boolean; screenCapture: boolean; microphone: boolean; systemAudio: boolean } {
207
- return { ...this.permissions };
208
- }
209
-
210
- /**
211
- * Check if all required permissions are granted
212
- */
213
- arePermissionsGranted(): boolean {
214
- return (
215
- this.permissions.accessibility &&
216
- this.permissions.screenCapture &&
217
- this.permissions.microphone
218
- );
219
- }
220
-
221
- /**
222
- * Add event listener for SDK events
223
- */
224
- addEventListener(listener: (event: any) => void): void {
225
- this.eventListeners.add(listener);
226
- }
227
-
228
- /**
229
- * Remove event listener
230
- */
231
- removeEventListener(listener: (event: any) => void): void {
232
- this.eventListeners.delete(listener);
233
- }
234
-
235
- /**
236
- * Emit event to all listeners
237
- */
238
- emitEvent(event: any): void {
239
- this.eventListeners.forEach(listener => {
240
- try {
241
- listener(event);
242
- } catch (error) {
243
- console.error('RecallSdkStore: Error in event listener:', error);
244
- }
245
- });
246
- }
247
-
248
95
  /**
249
96
  * Clear all state (useful for shutdown/reset)
250
97
  */
251
98
  clearState(): void {
252
- this.activeMeetings.clear();
253
- this.activeRecordings.clear();
254
99
  this.setSdkInitialized(false);
255
- this.setSdkState('idle');
256
- this.permissions = {
257
- accessibility: false,
258
- screenCapture: false,
259
- microphone: false,
260
- systemAudio: false,
261
- };
262
100
  console.log('RecallSdkStore: Cleared all state');
263
101
  }
264
102
  }
265
103
 
266
104
  export const recallSdkStore = new RecallSdkStore();
105
+
106
+ /**
107
+ * Persist the ToDesktop plugin context and hydrate the store configuration.
108
+ */
109
+ export const setPluginContext = (input: PluginContext): void => {
110
+ pluginContext = input;
111
+
112
+ const [enabledPref, apiUrlPref, requestPref] =
113
+ input.plugin?.todesktop?.preferences ?? [];
114
+
115
+ const preferences: Partial<RecallSdkConfig> = {
116
+ enabled:
117
+ typeof enabledPref?.spec?.value === 'boolean'
118
+ ? enabledPref.spec.value
119
+ : undefined,
120
+ apiUrl:
121
+ typeof apiUrlPref?.spec?.value === 'string' && apiUrlPref.spec.value.trim()
122
+ ? apiUrlPref.spec.value
123
+ : undefined,
124
+ requestPermissionsOnStartup:
125
+ typeof requestPref?.spec?.value === 'boolean'
126
+ ? requestPref.spec.value
127
+ : undefined,
128
+ };
129
+
130
+ recallSdkStore.loadFromPreferences(preferences);
131
+ };
132
+
133
+ /**
134
+ * Accessor for the stored plugin context.
135
+ */
136
+ export const getPluginContext = (): PluginContext => {
137
+ if (!pluginContext) {
138
+ throw new Error('Plugin context has not been set');
139
+ }
140
+ return pluginContext;
141
+ };