diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-01-21 18:12:20 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-01-26 09:06:54 +0100 |
| commit | 2ff3b90fd1ff908fdc0e341396b58c8f8192bd3a (patch) | |
| tree | e1e493204e73c910a6d0729ea54787709a3a1cf8 /gui/src | |
| parent | d618fecdf60d3dd28ace03fcfdaa9c2d448de151 (diff) | |
| download | mullvadvpn-2ff3b90fd1ff908fdc0e341396b58c8f8192bd3a.tar.xz mullvadvpn-2ff3b90fd1ff908fdc0e341396b58c8f8192bd3a.zip | |
Replace absolute paths for application icons on Linux with data URLs
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/linux-desktop-entry.ts | 16 | ||||
| -rw-r--r-- | gui/src/renderer/components/ImageView.tsx | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/gui/src/main/linux-desktop-entry.ts b/gui/src/main/linux-desktop-entry.ts index dc1ae0e57b..a2712bb7e3 100644 --- a/gui/src/main/linux-desktop-entry.ts +++ b/gui/src/main/linux-desktop-entry.ts @@ -1,4 +1,5 @@ import child_process from 'child_process'; +import { nativeImage } from 'electron'; import fs from 'fs'; import path from 'path'; import { ILinuxApplication } from '../shared/application-types'; @@ -45,7 +46,7 @@ export async function getAppIcon(name?: string) { // Chromium doesn't support .xpm files const extensions = ['svg', 'png']; - return findIcon(name, extensions, [ + const iconPath = await findIcon(name, extensions, [ getIconDirectories(), await getGtkThemeDirectories(), // Begin with preferred sized but if nothing matches other sizes should be considered as well. @@ -53,6 +54,19 @@ export async function getAppIcon(name?: string) { // Search in all categories of icons. [/.*/], ]); + + if (iconPath && path.extname(iconPath) === '.svg') { + try { + const contents = await fs.promises.readFile(iconPath); + return `data:image/svg+xml;base64,${contents.toString('base64')}`; + } catch (error) { + log.error(`Failed to read icon of application: ${name},`, error); + } + } else if (iconPath) { + return nativeImage.createFromPath(iconPath).toDataURL(); + } + + return undefined; } // Implemented according to freedesktop specification. diff --git a/gui/src/renderer/components/ImageView.tsx b/gui/src/renderer/components/ImageView.tsx index c828a57c38..3be04159a2 100644 --- a/gui/src/renderer/components/ImageView.tsx +++ b/gui/src/renderer/components/ImageView.tsx @@ -39,7 +39,7 @@ const ImageMask = styled.div((props: IImageMaskProps) => { const HiddenImage = styled.img({ visibility: 'hidden' }); export default function ImageView(props: IImageViewProps) { - const url = props.source.startsWith('/') + const url = props.source.startsWith('data:') ? props.source : `../../assets/images/${props.source}.svg`; |
