Skip to content

Commit db59f39

Browse files
committed
fix: convert local emoji paths to Tauri asset URLs
Use convertFileSrc from @tauri-apps/api/core to convert local file paths to asset:// URLs that work in Tauri's WebView.
1 parent ff365a3 commit db59f39

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/utils/emojis.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import twemoji, { type TwemojiOptions } from '@discordapp/twemoji';
22

3+
import { isTauriEnvironment } from './environment';
4+
35
const EMOJI_FORMAT = 'svg';
6+
const CDN_BASE = 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/';
47

58
export async function convertTextToEmojiImgHtml(text: string): Promise<string> {
9+
if (!isTauriEnvironment()) {
10+
// Browser fallback - use CDN
11+
return twemoji.parse(text, {
12+
folder: EMOJI_FORMAT,
13+
base: CDN_BASE,
14+
});
15+
}
16+
17+
// In Tauri mode, convert local file paths to asset:// URLs
18+
const { convertFileSrc } = await import('@tauri-apps/api/core');
619
const directory = await window.gitify.twemojiDirectory();
720

821
return twemoji.parse(text, {
9-
folder: EMOJI_FORMAT,
1022
callback: (icon: string, _options: TwemojiOptions) => {
11-
return `${directory}/${icon}.${EMOJI_FORMAT}`;
23+
const filePath = `${directory}/${icon}.${EMOJI_FORMAT}`;
24+
return convertFileSrc(filePath);
1225
},
1326
});
1427
}

0 commit comments

Comments
 (0)