mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-29 02:46:25 +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
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue