mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 13:52:40 +02:00
switch to on-demand permission requests and improve suggestion UX
This commit is contained in:
parent
aeb3f13f91
commit
c5aa869adb
12 changed files with 195 additions and 89 deletions
|
|
@ -9,6 +9,7 @@ export const IPC_CHANNELS = {
|
|||
// Permissions
|
||||
GET_PERMISSIONS_STATUS: 'get-permissions-status',
|
||||
REQUEST_ACCESSIBILITY: 'request-accessibility',
|
||||
REQUEST_SCREEN_RECORDING: 'request-screen-recording',
|
||||
RESTART_APP: 'restart-app',
|
||||
// Autocomplete
|
||||
AUTOCOMPLETE_CONTEXT: 'autocomplete-context',
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { IPC_CHANNELS } from './channels';
|
|||
import {
|
||||
getPermissionsStatus,
|
||||
requestAccessibility,
|
||||
requestScreenRecording,
|
||||
restartApp,
|
||||
} from '../modules/permissions';
|
||||
|
||||
|
|
@ -30,6 +31,10 @@ export function registerIpcHandlers(): void {
|
|||
requestAccessibility();
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.REQUEST_SCREEN_RECORDING, () => {
|
||||
requestScreenRecording();
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.RESTART_APP, () => {
|
||||
restartApp();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { setupMenu } from './modules/menu';
|
|||
import { registerQuickAsk, unregisterQuickAsk } from './modules/quick-ask';
|
||||
import { registerAutocomplete, unregisterAutocomplete } from './modules/autocomplete';
|
||||
import { registerIpcHandlers } from './ipc/handlers';
|
||||
import { allPermissionsGranted } from './modules/permissions';
|
||||
|
||||
registerGlobalErrorHandlers();
|
||||
|
||||
|
|
@ -18,14 +17,6 @@ if (!setupDeepLinks()) {
|
|||
|
||||
registerIpcHandlers();
|
||||
|
||||
function getInitialPath(): string {
|
||||
const granted = allPermissionsGranted();
|
||||
if (process.platform === 'darwin' && !granted) {
|
||||
return '/desktop/permissions';
|
||||
}
|
||||
return '/dashboard';
|
||||
}
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
setupMenu();
|
||||
try {
|
||||
|
|
@ -36,8 +27,7 @@ app.whenReady().then(async () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const initialPath = getInitialPath();
|
||||
createMainWindow(initialPath);
|
||||
createMainWindow('/dashboard');
|
||||
registerQuickAsk();
|
||||
registerAutocomplete();
|
||||
setupAutoUpdater();
|
||||
|
|
@ -46,7 +36,7 @@ app.whenReady().then(async () => {
|
|||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createMainWindow(getInitialPath());
|
||||
createMainWindow('/dashboard');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { clipboard, globalShortcut, ipcMain, screen } from 'electron';
|
||||
import { IPC_CHANNELS } from '../../ipc/channels';
|
||||
import { getFrontmostApp, hasAccessibilityPermission, simulatePaste } from '../platform';
|
||||
import { hasScreenRecordingPermission, requestAccessibility, requestScreenRecording } from '../permissions';
|
||||
import { getMainWindow } from '../window';
|
||||
import { captureScreen } from './screenshot';
|
||||
import { createSuggestionWindow, destroySuggestion, getSuggestionWindow } from './suggestion-window';
|
||||
|
|
@ -19,9 +20,13 @@ function isSurfSenseWindow(): boolean {
|
|||
|
||||
async function triggerAutocomplete(): Promise<void> {
|
||||
if (!autocompleteEnabled) return;
|
||||
if (!hasAccessibilityPermission()) return;
|
||||
if (isSurfSenseWindow()) return;
|
||||
|
||||
if (!hasScreenRecordingPermission()) {
|
||||
requestScreenRecording();
|
||||
return;
|
||||
}
|
||||
|
||||
sourceApp = getFrontmostApp();
|
||||
savedClipboard = clipboard.readText();
|
||||
|
||||
|
|
@ -59,7 +64,11 @@ async function triggerAutocomplete(): Promise<void> {
|
|||
|
||||
async function acceptAndInject(text: string): Promise<void> {
|
||||
if (!sourceApp) return;
|
||||
if (!hasAccessibilityPermission()) return;
|
||||
|
||||
if (!hasAccessibilityPermission()) {
|
||||
requestAccessibility();
|
||||
return;
|
||||
}
|
||||
|
||||
clipboard.writeText(text);
|
||||
destroySuggestion();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ type PermissionStatus = 'authorized' | 'denied' | 'not determined' | 'restricted
|
|||
|
||||
export interface PermissionsStatus {
|
||||
accessibility: PermissionStatus;
|
||||
screenRecording: PermissionStatus;
|
||||
}
|
||||
|
||||
function isMac(): boolean {
|
||||
|
|
@ -16,18 +17,19 @@ function getNodeMacPermissions() {
|
|||
|
||||
export function getPermissionsStatus(): PermissionsStatus {
|
||||
if (!isMac()) {
|
||||
return { accessibility: 'authorized' };
|
||||
return { accessibility: 'authorized', screenRecording: 'authorized' };
|
||||
}
|
||||
|
||||
const perms = getNodeMacPermissions();
|
||||
return {
|
||||
accessibility: perms.getAuthStatus('accessibility'),
|
||||
screenRecording: perms.getAuthStatus('screen'),
|
||||
};
|
||||
}
|
||||
|
||||
export function allPermissionsGranted(): boolean {
|
||||
const status = getPermissionsStatus();
|
||||
return status.accessibility === 'authorized';
|
||||
return status.accessibility === 'authorized' && status.screenRecording === 'authorized';
|
||||
}
|
||||
|
||||
export function requestAccessibility(): void {
|
||||
|
|
@ -36,6 +38,18 @@ export function requestAccessibility(): void {
|
|||
perms.askForAccessibilityAccess();
|
||||
}
|
||||
|
||||
export function hasScreenRecordingPermission(): boolean {
|
||||
if (!isMac()) return true;
|
||||
const perms = getNodeMacPermissions();
|
||||
return perms.getAuthStatus('screen') === 'authorized';
|
||||
}
|
||||
|
||||
export function requestScreenRecording(): void {
|
||||
if (!isMac()) return;
|
||||
const perms = getNodeMacPermissions();
|
||||
perms.askForScreenCaptureAccess();
|
||||
}
|
||||
|
||||
export function restartApp(): void {
|
||||
app.relaunch();
|
||||
app.exit(0);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
// Permissions
|
||||
getPermissionsStatus: () => ipcRenderer.invoke(IPC_CHANNELS.GET_PERMISSIONS_STATUS),
|
||||
requestAccessibility: () => ipcRenderer.invoke(IPC_CHANNELS.REQUEST_ACCESSIBILITY),
|
||||
requestScreenRecording: () => ipcRenderer.invoke(IPC_CHANNELS.REQUEST_SCREEN_RECORDING),
|
||||
restartApp: () => ipcRenderer.invoke(IPC_CHANNELS.RESTART_APP),
|
||||
// Autocomplete
|
||||
onAutocompleteContext: (callback: (data: { screenshot: string; searchSpaceId?: string }) => void) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue