Type the updater API and the Tauri global. [skip build]
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
MatrixEvent,
|
||||
Room,
|
||||
IPushRules,
|
||||
IPushRule,
|
||||
SyncState,
|
||||
} from 'matrix-js-sdk';
|
||||
import { useAtomValue } from 'jotai';
|
||||
@@ -113,8 +114,8 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
||||
const pushRules = pushRulesEvt?.getContent<IPushRules>() ?? { global: {} };
|
||||
const content = pushRules.global.content ?? [];
|
||||
const keywordPatterns = content
|
||||
.filter((rule: any) => rule.default === false && typeof rule.pattern === 'string')
|
||||
.map((rule: any) => rule.pattern as string);
|
||||
.filter((rule: IPushRule) => rule.default === false && typeof rule.pattern === 'string')
|
||||
.map((rule: IPushRule) => rule.pattern as string);
|
||||
|
||||
// Get notification preferences
|
||||
const global = pushRules?.global;
|
||||
@@ -128,21 +129,21 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
||||
};
|
||||
|
||||
// Check override rules for muted rooms
|
||||
override.forEach((rule: any) => {
|
||||
override.forEach((rule: IPushRule) => {
|
||||
if (isRoomId(rule.rule_id) && getNotificationMode(rule.actions) === NotificationMode.OFF) {
|
||||
preferences.mute.add(rule.rule_id);
|
||||
}
|
||||
});
|
||||
|
||||
// Check room rules for special messages (OFF mode = mentions only)
|
||||
room.forEach((rule: any) => {
|
||||
room.forEach((rule: IPushRule) => {
|
||||
if (getNotificationMode(rule.actions) === NotificationMode.OFF) {
|
||||
preferences.specialMessages.add(rule.rule_id);
|
||||
}
|
||||
});
|
||||
|
||||
// Check room rules for all messages (Notify or NotifyLoud mode)
|
||||
room.forEach((rule: any) => {
|
||||
room.forEach((rule: IPushRule) => {
|
||||
if (getNotificationMode(rule.actions) !== NotificationMode.OFF) {
|
||||
preferences.allMessages.add(rule.rule_id);
|
||||
}
|
||||
@@ -483,7 +484,7 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
||||
|
||||
const content = event.getContent();
|
||||
const isMyReceipt = Object.keys(content).find((eventId) =>
|
||||
(Object.keys(content[eventId]) as any[]).find(
|
||||
Object.keys(content[eventId]).find(
|
||||
(receiptType) => content[eventId][receiptType][myUserId],
|
||||
),
|
||||
);
|
||||
@@ -631,7 +632,7 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
||||
};
|
||||
|
||||
// Only render on desktop (when Tauri is available)
|
||||
if (typeof (window as any).__TAURI__ === 'undefined') {
|
||||
if (typeof window.__TAURI__ === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,7 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Box, Text } from 'folds';
|
||||
import * as css from './UpdateNotification.css';
|
||||
|
||||
interface UpdateInfo {
|
||||
version: string;
|
||||
releaseNotes?: string;
|
||||
releaseDate?: string;
|
||||
mock?: boolean;
|
||||
}
|
||||
|
||||
interface DownloadProgress {
|
||||
percent: number;
|
||||
transferred: number;
|
||||
total: number;
|
||||
mock?: boolean;
|
||||
}
|
||||
import type { DownloadProgress, UpdateInfo } from '../../../ext';
|
||||
|
||||
type UpdaterPhase = 'idle' | 'checking' | 'available' | 'downloading' | 'ready';
|
||||
|
||||
@@ -26,7 +13,7 @@ export function UpdateNotification() {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (!electron?.updater) return undefined;
|
||||
|
||||
const { updater } = electron;
|
||||
@@ -72,7 +59,7 @@ export function UpdateNotification() {
|
||||
const handleCheck = useCallback(async () => {
|
||||
setPhase('checking');
|
||||
try {
|
||||
const result = await (window as any).electron.updater.checkForUpdates();
|
||||
const result = await window.electron?.updater?.checkForUpdates();
|
||||
if (!result?.success) {
|
||||
setPhase('idle');
|
||||
}
|
||||
@@ -89,7 +76,7 @@ export function UpdateNotification() {
|
||||
setPhase('downloading');
|
||||
setDownloadProgress(0);
|
||||
try {
|
||||
await (window as any).electron.updater.downloadUpdate();
|
||||
await window.electron?.updater?.downloadUpdate();
|
||||
} catch {
|
||||
setPhase('available');
|
||||
}
|
||||
@@ -97,7 +84,7 @@ export function UpdateNotification() {
|
||||
|
||||
const handleInstall = useCallback(async () => {
|
||||
try {
|
||||
await (window as any).electron.updater.installUpdate();
|
||||
await window.electron?.updater?.installUpdate();
|
||||
if (isMock) {
|
||||
setPhase('idle');
|
||||
setUpdateInfo(null);
|
||||
@@ -114,7 +101,7 @@ export function UpdateNotification() {
|
||||
setDownloadProgress(0);
|
||||
}, []);
|
||||
|
||||
if (typeof window === 'undefined' || !(window as any).electron?.updater) {
|
||||
if (typeof window === 'undefined' || !window.electron?.updater) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user