Drop the dead Tauri branches and the plugin packages. [skip build]
This commit is contained in:
@@ -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<Uint8Array> {
|
||||
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<void> {
|
||||
const media = (window.electron as { media?: ElectronMediaApi } | undefined)?.media;
|
||||
if (!media?.saveFile) {
|
||||
@@ -82,25 +39,6 @@ async function saveWithElectron(blob: Blob, filename: string): Promise<void> {
|
||||
throw new Error(result.error || 'Failed to save file');
|
||||
}
|
||||
}
|
||||
|
||||
async function saveWithTauri(blob: Blob, filename: string): Promise<void> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+4
-140
@@ -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<void> => {
|
||||
@@ -19,31 +19,6 @@ export const openExternalUrl = async (url: string): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<CapacitorLocalNotifi
|
||||
import(/* @vite-ignore */ CAPACITOR_LOCAL_NOTIFICATIONS_MODULE_ID);
|
||||
|
||||
/**
|
||||
* Bring the Tauri window to the front and focus it
|
||||
* Bring the app window to the front and focus it
|
||||
*/
|
||||
export const focusWindow = async (): Promise<void> => {
|
||||
// Use Electron's window focus if in Electron
|
||||
@@ -146,18 +121,6 @@ export const focusWindow = async (): Promise<void> => {
|
||||
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<void> => {
|
||||
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<void> => {
|
||||
if (notificationChannelCreated || !isAndroid()) return;
|
||||
|
||||
@@ -375,7 +293,7 @@ const ensureCapacitorNotificationChannel = async (): Promise<void> => {
|
||||
* Request notification permission across Electron, Tauri, Capacitor, and browser
|
||||
*/
|
||||
export const requestSystemNotificationPermission = async (): Promise<boolean> => {
|
||||
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<Permission
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a notification using Tauri's notification plugin
|
||||
* Falls back to browser Notification API if not in Tauri
|
||||
* Send a notification on Electron or Capacitor, falling back to the browser Notification API
|
||||
*/
|
||||
export const sendNotification = async (options: {
|
||||
title: string;
|
||||
@@ -453,40 +370,6 @@ export const sendNotification = async (options: {
|
||||
}
|
||||
}
|
||||
|
||||
// Use Tauri plugin for actual Tauri builds (not Electron)
|
||||
if (isTauri() && !isElectron()) {
|
||||
try {
|
||||
const {
|
||||
sendNotification: tauriSendNotification,
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
} = await import('@tauri-apps/plugin-notification');
|
||||
|
||||
let permissionGranted = await isPermissionGranted();
|
||||
if (!permissionGranted) {
|
||||
const permission = await requestPermission();
|
||||
permissionGranted = permission === 'granted';
|
||||
}
|
||||
|
||||
if (permissionGranted) {
|
||||
// Ensure notification channel exists on Android
|
||||
await ensureNotificationChannel();
|
||||
|
||||
await tauriSendNotification({
|
||||
title,
|
||||
body,
|
||||
// Use the channel on Android
|
||||
channelId: isAndroid() ? 'messages' : undefined,
|
||||
// Store path in extra data for notification tap handling
|
||||
extra: path ? { path } : undefined,
|
||||
});
|
||||
}
|
||||
return;
|
||||
} catch (err) {
|
||||
console.warn('Tauri notification failed:', err);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCapacitorNative()) {
|
||||
try {
|
||||
const { LocalNotifications } = await importCapacitorLocalNotifications();
|
||||
@@ -563,25 +446,6 @@ export const readClipboardImage = async (): Promise<File | null> => {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<string | null>('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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/**
|
||||
* Tauri shell open utility, only imported in Tauri builds
|
||||
*/
|
||||
|
||||
export async function openWithTauriShell(url: string): Promise<void> {
|
||||
// @ts-ignore
|
||||
const { open } = await import(/* @vite-ignore */ '@tauri-apps/plugin-shell');
|
||||
await open(url);
|
||||
}
|
||||
@@ -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<string> {
|
||||
* @returns File blob
|
||||
*/
|
||||
async function downloadFile(botToken: string, filePath: string): Promise<Blob> {
|
||||
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}`);
|
||||
|
||||
+1
-57
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user