Fix the mechanical style rules. [skip build]
This commit is contained in:
@@ -21,7 +21,7 @@ export function pruneAvatarCache(): void {
|
||||
if (loadedAvatars.size > MAX_CACHE_SIZE) {
|
||||
const iterator = loadedAvatars.values();
|
||||
// Remove oldest entries (first added)
|
||||
for (let i = 0; i < loadedAvatars.size - MAX_CACHE_SIZE; i++) {
|
||||
for (let i = 0; i < loadedAvatars.size - MAX_CACHE_SIZE; i += 1) {
|
||||
const result = iterator.next();
|
||||
if (!result.done) {
|
||||
loadedAvatars.delete(result.value);
|
||||
|
||||
@@ -543,6 +543,19 @@ export const setAppForegroundState = async (foreground: boolean): Promise<void>
|
||||
}
|
||||
};
|
||||
|
||||
/** Returns the current native UnifiedPush status, or undefined if unavailable. */
|
||||
export const getBackgroundSyncStatus = async (): Promise<UnifiedPushStatus | undefined> => {
|
||||
if (!isBackgroundSyncSupported()) return undefined;
|
||||
try {
|
||||
const { registerPlugin } = await loadCapacitorCore();
|
||||
const MatrixBackgroundSync = registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
return await MatrixBackgroundSync.getStatus();
|
||||
} catch (err) {
|
||||
console.warn('[BackgroundSync] getStatus failed:', err);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Re-opens the UnifiedPush distributor selection dialog.
|
||||
* Allows users to re-select or change their push notification distributor without terminal access.
|
||||
@@ -581,16 +594,3 @@ export const requestResetPushRegistration = async (): Promise<{ success: boolean
|
||||
return { success: false };
|
||||
}
|
||||
};
|
||||
|
||||
/** Returns the current native UnifiedPush status, or undefined if unavailable. */
|
||||
export const getBackgroundSyncStatus = async (): Promise<UnifiedPushStatus | undefined> => {
|
||||
if (!isBackgroundSyncSupported()) return undefined;
|
||||
try {
|
||||
const { registerPlugin } = await loadCapacitorCore();
|
||||
const MatrixBackgroundSync = registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
return await MatrixBackgroundSync.getStatus();
|
||||
} catch (err) {
|
||||
console.warn('[BackgroundSync] getStatus failed:', err);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,6 +30,10 @@ export function pickCatalogStaticPreviewUrl(item: DiscordCollectibleItem): strin
|
||||
}
|
||||
}
|
||||
|
||||
export function pickCatalogProfileEffectLoopUrl(item: DiscordCollectibleItem): string | undefined {
|
||||
return catalogAssetUrl(item, 'effect_1', 'effect_0', 'effect_2', 'effect_3');
|
||||
}
|
||||
|
||||
export function pickCatalogAnimatedPreviewUrl(item: DiscordCollectibleItem): string | undefined {
|
||||
switch (item.type) {
|
||||
case 'nameplate':
|
||||
@@ -47,10 +51,6 @@ export function pickCatalogProfileEffectIntroUrl(item: DiscordCollectibleItem):
|
||||
return catalogAssetUrl(item, 'effect_0');
|
||||
}
|
||||
|
||||
export function pickCatalogProfileEffectLoopUrl(item: DiscordCollectibleItem): string | undefined {
|
||||
return catalogAssetUrl(item, 'effect_1', 'effect_0', 'effect_2', 'effect_3');
|
||||
}
|
||||
|
||||
export function catalogProfileEffectIntroDurationMs(
|
||||
item: DiscordCollectibleItem,
|
||||
): number | undefined {
|
||||
|
||||
@@ -141,9 +141,9 @@ function replaceCdnUrls<T>(value: T, urlToMxc: Map<string, string>): T {
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
|
||||
Object.entries(value as Record<string, unknown>).forEach(([key, entry]) => {
|
||||
out[key] = replaceCdnUrls(entry, urlToMxc);
|
||||
}
|
||||
});
|
||||
return out as T;
|
||||
}
|
||||
return value;
|
||||
@@ -280,12 +280,12 @@ function dedupeVariantItems(items: DiscordCollectibleItem[]): DiscordCollectible
|
||||
export function groupCollectibleItems(items: DiscordCollectibleItem[]): CollectibleVariantGroup[] {
|
||||
const map = new Map<string, DiscordCollectibleItem[]>();
|
||||
|
||||
for (const item of items) {
|
||||
items.forEach((item) => {
|
||||
const key = variantGroupKey(item);
|
||||
const list = map.get(key);
|
||||
if (list) list.push(item);
|
||||
else map.set(key, [item]);
|
||||
}
|
||||
});
|
||||
|
||||
return [...map.entries()]
|
||||
.map(([id, groupItems]) => {
|
||||
|
||||
@@ -77,7 +77,7 @@ export function convertEmoticons(text: string): string {
|
||||
// e.g., :-) before :)
|
||||
const emoticons = Object.keys(EMOTICON_MAP).sort((a, b) => b.length - a.length);
|
||||
|
||||
for (const emoticon of emoticons) {
|
||||
emoticons.forEach((emoticon) => {
|
||||
// Escape special regex characters
|
||||
const escapedEmoticon = emoticon.replace(/[.*+?^${}()|[\]\\<>]/g, '\\$&');
|
||||
|
||||
@@ -93,7 +93,7 @@ export function convertEmoticons(text: string): string {
|
||||
// Otherwise convert to emoji
|
||||
return prefix + EMOTICON_MAP[emoticon];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ export function convertEmoticonsInHtml(html: string): string {
|
||||
// Sort emoticons by length (longest first) to handle overlapping patterns
|
||||
const emoticons = Object.keys(EMOTICON_MAP).sort((a, b) => b.length - a.length);
|
||||
|
||||
for (const emoticon of emoticons) {
|
||||
emoticons.forEach((emoticon) => {
|
||||
// Convert emoticon to HTML entity version (for < and >)
|
||||
const htmlEmoticon = emoticon.replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
@@ -130,7 +130,7 @@ export function convertEmoticonsInHtml(html: string): string {
|
||||
// Otherwise convert to emoji
|
||||
return prefix + EMOTICON_MAP[emoticon];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -85,13 +85,13 @@ export function fuzzyMatchAny(
|
||||
texts: Array<string | undefined | null>,
|
||||
): FuzzyMatch | null {
|
||||
let best: FuzzyMatch | null = null;
|
||||
for (const text of texts) {
|
||||
if (!text) continue;
|
||||
texts.forEach((text) => {
|
||||
if (!text) return;
|
||||
const match = fuzzyMatch(query, text);
|
||||
if (match && (!best || match.score > best.score)) {
|
||||
best = match;
|
||||
}
|
||||
}
|
||||
});
|
||||
return best;
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ export function fuzzyFilter<T>(
|
||||
}
|
||||
|
||||
const results: Array<{ item: T; score: number }> = [];
|
||||
for (const item of items) {
|
||||
items.forEach((item) => {
|
||||
const match = fuzzyMatchAny(q, getTexts(item));
|
||||
if (match) {
|
||||
results.push({ item, score: match.score });
|
||||
}
|
||||
}
|
||||
});
|
||||
results.sort((a, b) => b.score - a.score);
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -268,6 +268,34 @@ export function needsPngForMetadata(metadata: ImageMetadata): boolean {
|
||||
return Boolean(metadata.banner || metadata.avatarBorderColor || metadata.gradient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Blob from Uint8Array without relying on BufferSource/BlobPart quirks
|
||||
* across TS DOM lib / Electron versions (avoids SharedArrayBuffer typing issues).
|
||||
*/
|
||||
export function uint8ArrayToBlob(data: Uint8Array, type: string): Blob {
|
||||
const copy = new ArrayBuffer(data.byteLength);
|
||||
new Uint8Array(copy).set(data);
|
||||
return new Blob([copy], { type });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MIME type for an image format
|
||||
*/
|
||||
export function getMimeType(format: ImageFormat): string {
|
||||
switch (format) {
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'webp':
|
||||
return 'image/webp';
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'gif':
|
||||
return 'image/gif';
|
||||
default:
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert image data to PNG via canvas (needed for banner/border/gradient metadata).
|
||||
*/
|
||||
@@ -304,16 +332,6 @@ export async function convertImageDataToPng(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Blob from Uint8Array without relying on BufferSource/BlobPart quirks
|
||||
* across TS DOM lib / Electron versions (avoids SharedArrayBuffer typing issues).
|
||||
*/
|
||||
export function uint8ArrayToBlob(data: Uint8Array, type: string): Blob {
|
||||
const copy = new ArrayBuffer(data.byteLength);
|
||||
new Uint8Array(copy).set(data);
|
||||
return new Blob([copy], { type });
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed paarrot metadata (color and/or banner) into image data
|
||||
* Preserves existing metadata that is not being updated
|
||||
@@ -376,24 +394,6 @@ export function removeColorFromImage(imageData: ArrayBuffer | Uint8Array): Uint8
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MIME type for an image format
|
||||
*/
|
||||
export function getMimeType(format: ImageFormat): string {
|
||||
switch (format) {
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'webp':
|
||||
return 'image/webp';
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'gif':
|
||||
return 'image/gif';
|
||||
default:
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file extension for an image format
|
||||
*/
|
||||
|
||||
@@ -134,11 +134,11 @@ function parseStoredCollectible(value: unknown): StoredCollectible | undefined {
|
||||
if (!sku_id || !name || !assets || typeof assets !== 'object') return undefined;
|
||||
|
||||
const parsedAssets: Record<string, string> = {};
|
||||
for (const [key, mxc] of Object.entries(assets as Record<string, unknown>)) {
|
||||
Object.entries(assets as Record<string, unknown>).forEach(([key, mxc]) => {
|
||||
if (typeof mxc === 'string' && mxc.startsWith('mxc://')) {
|
||||
parsedAssets[key] = mxc;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (Object.keys(parsedAssets).length === 0) return undefined;
|
||||
|
||||
return {
|
||||
|
||||
+32
-32
@@ -152,6 +152,38 @@ export const getPaarrotUiContent = (room: Room | null): PaarrotUiContent | undef
|
||||
|
||||
export const hasRoomAppUi = (room: Room | null): boolean => getPaarrotUiContent(room) !== undefined;
|
||||
|
||||
export function isValidChild(mEvent: MatrixEvent): boolean {
|
||||
if (mEvent.getType() !== StateEvent.SpaceChild) return false;
|
||||
const stateKey = mEvent.getStateKey();
|
||||
if (!stateKey || !stateKey.startsWith('!')) return false;
|
||||
// via is required; omitting it (e.g. empty {}) removes the child per Matrix spec
|
||||
return Array.isArray(mEvent.getContent<{ via?: string[] }>().via);
|
||||
}
|
||||
|
||||
export const getAllParents = (roomToParents: RoomToParents, roomId: string): Set<string> => {
|
||||
const allParents = new Set<string>();
|
||||
|
||||
const addAllParentIds = (rId: string) => {
|
||||
if (allParents.has(rId)) return;
|
||||
allParents.add(rId);
|
||||
|
||||
const parents = roomToParents.get(rId);
|
||||
parents?.forEach((id) => addAllParentIds(id));
|
||||
};
|
||||
addAllParentIds(roomId);
|
||||
allParents.delete(roomId);
|
||||
return allParents;
|
||||
};
|
||||
|
||||
export const getSpaceChildren = (room: Room) =>
|
||||
getStateEvents(room, StateEvent.SpaceChild).reduce<string[]>((filtered, mEvent) => {
|
||||
const stateKey = mEvent.getStateKey();
|
||||
if (isValidChild(mEvent) && stateKey) {
|
||||
filtered.push(stateKey);
|
||||
}
|
||||
return filtered;
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* m.forum space root (forum board lobby), not a plain m.space or a lone m.forum topic channel.
|
||||
* Matrix sets create type m.forum on forum spaces but SDK isSpaceRoom() is often still false;
|
||||
@@ -201,38 +233,6 @@ export const isUnsupportedRoom = (room: Room | null): boolean => {
|
||||
return roomType !== RoomType.Space && roomType !== RoomType.Forum;
|
||||
};
|
||||
|
||||
export function isValidChild(mEvent: MatrixEvent): boolean {
|
||||
if (mEvent.getType() !== StateEvent.SpaceChild) return false;
|
||||
const stateKey = mEvent.getStateKey();
|
||||
if (!stateKey || !stateKey.startsWith('!')) return false;
|
||||
// via is required; omitting it (e.g. empty {}) removes the child per Matrix spec
|
||||
return Array.isArray(mEvent.getContent<{ via?: string[] }>().via);
|
||||
}
|
||||
|
||||
export const getAllParents = (roomToParents: RoomToParents, roomId: string): Set<string> => {
|
||||
const allParents = new Set<string>();
|
||||
|
||||
const addAllParentIds = (rId: string) => {
|
||||
if (allParents.has(rId)) return;
|
||||
allParents.add(rId);
|
||||
|
||||
const parents = roomToParents.get(rId);
|
||||
parents?.forEach((id) => addAllParentIds(id));
|
||||
};
|
||||
addAllParentIds(roomId);
|
||||
allParents.delete(roomId);
|
||||
return allParents;
|
||||
};
|
||||
|
||||
export const getSpaceChildren = (room: Room) =>
|
||||
getStateEvents(room, StateEvent.SpaceChild).reduce<string[]>((filtered, mEvent) => {
|
||||
const stateKey = mEvent.getStateKey();
|
||||
if (isValidChild(mEvent) && stateKey) {
|
||||
filtered.push(stateKey);
|
||||
}
|
||||
return filtered;
|
||||
}, []);
|
||||
|
||||
export const mapParentWithChildren = (
|
||||
roomToParents: RoomToParents,
|
||||
roomId: string,
|
||||
|
||||
+18
-18
@@ -1,3 +1,21 @@
|
||||
/**
|
||||
* Check if we're running inside Electron (not Tauri)
|
||||
*/
|
||||
export const isElectron = (): boolean => typeof window !== 'undefined' && 'electron' in window;
|
||||
|
||||
/**
|
||||
* Check if we're running inside a Capacitor native app
|
||||
*/
|
||||
export const isCapacitorNative = (): boolean => {
|
||||
if (typeof window === 'undefined') return false;
|
||||
const cap = (window as any).Capacitor;
|
||||
return Boolean(
|
||||
cap?.isNativePlatform?.() ||
|
||||
cap?.getPlatform?.() === 'android' ||
|
||||
cap?.getPlatform?.() === 'ios',
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Open an external URL using Electron's shell.openExternal, or window.open in browser
|
||||
* @param url The URL to open
|
||||
@@ -174,24 +192,6 @@ export const setupNotificationTapListener = async (
|
||||
*/
|
||||
export const isTauri = (): boolean => '__TAURI__' in window || '__TAURI_INTERNALS__' in window;
|
||||
|
||||
/**
|
||||
* Check if we're running inside Electron (not Tauri)
|
||||
*/
|
||||
export const isElectron = (): boolean => typeof window !== 'undefined' && 'electron' in window;
|
||||
|
||||
/**
|
||||
* Check if we're running inside a Capacitor native app
|
||||
*/
|
||||
export const isCapacitorNative = (): boolean => {
|
||||
if (typeof window === 'undefined') return false;
|
||||
const cap = (window as any).Capacitor;
|
||||
return Boolean(
|
||||
cap?.isNativePlatform?.() ||
|
||||
cap?.getPlatform?.() === 'android' ||
|
||||
cap?.getPlatform?.() === 'ios',
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if we're running on a mobile platform (Android/iOS)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user