Type the updater API and the Tauri global. [skip build]
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
Room,
|
Room,
|
||||||
IPushRules,
|
IPushRules,
|
||||||
|
IPushRule,
|
||||||
SyncState,
|
SyncState,
|
||||||
} from 'matrix-js-sdk';
|
} from 'matrix-js-sdk';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
@@ -113,8 +114,8 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
|||||||
const pushRules = pushRulesEvt?.getContent<IPushRules>() ?? { global: {} };
|
const pushRules = pushRulesEvt?.getContent<IPushRules>() ?? { global: {} };
|
||||||
const content = pushRules.global.content ?? [];
|
const content = pushRules.global.content ?? [];
|
||||||
const keywordPatterns = content
|
const keywordPatterns = content
|
||||||
.filter((rule: any) => rule.default === false && typeof rule.pattern === 'string')
|
.filter((rule: IPushRule) => rule.default === false && typeof rule.pattern === 'string')
|
||||||
.map((rule: any) => rule.pattern as string);
|
.map((rule: IPushRule) => rule.pattern as string);
|
||||||
|
|
||||||
// Get notification preferences
|
// Get notification preferences
|
||||||
const global = pushRules?.global;
|
const global = pushRules?.global;
|
||||||
@@ -128,21 +129,21 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check override rules for muted rooms
|
// Check override rules for muted rooms
|
||||||
override.forEach((rule: any) => {
|
override.forEach((rule: IPushRule) => {
|
||||||
if (isRoomId(rule.rule_id) && getNotificationMode(rule.actions) === NotificationMode.OFF) {
|
if (isRoomId(rule.rule_id) && getNotificationMode(rule.actions) === NotificationMode.OFF) {
|
||||||
preferences.mute.add(rule.rule_id);
|
preferences.mute.add(rule.rule_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check room rules for special messages (OFF mode = mentions only)
|
// Check room rules for special messages (OFF mode = mentions only)
|
||||||
room.forEach((rule: any) => {
|
room.forEach((rule: IPushRule) => {
|
||||||
if (getNotificationMode(rule.actions) === NotificationMode.OFF) {
|
if (getNotificationMode(rule.actions) === NotificationMode.OFF) {
|
||||||
preferences.specialMessages.add(rule.rule_id);
|
preferences.specialMessages.add(rule.rule_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check room rules for all messages (Notify or NotifyLoud mode)
|
// Check room rules for all messages (Notify or NotifyLoud mode)
|
||||||
room.forEach((rule: any) => {
|
room.forEach((rule: IPushRule) => {
|
||||||
if (getNotificationMode(rule.actions) !== NotificationMode.OFF) {
|
if (getNotificationMode(rule.actions) !== NotificationMode.OFF) {
|
||||||
preferences.allMessages.add(rule.rule_id);
|
preferences.allMessages.add(rule.rule_id);
|
||||||
}
|
}
|
||||||
@@ -483,7 +484,7 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
|||||||
|
|
||||||
const content = event.getContent();
|
const content = event.getContent();
|
||||||
const isMyReceipt = Object.keys(content).find((eventId) =>
|
const isMyReceipt = Object.keys(content).find((eventId) =>
|
||||||
(Object.keys(content[eventId]) as any[]).find(
|
Object.keys(content[eventId]).find(
|
||||||
(receiptType) => content[eventId][receiptType][myUserId],
|
(receiptType) => content[eventId][receiptType][myUserId],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -631,7 +632,7 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only render on desktop (when Tauri is available)
|
// Only render on desktop (when Tauri is available)
|
||||||
if (typeof (window as any).__TAURI__ === 'undefined') {
|
if (typeof window.__TAURI__ === 'undefined') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,7 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { Box, Text } from 'folds';
|
import { Box, Text } from 'folds';
|
||||||
import * as css from './UpdateNotification.css';
|
import * as css from './UpdateNotification.css';
|
||||||
|
import type { DownloadProgress, UpdateInfo } from '../../../ext';
|
||||||
interface UpdateInfo {
|
|
||||||
version: string;
|
|
||||||
releaseNotes?: string;
|
|
||||||
releaseDate?: string;
|
|
||||||
mock?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DownloadProgress {
|
|
||||||
percent: number;
|
|
||||||
transferred: number;
|
|
||||||
total: number;
|
|
||||||
mock?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdaterPhase = 'idle' | 'checking' | 'available' | 'downloading' | 'ready';
|
type UpdaterPhase = 'idle' | 'checking' | 'available' | 'downloading' | 'ready';
|
||||||
|
|
||||||
@@ -26,7 +13,7 @@ export function UpdateNotification() {
|
|||||||
const [hovered, setHovered] = useState(false);
|
const [hovered, setHovered] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { electron } = window as any;
|
const { electron } = window;
|
||||||
if (!electron?.updater) return undefined;
|
if (!electron?.updater) return undefined;
|
||||||
|
|
||||||
const { updater } = electron;
|
const { updater } = electron;
|
||||||
@@ -72,7 +59,7 @@ export function UpdateNotification() {
|
|||||||
const handleCheck = useCallback(async () => {
|
const handleCheck = useCallback(async () => {
|
||||||
setPhase('checking');
|
setPhase('checking');
|
||||||
try {
|
try {
|
||||||
const result = await (window as any).electron.updater.checkForUpdates();
|
const result = await window.electron?.updater?.checkForUpdates();
|
||||||
if (!result?.success) {
|
if (!result?.success) {
|
||||||
setPhase('idle');
|
setPhase('idle');
|
||||||
}
|
}
|
||||||
@@ -89,7 +76,7 @@ export function UpdateNotification() {
|
|||||||
setPhase('downloading');
|
setPhase('downloading');
|
||||||
setDownloadProgress(0);
|
setDownloadProgress(0);
|
||||||
try {
|
try {
|
||||||
await (window as any).electron.updater.downloadUpdate();
|
await window.electron?.updater?.downloadUpdate();
|
||||||
} catch {
|
} catch {
|
||||||
setPhase('available');
|
setPhase('available');
|
||||||
}
|
}
|
||||||
@@ -97,7 +84,7 @@ export function UpdateNotification() {
|
|||||||
|
|
||||||
const handleInstall = useCallback(async () => {
|
const handleInstall = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
await (window as any).electron.updater.installUpdate();
|
await window.electron?.updater?.installUpdate();
|
||||||
if (isMock) {
|
if (isMock) {
|
||||||
setPhase('idle');
|
setPhase('idle');
|
||||||
setUpdateInfo(null);
|
setUpdateInfo(null);
|
||||||
@@ -114,7 +101,7 @@ export function UpdateNotification() {
|
|||||||
setDownloadProgress(0);
|
setDownloadProgress(0);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (typeof window === 'undefined' || !(window as any).electron?.updater) {
|
if (typeof window === 'undefined' || !window.electron?.updater) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
|||||||
);
|
);
|
||||||
const powerLevelTags = powerLevelTagsEvent?.getContent();
|
const powerLevelTags = powerLevelTagsEvent?.getContent();
|
||||||
|
|
||||||
const info: any = {
|
const info = {
|
||||||
roomId: room.roomId,
|
roomId: room.roomId,
|
||||||
name: room.name,
|
name: room.name,
|
||||||
canonicalAlias: room.canonicalAlias,
|
canonicalAlias: room.canonicalAlias,
|
||||||
@@ -103,8 +103,8 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
|||||||
timelineSetSize: room.getTimelineSets().length,
|
timelineSetSize: room.getTimelineSets().length,
|
||||||
},
|
},
|
||||||
encryption: room.hasEncryptionStateEvent(),
|
encryption: room.hasEncryptionStateEvent(),
|
||||||
state: {} as any,
|
state: {} as Record<string, Record<string, unknown>>,
|
||||||
accountData: {} as any,
|
accountData: {} as Record<string, unknown>,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add all state events
|
// Add all state events
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ export const MessageAllReactionItem = as<
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Overlay
|
<Overlay
|
||||||
onContextMenu={(evt: any) => {
|
onContextMenu={(evt) => {
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
}}
|
}}
|
||||||
open={open}
|
open={open}
|
||||||
@@ -974,7 +974,7 @@ export const Message = as<'div', MessageProps>(
|
|||||||
|
|
||||||
const handleContextMenu: MouseEventHandler<HTMLDivElement> = (evt) => {
|
const handleContextMenu: MouseEventHandler<HTMLDivElement> = (evt) => {
|
||||||
if (evt.altKey || !window.getSelection()?.isCollapsed || edit) return;
|
if (evt.altKey || !window.getSelection()?.isCollapsed || edit) return;
|
||||||
const tag = (evt.target as any).tagName;
|
const tag = (evt.target as HTMLElement).tagName;
|
||||||
if (typeof tag === 'string' && (tag.toLowerCase() === 'a' || tag.toLowerCase() === 'img'))
|
if (typeof tag === 'string' && (tag.toLowerCase() === 'a' || tag.toLowerCase() === 'img'))
|
||||||
return;
|
return;
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@@ -1187,7 +1187,7 @@ export const Message = as<'div', MessageProps>(
|
|||||||
after={<Icon size="100" src={Icons.ReplyArrow} />}
|
after={<Icon size="100" src={Icons.ReplyArrow} />}
|
||||||
radii="300"
|
radii="300"
|
||||||
data-event-id={mEvent.getId()}
|
data-event-id={mEvent.getId()}
|
||||||
onClick={(evt: any) => {
|
onClick={(evt) => {
|
||||||
onReplyClick(evt);
|
onReplyClick(evt);
|
||||||
closeMenu();
|
closeMenu();
|
||||||
}}
|
}}
|
||||||
@@ -1207,7 +1207,7 @@ export const Message = as<'div', MessageProps>(
|
|||||||
after={<Icon src={Icons.ThreadPlus} size="100" />}
|
after={<Icon src={Icons.ThreadPlus} size="100" />}
|
||||||
radii="300"
|
radii="300"
|
||||||
data-event-id={mEvent.getId()}
|
data-event-id={mEvent.getId()}
|
||||||
onClick={(evt: any) => {
|
onClick={(evt) => {
|
||||||
onReplyClick(evt, true);
|
onReplyClick(evt, true);
|
||||||
closeMenu();
|
closeMenu();
|
||||||
}}
|
}}
|
||||||
@@ -1359,7 +1359,7 @@ export const Event = as<'div', EventProps>(
|
|||||||
|
|
||||||
const handleContextMenu: MouseEventHandler<HTMLDivElement> = (evt) => {
|
const handleContextMenu: MouseEventHandler<HTMLDivElement> = (evt) => {
|
||||||
if (evt.altKey || !window.getSelection()?.isCollapsed) return;
|
if (evt.altKey || !window.getSelection()?.isCollapsed) return;
|
||||||
const tag = (evt.target as any).tagName;
|
const tag = (evt.target as HTMLElement).tagName;
|
||||||
if (typeof tag === 'string' && (tag.toLowerCase() === 'a' || tag.toLowerCase() === 'img'))
|
if (typeof tag === 'string' && (tag.toLowerCase() === 'a' || tag.toLowerCase() === 'img'))
|
||||||
return;
|
return;
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ interface PluginLoaderProps {
|
|||||||
* Reads and evaluates a plugin's JS module from the Electron filesystem.
|
* Reads and evaluates a plugin's JS module from the Electron filesystem.
|
||||||
* Supports both CommonJS and ESM-style exports.
|
* Supports both CommonJS and ESM-style exports.
|
||||||
*/
|
*/
|
||||||
async function loadPluginModule(pluginId: string): Promise<any> {
|
async function loadPluginModule(pluginId: string): Promise<Record<string, unknown>> {
|
||||||
if (!window.electron?.plugins) {
|
if (!window.electron?.plugins) {
|
||||||
throw new Error('Plugins are only supported in the desktop app');
|
throw new Error('Plugins are only supported in the desktop app');
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ async function loadPluginModule(pluginId: string): Promise<any> {
|
|||||||
throw new Error(response.error ?? 'Failed to read plugin code');
|
throw new Error(response.error ?? 'Failed to read plugin code');
|
||||||
}
|
}
|
||||||
|
|
||||||
const pluginExports: any = {};
|
const pluginExports: Record<string, unknown> = {};
|
||||||
const mod = { exports: pluginExports };
|
const mod = { exports: pluginExports };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -134,7 +134,7 @@ export function PluginLoader({ matrixClient, children }: PluginLoaderProps) {
|
|||||||
const context = createPluginContext(
|
const context = createPluginContext(
|
||||||
{
|
{
|
||||||
pluginId: installedPlugin.id,
|
pluginId: installedPlugin.id,
|
||||||
eventClient: matrixClient as any,
|
eventClient: matrixClient,
|
||||||
onNotify: async (opts) => {
|
onNotify: async (opts) => {
|
||||||
await sendNotification({
|
await sendNotification({
|
||||||
title: opts.title,
|
title: opts.title,
|
||||||
@@ -146,13 +146,13 @@ export function PluginLoader({ matrixClient, children }: PluginLoaderProps) {
|
|||||||
pluginRegistry,
|
pluginRegistry,
|
||||||
);
|
);
|
||||||
|
|
||||||
const compatContext = Object.assign(context as Record<string, unknown>, {
|
const compatContext = Object.assign(context, {
|
||||||
matrixClient,
|
matrixClient,
|
||||||
matrix: {
|
matrix: {
|
||||||
on: (eventType: string, handler: (...args: unknown[]) => void) =>
|
on: (eventType: string, handler: (...args: unknown[]) => void) =>
|
||||||
matrixClient.on(eventType as any, handler as any),
|
matrixClient.on(eventType as any, handler),
|
||||||
off: (eventType: string, handler: (...args: unknown[]) => void) =>
|
off: (eventType: string, handler: (...args: unknown[]) => void) =>
|
||||||
matrixClient.off(eventType as any, handler as any),
|
matrixClient.off(eventType as any, handler),
|
||||||
},
|
},
|
||||||
React,
|
React,
|
||||||
lucide,
|
lucide,
|
||||||
@@ -163,7 +163,7 @@ export function PluginLoader({ matrixClient, children }: PluginLoaderProps) {
|
|||||||
console.log('[PluginLoader] About to register plugin and call onLoad...');
|
console.log('[PluginLoader] About to register plugin and call onLoad...');
|
||||||
|
|
||||||
pluginRegistry.registerPlugin(installedPlugin.id, plugin, context);
|
pluginRegistry.registerPlugin(installedPlugin.id, plugin, context);
|
||||||
await plugin.onLoad(compatContext as any);
|
await plugin.onLoad(compatContext);
|
||||||
console.log(`[PluginLoader] Successfully loaded plugin: ${installedPlugin.id}`);
|
console.log(`[PluginLoader] Successfully loaded plugin: ${installedPlugin.id}`);
|
||||||
dispatchPluginButtonsChanged();
|
dispatchPluginButtonsChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,8 +185,8 @@ export const renderMatrixMention = (
|
|||||||
|
|
||||||
export const factoryRenderLinkifyWithMention = (
|
export const factoryRenderLinkifyWithMention = (
|
||||||
mentionRender: (href: string) => React.JSX.Element | undefined,
|
mentionRender: (href: string) => React.JSX.Element | undefined,
|
||||||
): OptFn<(ir: IntermediateRepresentation) => any> => {
|
): OptFn<(ir: IntermediateRepresentation) => React.JSX.Element | undefined> => {
|
||||||
const render: OptFn<(ir: IntermediateRepresentation) => any> = ({
|
const render: OptFn<(ir: IntermediateRepresentation) => React.JSX.Element | undefined> = ({
|
||||||
tagName,
|
tagName,
|
||||||
attributes,
|
attributes,
|
||||||
content,
|
content,
|
||||||
@@ -502,7 +502,7 @@ export function InlineCode({
|
|||||||
}: {
|
}: {
|
||||||
children: ChildNode[];
|
children: ChildNode[];
|
||||||
opts: HTMLReactParserOptions;
|
opts: HTMLReactParserOptions;
|
||||||
props: any;
|
props: ReturnType<typeof attributesToProps>;
|
||||||
}) {
|
}) {
|
||||||
const [copied, setCopied] = useTimeoutToggle();
|
const [copied, setCopied] = useTimeoutToggle();
|
||||||
|
|
||||||
|
|||||||
Vendored
+31
-3
@@ -25,6 +25,20 @@ interface PluginAPI {
|
|||||||
) => Promise<{ success: boolean; data?: string; error?: string }>;
|
) => Promise<{ success: boolean; data?: string; error?: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpdateInfo {
|
||||||
|
version: string;
|
||||||
|
releaseNotes?: string;
|
||||||
|
releaseDate?: string;
|
||||||
|
mock?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DownloadProgress {
|
||||||
|
percent: number;
|
||||||
|
transferred: number;
|
||||||
|
total: number;
|
||||||
|
mock?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface ElectronAPI {
|
interface ElectronAPI {
|
||||||
platform?: string;
|
platform?: string;
|
||||||
arch?: string;
|
arch?: string;
|
||||||
@@ -91,9 +105,19 @@ interface ElectronAPI {
|
|||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
updater?: {
|
updater?: {
|
||||||
onUpdateDownloaded: (
|
checkForUpdates: () => Promise<{
|
||||||
callback: (info: { version: string; releaseNotes?: unknown }) => void,
|
success: boolean;
|
||||||
) => void;
|
data?: { updateInfo?: UpdateInfo };
|
||||||
|
error?: string;
|
||||||
|
}>;
|
||||||
|
downloadUpdate: () => Promise<{ success: boolean; error?: string }>;
|
||||||
|
installUpdate: () => Promise<{ success: boolean; error?: string }>;
|
||||||
|
downloadAndInstallUpdate: () => Promise<{ success: boolean; error?: string }>;
|
||||||
|
isMock: () => Promise<{ success: boolean; data?: { mock: boolean } }>;
|
||||||
|
onUpdateAvailable: (callback: (info: UpdateInfo) => void) => void;
|
||||||
|
onUpdateDownloadProgress: (callback: (progress: DownloadProgress) => void) => void;
|
||||||
|
onUpdateDownloaded: (callback: (info: UpdateInfo) => void) => void;
|
||||||
|
onUpdateNotAvailable: (callback: (info: UpdateInfo) => void) => void;
|
||||||
};
|
};
|
||||||
discordCollectibles?: {
|
discordCollectibles?: {
|
||||||
fetchCatalog: (force?: boolean) => Promise<{
|
fetchCatalog: (force?: boolean) => Promise<{
|
||||||
@@ -120,6 +144,10 @@ interface ElectronAPI {
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
electron?: ElectronAPI;
|
electron?: ElectronAPI;
|
||||||
|
__TAURI__?: {
|
||||||
|
invoke: (command: string, args?: unknown) => Promise<unknown>;
|
||||||
|
listen: (event: string, handler: (...args: unknown[]) => void) => () => void;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user