Compare commits
1
Commits
8d6aaa619f
...
b36335cde9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b36335cde9 |
@@ -1,10 +1,11 @@
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import { Box, Button, IconButton, Scroll, Spinner, Text, color } from 'folds';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { EventType } from 'matrix-js-sdk';
|
||||
import { Icon, Icons } from '../../../components/icons';
|
||||
import { Page, PageContent, PageHeader } from '../../../components/page';
|
||||
import { useRoom } from '../../../hooks/useRoom';
|
||||
import { usePowerLevels } from '../../../hooks/usePowerLevels';
|
||||
import { IPowerLevels, usePowerLevels } from '../../../hooks/usePowerLevels';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { StateEvent } from '../../../../types/matrix/room';
|
||||
import { usePermissionGroups } from './usePermissionItems';
|
||||
@@ -148,7 +149,7 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
}
|
||||
|
||||
// Cap all power level values at my power level
|
||||
const capPowerLevel = (value: any) => {
|
||||
const capPowerLevel = (value: number | undefined): number | undefined => {
|
||||
if (typeof value === 'number') {
|
||||
return Math.min(value, myPowerInChild);
|
||||
}
|
||||
@@ -156,7 +157,7 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
};
|
||||
|
||||
// Create the merged power levels with capped values
|
||||
const mergedPowerLevels: any = {
|
||||
const mergedPowerLevels: IPowerLevels = {
|
||||
...powerLevels,
|
||||
users: mergedUsers,
|
||||
ban: capPowerLevel(powerLevels.ban),
|
||||
@@ -172,7 +173,8 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
if (powerLevels.events) {
|
||||
mergedPowerLevels.events = {};
|
||||
Object.entries(powerLevels.events).forEach(([eventType, power]) => {
|
||||
mergedPowerLevels.events[eventType] = capPowerLevel(power);
|
||||
const capped = capPowerLevel(power);
|
||||
if (capped !== undefined) mergedPowerLevels.events![eventType] = capped;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -180,11 +182,12 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
if (powerLevels.notifications) {
|
||||
mergedPowerLevels.notifications = {};
|
||||
Object.entries(powerLevels.notifications).forEach(([key, power]) => {
|
||||
mergedPowerLevels.notifications[key] = capPowerLevel(power);
|
||||
const capped = capPowerLevel(power);
|
||||
if (capped !== undefined) mergedPowerLevels.notifications![key] = capped;
|
||||
});
|
||||
}
|
||||
|
||||
await mx.sendStateEvent(childId, StateEvent.RoomPowerLevels as any, mergedPowerLevels);
|
||||
await mx.sendStateEvent(childId, EventType.RoomPowerLevels, mergedPowerLevels);
|
||||
|
||||
// Also copy power level tags if they exist
|
||||
if (powerLevelTags) {
|
||||
@@ -257,7 +260,7 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
}
|
||||
|
||||
// Cap all power level values at my power level
|
||||
const capPowerLevel = (value: any) => {
|
||||
const capPowerLevel = (value: number | undefined): number | undefined => {
|
||||
if (typeof value === 'number') {
|
||||
return Math.min(value, myPowerInChild);
|
||||
}
|
||||
@@ -265,7 +268,7 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
};
|
||||
|
||||
// Create the merged power levels with capped values
|
||||
const mergedPowerLevels: any = {
|
||||
const mergedPowerLevels: IPowerLevels = {
|
||||
...powerLevels,
|
||||
users: mergedUsers,
|
||||
ban: capPowerLevel(powerLevels.ban),
|
||||
@@ -281,7 +284,8 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
if (powerLevels.events) {
|
||||
mergedPowerLevels.events = {};
|
||||
Object.entries(powerLevels.events).forEach(([eventType, power]) => {
|
||||
mergedPowerLevels.events[eventType] = capPowerLevel(power);
|
||||
const capped = capPowerLevel(power);
|
||||
if (capped !== undefined) mergedPowerLevels.events![eventType] = capped;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -289,11 +293,12 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
if (powerLevels.notifications) {
|
||||
mergedPowerLevels.notifications = {};
|
||||
Object.entries(powerLevels.notifications).forEach(([key, power]) => {
|
||||
mergedPowerLevels.notifications[key] = capPowerLevel(power);
|
||||
const capped = capPowerLevel(power);
|
||||
if (capped !== undefined) mergedPowerLevels.notifications![key] = capped;
|
||||
});
|
||||
}
|
||||
|
||||
await mx.sendStateEvent(childId, StateEvent.RoomPowerLevels as any, mergedPowerLevels);
|
||||
await mx.sendStateEvent(childId, EventType.RoomPowerLevels, mergedPowerLevels);
|
||||
|
||||
completed += 1;
|
||||
|
||||
|
||||
@@ -43,11 +43,22 @@ const DEFAULT_POWER_LEVELS: Required<IPowerLevels> = {
|
||||
|
||||
const fillMissingPowers = (powerLevels: IPowerLevels): IPowerLevels =>
|
||||
produce(powerLevels, (draftPl: IPowerLevels) => {
|
||||
const keys = Object.keys(DEFAULT_POWER_LEVELS) as unknown as (keyof IPowerLevels)[];
|
||||
keys.forEach((key) => {
|
||||
if (draftPl[key] === undefined) {
|
||||
draftPl[key] = DEFAULT_POWER_LEVELS[key] as any;
|
||||
}
|
||||
const numberKeys = [
|
||||
'users_default',
|
||||
'state_default',
|
||||
'events_default',
|
||||
'historical',
|
||||
'invite',
|
||||
'redact',
|
||||
'kick',
|
||||
'ban',
|
||||
] as const;
|
||||
const recordKeys = ['events', 'users', 'notifications'] as const;
|
||||
numberKeys.forEach((key) => {
|
||||
if (draftPl[key] === undefined) draftPl[key] = DEFAULT_POWER_LEVELS[key];
|
||||
});
|
||||
recordKeys.forEach((key) => {
|
||||
if (draftPl[key] === undefined) draftPl[key] = DEFAULT_POWER_LEVELS[key];
|
||||
});
|
||||
if (draftPl.notifications && typeof draftPl.notifications.room !== 'number') {
|
||||
draftPl.notifications.room = DEFAULT_POWER_LEVELS.notifications.room;
|
||||
|
||||
+10
-12
@@ -8,7 +8,7 @@ export const isElectron = (): boolean => typeof window !== 'undefined' && 'elect
|
||||
*/
|
||||
export const isCapacitorNative = (): boolean => {
|
||||
if (typeof window === 'undefined') return false;
|
||||
const cap = (window as any).Capacitor;
|
||||
const cap = window.Capacitor;
|
||||
return Boolean(
|
||||
cap?.isNativePlatform?.() ||
|
||||
cap?.getPlatform?.() === 'android' ||
|
||||
@@ -26,7 +26,7 @@ export const openExternalUrl = async (url: string): Promise<void> => {
|
||||
// Use Electron's shell.openExternal if in Electron
|
||||
if (isElectron()) {
|
||||
try {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.shell?.openExternal) {
|
||||
await electron.shell.openExternal(url);
|
||||
console.log('[openExternalUrl] Electron shell.openExternal succeeded');
|
||||
@@ -64,7 +64,7 @@ export const getYouTubeStream = async (url: string): Promise<YouTubeStreamInfo>
|
||||
}
|
||||
|
||||
// Check for Electron
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.youtube?.getStream) {
|
||||
const result = await electron.youtube.getStream(url);
|
||||
// Electron returns { success: true, data: { video_url, title } } or { success: false, error }
|
||||
@@ -75,7 +75,7 @@ export const getYouTubeStream = async (url: string): Promise<YouTubeStreamInfo>
|
||||
}
|
||||
|
||||
// Check for Tauri
|
||||
if ((window as any).__TAURI__) {
|
||||
if (window.__TAURI__) {
|
||||
const { invoke } = await import('@tauri-apps/api/core');
|
||||
return invoke<YouTubeStreamInfo>('get_youtube_stream', { url });
|
||||
}
|
||||
@@ -93,13 +93,13 @@ export const isYouTubeStreamingAvailable = (): boolean => {
|
||||
}
|
||||
|
||||
// Check for Electron
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.youtube?.getStream) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for Tauri
|
||||
return !!(window as any).__TAURI__;
|
||||
return !!window.__TAURI__;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ export const focusWindow = async (): Promise<void> => {
|
||||
// Use Electron's window focus if in Electron
|
||||
if (isElectron()) {
|
||||
try {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.window?.focus) {
|
||||
await electron.window.focus();
|
||||
}
|
||||
@@ -138,18 +138,16 @@ export const setupNotificationTapListener = async (
|
||||
// Use Electron's native notification handler if in Electron
|
||||
if (isElectron()) {
|
||||
try {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.notification?.onNavigate) {
|
||||
electron.notification.onNavigate((data: { path?: string }) => {
|
||||
if (data.path && typeof data.path === 'string' && notificationTapCallback) {
|
||||
notificationTapCallback(data.path);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Failed to set up Electron notification listener:', err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -273,7 +271,7 @@ export const sendNotification = async (options: {
|
||||
// Use Electron's native notification API if in Electron
|
||||
if (isElectron()) {
|
||||
try {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.notification?.show) {
|
||||
await electron.notification.show({
|
||||
title,
|
||||
@@ -308,7 +306,7 @@ export const readClipboardImage = async (): Promise<File | null> => {
|
||||
// Use Electron's clipboard API if in Electron
|
||||
if (isElectron()) {
|
||||
try {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (electron?.clipboard?.readImage) {
|
||||
const result = await electron.clipboard.readImage();
|
||||
// IPC may return a data URL string or { success, data } depending on path.
|
||||
|
||||
Vendored
+23
@@ -1,6 +1,7 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
import type { DebugPacket } from './app/state/debugPackets';
|
||||
import type { YouTubeStreamInfo } from './app/utils/tauri';
|
||||
|
||||
declare module '*.svg' {
|
||||
const content: string;
|
||||
@@ -51,6 +52,24 @@ interface ElectronAPI {
|
||||
};
|
||||
clipboard?: {
|
||||
writeText: (text: string) => void;
|
||||
readImage?: () => Promise<string | { data?: string }>;
|
||||
};
|
||||
shell?: {
|
||||
openExternal?: (url: string) => Promise<unknown>;
|
||||
};
|
||||
youtube?: {
|
||||
getStream?: (
|
||||
url: string,
|
||||
) => Promise<{ success: boolean; data: YouTubeStreamInfo; error?: string }>;
|
||||
};
|
||||
notification?: {
|
||||
show?: (options: {
|
||||
title: string;
|
||||
body: string;
|
||||
icon?: string;
|
||||
path?: string;
|
||||
}) => Promise<unknown>;
|
||||
onNavigate?: (callback: (data: { path?: string }) => void) => void;
|
||||
};
|
||||
media?: {
|
||||
saveFile: (payload: { filename: string; mimeType?: string; data: Uint8Array }) => Promise<{
|
||||
@@ -148,6 +167,10 @@ declare global {
|
||||
invoke: (command: string, args?: unknown) => Promise<unknown>;
|
||||
listen: (event: string, handler: (...args: unknown[]) => void) => () => void;
|
||||
};
|
||||
Capacitor?: {
|
||||
isNativePlatform?: () => boolean;
|
||||
getPlatform?: () => string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user