mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-29 19:06:24 +02:00
Merge pull request #1162 from CREDO23/feat/vision-autocomplete
[Feat] Multi-suggestion autocomplete, Vision LLM config & Desktop analytics
This commit is contained in:
commit
e827a3906d
49 changed files with 3263 additions and 153 deletions
50
surfsense_desktop/src/modules/analytics.ts
Normal file
50
surfsense_desktop/src/modules/analytics.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { PostHog } from 'posthog-node';
|
||||
import { machineIdSync } from 'node-machine-id';
|
||||
import { app } from 'electron';
|
||||
|
||||
let client: PostHog | null = null;
|
||||
let distinctId = '';
|
||||
|
||||
export function initAnalytics(): void {
|
||||
const key = process.env.POSTHOG_KEY;
|
||||
if (!key) return;
|
||||
|
||||
try {
|
||||
distinctId = machineIdSync(true);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
client = new PostHog(key, {
|
||||
host: process.env.POSTHOG_HOST || 'https://assets.surfsense.com',
|
||||
flushAt: 20,
|
||||
flushInterval: 10000,
|
||||
});
|
||||
}
|
||||
|
||||
export function trackEvent(event: string, properties?: Record<string, unknown>): void {
|
||||
if (!client) return;
|
||||
|
||||
try {
|
||||
client.capture({
|
||||
distinctId,
|
||||
event,
|
||||
properties: {
|
||||
platform: 'desktop',
|
||||
app_version: app.getVersion(),
|
||||
os: process.platform,
|
||||
...properties,
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
// Analytics should never break the app
|
||||
}
|
||||
}
|
||||
|
||||
export async function shutdownAnalytics(): Promise<void> {
|
||||
if (!client) return;
|
||||
|
||||
const timeout = new Promise<void>((resolve) => setTimeout(resolve, 3000));
|
||||
await Promise.race([client.shutdown(), timeout]);
|
||||
client = null;
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import { captureScreen } from './screenshot';
|
|||
import { createSuggestionWindow, destroySuggestion, getSuggestionWindow } from './suggestion-window';
|
||||
import { getShortcuts } from '../shortcuts';
|
||||
import { getActiveSearchSpaceId } from '../active-search-space';
|
||||
import { trackEvent } from '../analytics';
|
||||
|
||||
let currentShortcut = '';
|
||||
let autocompleteEnabled = true;
|
||||
|
|
@ -41,6 +42,7 @@ async function triggerAutocomplete(): Promise<void> {
|
|||
console.warn('[autocomplete] No active search space. Select a search space first.');
|
||||
return;
|
||||
}
|
||||
trackEvent('desktop_autocomplete_triggered', { search_space_id: searchSpaceId });
|
||||
const cursor = screen.getCursorScreenPoint();
|
||||
const win = createSuggestionWindow(cursor.x, cursor.y);
|
||||
|
||||
|
|
@ -87,9 +89,11 @@ function registerIpcHandlers(): void {
|
|||
ipcRegistered = true;
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.ACCEPT_SUGGESTION, async (_event, text: string) => {
|
||||
trackEvent('desktop_autocomplete_accepted');
|
||||
await acceptAndInject(text);
|
||||
});
|
||||
ipcMain.handle(IPC_CHANNELS.DISMISS_SUGGESTION, () => {
|
||||
trackEvent('desktop_autocomplete_dismissed');
|
||||
destroySuggestion();
|
||||
});
|
||||
ipcMain.handle(IPC_CHANNELS.SET_AUTOCOMPLETE_ENABLED, (_event, enabled: boolean) => {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { checkAccessibilityPermission, getFrontmostApp, simulateCopy, simulatePa
|
|||
import { getServerPort } from './server';
|
||||
import { getShortcuts } from './shortcuts';
|
||||
import { getActiveSearchSpaceId } from './active-search-space';
|
||||
import { trackEvent } from './analytics';
|
||||
|
||||
let currentShortcut = '';
|
||||
let quickAskWindow: BrowserWindow | null = null;
|
||||
|
|
@ -121,6 +122,7 @@ async function quickAskHandler(): Promise<void> {
|
|||
|
||||
sourceApp = getFrontmostApp();
|
||||
console.log('[quick-ask] Source app:', sourceApp, '| Opening Quick Assist with', text.length, 'chars', selected ? '(selected)' : text ? '(clipboard fallback)' : '(empty)');
|
||||
trackEvent('desktop_quick_ask_opened', { has_selected_text: !!selected });
|
||||
openQuickAsk(text);
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +154,7 @@ function registerIpcHandlers(): void {
|
|||
|
||||
if (!checkAccessibilityPermission()) return;
|
||||
|
||||
trackEvent('desktop_quick_ask_replaced');
|
||||
clipboard.writeText(text);
|
||||
destroyQuickAsk();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue