mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 17:56:25 +02:00
feat: add macOS permission infrastructure for autocomplete
This commit is contained in:
parent
bcc227a4dd
commit
ec2b7851b6
5 changed files with 91 additions and 0 deletions
50
surfsense_desktop/src/modules/permissions.ts
Normal file
50
surfsense_desktop/src/modules/permissions.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { app } from 'electron';
|
||||
|
||||
type PermissionStatus = 'authorized' | 'denied' | 'not determined' | 'restricted' | 'limited';
|
||||
|
||||
export interface PermissionsStatus {
|
||||
accessibility: PermissionStatus;
|
||||
inputMonitoring: PermissionStatus;
|
||||
}
|
||||
|
||||
function isMac(): boolean {
|
||||
return process.platform === 'darwin';
|
||||
}
|
||||
|
||||
function getNodeMacPermissions() {
|
||||
return require('node-mac-permissions');
|
||||
}
|
||||
|
||||
export function getPermissionsStatus(): PermissionsStatus {
|
||||
if (!isMac()) {
|
||||
return { accessibility: 'authorized', inputMonitoring: 'authorized' };
|
||||
}
|
||||
|
||||
const perms = getNodeMacPermissions();
|
||||
return {
|
||||
accessibility: perms.getAuthStatus('accessibility'),
|
||||
inputMonitoring: perms.getAuthStatus('input-monitoring'),
|
||||
};
|
||||
}
|
||||
|
||||
export function allPermissionsGranted(): boolean {
|
||||
const status = getPermissionsStatus();
|
||||
return status.accessibility === 'authorized' && status.inputMonitoring === 'authorized';
|
||||
}
|
||||
|
||||
export function requestAccessibility(): void {
|
||||
if (!isMac()) return;
|
||||
const perms = getNodeMacPermissions();
|
||||
perms.askForAccessibilityAccess();
|
||||
}
|
||||
|
||||
export async function requestInputMonitoring(): Promise<string> {
|
||||
if (!isMac()) return 'authorized';
|
||||
const perms = getNodeMacPermissions();
|
||||
return perms.askForInputMonitoringAccess('listen');
|
||||
}
|
||||
|
||||
export function restartApp(): void {
|
||||
app.relaunch();
|
||||
app.exit(0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue