From d6fe94ff48ba533feba8ef79065b4abe6c08272f Mon Sep 17 00:00:00 2001 From: litruv Date: Sun, 1 Nov 2026 05:31:13 +1100 Subject: [PATCH] Drop the dead Tauri branches and the plugin packages. [skip build] --- package-lock.json | 70 ---------- package.json | 7 - src/app/utils/registerDesktopMediaSaver.ts | 70 +--------- src/app/utils/tauri.ts | 144 +-------------------- src/app/utils/tauriShell.ts | 9 -- src/app/utils/telegramStickerImport.ts | 3 +- src/index.tsx | 58 +-------- 7 files changed, 7 insertions(+), 354 deletions(-) delete mode 100644 src/app/utils/tauriShell.ts diff --git a/package-lock.json b/package-lock.json index 6f80fbd9..65630ae7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,13 +20,6 @@ "@tanstack/react-query-devtools": "5.101.2", "@tanstack/react-virtual": "3.14.5", "@tauri-apps/api": "2.11.1", - "@tauri-apps/plugin-dialog": "2.7.1", - "@tauri-apps/plugin-fs": "2.5.1", - "@tauri-apps/plugin-http": "2.5.9", - "@tauri-apps/plugin-notification": "2.3.3", - "@tauri-apps/plugin-opener": "2", - "@tauri-apps/plugin-process": "2.3.1", - "@tauri-apps/plugin-updater": "2.10.1", "@types/pako": "2.0.4", "@vanilla-extract/css": "1.21.1", "@vanilla-extract/recipes": "0.5.7", @@ -4080,69 +4073,6 @@ "url": "https://opencollective.com/tauri" } }, - "node_modules/@tauri-apps/plugin-dialog": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.7.1.tgz", - "integrity": "sha512-OK1UBXYt+ojcmxMktzzuyonYIFta8CmAASpX+CA+DTGK24KlHjhYI6x2iOJ/TjZF4N7/ACK1oFmEOjIY9IhzOQ==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.11.0" - } - }, - "node_modules/@tauri-apps/plugin-fs": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-fs/-/plugin-fs-2.5.1.tgz", - "integrity": "sha512-9Lz+Jopp6QyeEWhlpkMx4R/+P9HgR+AVAI4vOZhlT8Xaymtz8iVI/Ov984/XTqgJz/5gz5NretqPB/XEMS3NhQ==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.11.0" - } - }, - "node_modules/@tauri-apps/plugin-http": { - "version": "2.5.9", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.5.9.tgz", - "integrity": "sha512-lCiY0+vs4HvIUSvZrBs8TC3TiCB0MOPRmiUjTq4prW7SlcJE2jdLeT6KBsJrT9Tlplufl7W1pY6SFAO3gCWxDA==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.11.0" - } - }, - "node_modules/@tauri-apps/plugin-notification": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-notification/-/plugin-notification-2.3.3.tgz", - "integrity": "sha512-Zw+ZH18RJb41G4NrfHgIuofJiymusqN+q8fGUIIV7vyCH+5sSn5coqRv/MWB9qETsUs97vmU045q7OyseCV3Qg==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.8.0" - } - }, - "node_modules/@tauri-apps/plugin-opener": { - "version": "2.5.3", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.3.tgz", - "integrity": "sha512-CCcUltXMOfUEArbf3db3kCE7Ggy1ExBEBl51Ko2ODJ6GDYHRp1nSNlQm5uNCFY5k7/ufaK5Ib3Du/Zir19IYQQ==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.8.0" - } - }, - "node_modules/@tauri-apps/plugin-process": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-process/-/plugin-process-2.3.1.tgz", - "integrity": "sha512-nCa4fGVaDL/B9ai03VyPOjfAHRHSBz5v6F/ObsB73r/dA3MHHhZtldaDMIc0V/pnUw9ehzr2iEG+XkSEyC0JJA==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.8.0" - } - }, - "node_modules/@tauri-apps/plugin-updater": { - "version": "2.10.1", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-updater/-/plugin-updater-2.10.1.tgz", - "integrity": "sha512-NFYMg+tWOZPJdzE/PpFj2qfqwAWwNS3kXrb1tm1gnBJ9mYzZ4WDRrwy8udzWoAnfGCHLuePNLY1WVCNHnh3eRA==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.10.1" - } - }, "node_modules/@trickfilm400/rollup-plugin-off-main-thread": { "version": "3.0.0-pre1", "resolved": "https://registry.npmjs.org/@trickfilm400/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-3.0.0-pre1.tgz", diff --git a/package.json b/package.json index 65facaf2..4eb5c83c 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,6 @@ "@tanstack/react-query-devtools": "5.101.2", "@tanstack/react-virtual": "3.14.5", "@tauri-apps/api": "2.11.1", - "@tauri-apps/plugin-dialog": "2.7.1", - "@tauri-apps/plugin-fs": "2.5.1", - "@tauri-apps/plugin-http": "2.5.9", - "@tauri-apps/plugin-notification": "2.3.3", - "@tauri-apps/plugin-opener": "2", - "@tauri-apps/plugin-process": "2.3.1", - "@tauri-apps/plugin-updater": "2.10.1", "@types/pako": "2.0.4", "@vanilla-extract/css": "1.21.1", "@vanilla-extract/recipes": "0.5.7", diff --git a/src/app/utils/registerDesktopMediaSaver.ts b/src/app/utils/registerDesktopMediaSaver.ts index 7df9d4e0..93cb96fc 100644 --- a/src/app/utils/registerDesktopMediaSaver.ts +++ b/src/app/utils/registerDesktopMediaSaver.ts @@ -1,5 +1,5 @@ import { registerMediaSaver } from './saveMedia'; -import { isElectron, isTauri } from './tauri'; +import { isElectron } from './tauri'; type ElectronSaveResult = { success?: boolean; @@ -21,49 +21,6 @@ async function blobToUint8Array(blob: Blob): Promise { return new Uint8Array(buffer); } -function guessFilters( - filename: string, - mimeType?: string, -): Array<{ name: string; extensions: string[] }> { - const ext = filename.includes('.') ? filename.split('.').pop()!.toLowerCase() : ''; - const mime = (mimeType || '').toLowerCase(); - - if ( - mime.startsWith('image/') || - ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg'].includes(ext) - ) { - return [ - { name: 'Images', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg'] }, - { name: 'All Files', extensions: ['*'] }, - ]; - } - if (mime.startsWith('video/') || ['mp4', 'webm', 'mkv', 'mov'].includes(ext)) { - return [ - { name: 'Videos', extensions: ['mp4', 'webm', 'mkv', 'mov'] }, - { name: 'All Files', extensions: ['*'] }, - ]; - } - if (mime.startsWith('audio/') || ['mp3', 'ogg', 'wav', 'm4a', 'flac'].includes(ext)) { - return [ - { name: 'Audio', extensions: ['mp3', 'ogg', 'wav', 'm4a', 'flac'] }, - { name: 'All Files', extensions: ['*'] }, - ]; - } - if (mime === 'application/pdf' || ext === 'pdf') { - return [ - { name: 'PDF', extensions: ['pdf'] }, - { name: 'All Files', extensions: ['*'] }, - ]; - } - if (ext) { - return [ - { name: ext.toUpperCase(), extensions: [ext] }, - { name: 'All Files', extensions: ['*'] }, - ]; - } - return [{ name: 'All Files', extensions: ['*'] }]; -} - async function saveWithElectron(blob: Blob, filename: string): Promise { const media = (window.electron as { media?: ElectronMediaApi } | undefined)?.media; if (!media?.saveFile) { @@ -82,25 +39,6 @@ async function saveWithElectron(blob: Blob, filename: string): Promise { throw new Error(result.error || 'Failed to save file'); } } - -async function saveWithTauri(blob: Blob, filename: string): Promise { - const { save } = await import('@tauri-apps/plugin-dialog'); - const { writeFile } = await import('@tauri-apps/plugin-fs'); - - const path = await save({ - defaultPath: filename, - filters: guessFilters(filename, blob.type), - }); - if (!path) return; - - const data = await blobToUint8Array(blob); - await writeFile(path, data); -} - -/** - * Wire Electron / Tauri native save dialogs into core saveMedia helpers. - * Call once at desktop app startup. No-ops in plain browser. - */ export function registerDesktopMediaSaver(): void { if (isElectron()) { registerMediaSaver(async (blob, filename) => { @@ -108,10 +46,4 @@ export function registerDesktopMediaSaver(): void { }); return; } - - if (isTauri()) { - registerMediaSaver(async (blob, filename) => { - await saveWithTauri(blob, filename); - }); - } } diff --git a/src/app/utils/tauri.ts b/src/app/utils/tauri.ts index 225d08c7..ac049804 100644 --- a/src/app/utils/tauri.ts +++ b/src/app/utils/tauri.ts @@ -1,5 +1,5 @@ /** - * Open an external URL using Tauri opener plugin on desktop/mobile, or window.open in browser + * Open an external URL using Electron's shell.openExternal, or window.open in browser * @param url The URL to open */ export const openExternalUrl = async (url: string): Promise => { @@ -19,31 +19,6 @@ export const openExternalUrl = async (url: string): Promise => { } } - // Use Tauri for actual Tauri builds - if (isTauri() && !isElectron()) { - try { - // First, try the plugin directly (works on both desktop and mobile) - console.log('[openExternalUrl] trying Tauri opener plugin...'); - const { openUrl } = await import('@tauri-apps/plugin-opener'); - await openUrl(url); - console.log('[openExternalUrl] Tauri plugin succeeded'); - return; - } catch (pluginErr) { - console.warn('[openExternalUrl] Tauri opener plugin failed:', pluginErr); - - // Fallback: try the custom command (useful if plugin fails due to ACL) - try { - console.log('[openExternalUrl] trying Tauri invoke command fallback...'); - const { invoke } = await import('@tauri-apps/api/core'); - await invoke('open_external_url', { url }); - console.log('[openExternalUrl] Tauri command fallback succeeded'); - return; - } catch (invokeErr) { - console.error('[openExternalUrl] Tauri command fallback also failed:', invokeErr); - } - } - } - console.log('[openExternalUrl] falling back to window.open'); window.open(url, '_blank'); }; @@ -131,7 +106,7 @@ const importCapacitorLocalNotifications = async (): Promise => { // Use Electron's window focus if in Electron @@ -146,18 +121,6 @@ export const focusWindow = async (): Promise => { console.warn('Failed to focus Electron window:', err); } } - - // Use Tauri's window focus for actual Tauri builds - if (isTauri() && !isElectron()) { - try { - const { getCurrentWindow } = await import('@tauri-apps/api/window'); - const window = getCurrentWindow(); - await window.unminimize(); - await window.setFocus(); - } catch (err) { - console.warn('Failed to focus Tauri window:', err); - } - } }; /** @@ -187,26 +150,6 @@ export const setupNotificationTapListener = async ( } } - // Use Tauri plugin for actual Tauri builds (not Electron) - if (isTauri() && !isElectron()) { - try { - const { onAction } = await import('@tauri-apps/plugin-notification'); - - await onAction(async (notification) => { - // Bring window to front first - await focusWindow(); - - // Get the path from extra data and navigate - const path = notification.notification?.extra?.path; - if (path && typeof path === 'string' && notificationTapCallback) { - notificationTapCallback(path); - } - }); - } catch (err) { - console.warn('Failed to set up Tauri notification tap listener:', err); - } - } - if (isCapacitorNative()) { try { const { LocalNotifications } = await importCapacitorLocalNotifications(); @@ -325,31 +268,6 @@ const sendBrowserNotification = (options: { /** Flag to track if notification channel has been created on Android */ let notificationChannelCreated = false; -/** - * Create notification channel for Android - * Required for Android 8.0+ to show notifications - */ -const ensureNotificationChannel = async (): Promise => { - if (notificationChannelCreated || !isAndroid()) return; - - try { - const { createChannel, Importance } = await import('@tauri-apps/plugin-notification'); - - await createChannel({ - id: 'messages', - name: 'Messages', - description: 'Message notifications from Matrix', - importance: Importance.High, - vibration: true, - sound: 'default', - }); - - notificationChannelCreated = true; - } catch (err) { - console.warn('Failed to create notification channel:', err); - } -}; - const ensureCapacitorNotificationChannel = async (): Promise => { if (notificationChannelCreated || !isAndroid()) return; @@ -375,7 +293,7 @@ const ensureCapacitorNotificationChannel = async (): Promise => { * Request notification permission across Electron, Tauri, Capacitor, and browser */ export const requestSystemNotificationPermission = async (): Promise => { - if (isElectron() || (isTauri() && !isElectron())) { + if (isElectron()) { if (!('Notification' in window)) return false; const permission = await Notification.requestPermission(); return permission === 'granted'; @@ -423,8 +341,7 @@ export const getSystemNotificationPermissionState = async (): Promise => { } } - // Use Tauri's invoke for actual Tauri builds on Linux - if (isTauri() && !isElectron() && isLinux()) { - try { - const { invoke } = await import('@tauri-apps/api/core'); - const dataUrl = await invoke('read_clipboard_image'); - - if (!dataUrl) return null; - - // Convert data URL to File - const response = await fetch(dataUrl); - const blob = await response.blob(); - if (blob.size < 32) return null; - return new File([blob], 'clipboard-image.png', { type: 'image/png' }); - } catch (err) { - console.warn('Failed to read Tauri clipboard image:', err); - return null; - } - } - return null; }; diff --git a/src/app/utils/tauriShell.ts b/src/app/utils/tauriShell.ts deleted file mode 100644 index ae7fa2e1..00000000 --- a/src/app/utils/tauriShell.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Tauri shell open utility, only imported in Tauri builds - */ - -export async function openWithTauriShell(url: string): Promise { - // @ts-ignore - const { open } = await import(/* @vite-ignore */ '@tauri-apps/plugin-shell'); - await open(url); -} diff --git a/src/app/utils/telegramStickerImport.ts b/src/app/utils/telegramStickerImport.ts index 85aecfe7..f08deb8c 100644 --- a/src/app/utils/telegramStickerImport.ts +++ b/src/app/utils/telegramStickerImport.ts @@ -1,5 +1,4 @@ import { MatrixClient } from 'matrix-js-sdk'; -import { fetch as tauriFetch } from '@tauri-apps/plugin-http'; import { AccountDataEvent } from '../../types/matrix/accountData'; import { ImageUsage, PackContent, PackImages } from '../plugins/custom-emoji/types'; import { getAccountData } from './room'; @@ -137,7 +136,7 @@ async function getFilePath(botToken: string, fileId: string): Promise { * @returns File blob */ async function downloadFile(botToken: string, filePath: string): Promise { - const response = await tauriFetch(`${TELEGRAM_FILE_API}${botToken}/${filePath}`); + const response = await fetch(`${TELEGRAM_FILE_API}${botToken}/${filePath}`); if (!response.ok) { throw new Error(`Failed to download file: ${response.statusText}`); diff --git a/src/index.tsx b/src/index.tsx index 6af9abe9..58bc62d2 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -15,7 +15,7 @@ import './index.css'; import { trimTrailingSlash } from './app/utils/common'; import App from './app/pages/App'; -import { applySafeAreaInsets, isTauri } from './app/utils/tauri'; +import { applySafeAreaInsets } from './app/utils/tauri'; import { enableViewTransitionsForNavigation } from './app/utils/viewTransitions'; import { registerDesktopMediaSaver } from './app/utils/registerDesktopMediaSaver'; @@ -60,57 +60,6 @@ if ('serviceWorker' in navigator) { }); } -/** - * Check if we're running in Electron (not Tauri) - * Electron exposes window.electron in preload.js - */ -const isElectron = (): boolean => 'electron' in window; - -/** - * Check for app updates using Tauri updater - * Prompts user if update is available and handles download/install - * Note: Electron has its own auto-updater in main.js, so skip for Electron - */ -async function checkForUpdates() { - // Skip if in Electron - Electron has its own auto-updater - if (isElectron()) { - console.log('Update check skipped - Electron handles updates natively'); - return; - } - - // Only run in Tauri context (not Electron) - if (!isTauri() || isElectron()) { - console.log('Update check skipped - not running in Tauri'); - return; - } - - console.log('Checking for updates...'); - try { - const { check } = await import('@tauri-apps/plugin-updater'); - const { ask } = await import('@tauri-apps/plugin-dialog'); - const { relaunch } = await import('@tauri-apps/plugin-process'); - - const update = await check(); - console.log('Update check result:', update); - if (update) { - console.log(`Update available: ${update.version}`); - const shouldUpdate = await ask( - `A new version (${update.version}) is available. Would you like to update now?`, - { title: 'Update Available', kind: 'info' }, - ); - if (shouldUpdate) { - console.log('User chose to update, downloading...'); - await update.downloadAndInstall(); - await relaunch(); - } - } else { - console.log('App is up to date'); - } - } catch (error) { - console.error('Failed to check for updates:', error); - } -} - const mountApp = () => { const rootContainer = document.getElementById('root'); @@ -124,8 +73,3 @@ const mountApp = () => { }; mountApp(); - -// Check for updates after app loads (with delay to not block startup) -setTimeout(() => { - checkForUpdates(); -}, 3000);