Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

🏎️ Lazy-load simple-icons and error report

Alicia Sykesec346dd48eec
diff --git a/src/components/LinkItems/ItemIcon.vue b/src/components/LinkItems/ItemIcon.vue
index cf0eb3c4..187b1045 100644
--- a/src/components/LinkItems/ItemIcon.vue
+++ b/src/components/LinkItems/ItemIcon.vue
@@ -6,10 +6,10 @@
<i v-else-if="iconType === 'emoji'" :class="`emoji-icon ${size}`" >{{getEmoji(iconPath)}}</i>
<!-- Material Design Icon -->
<span v-else-if="iconType === 'mdi'" :class=" `mdi ${icon} ${size}`"></span>
- <!-- Simple-Icons -->
+ <!-- Simple-Icons (siPath resolved async after lazy-load) -->
<svg v-else-if="iconType === 'si' && !broken" :class="`simple-icons ${size}`"
role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
- <path :d="getSimpleIcon(icon)" />
+ <path v-if="siPath" :d="siPath" />
</svg>
<!-- Standard image asset icon -->
<img v-else-if="icon" :src="iconPath" @error="imageNotFound"
@@ -28,7 +28,12 @@ import emojiLookup from '@/utils/emojis.json';
import { asciiHash } from '@/utils/MiscHelpers';
import { faviconApi as defaultFaviconApi, faviconApiEndpoints, iconCdns } from '@/utils/config/defaults';
-import * as simpleicons from 'simple-icons';
+// simple-icons is heavy. So lazy load and then share across instances
+let simpleIconsPromise = null;
+const loadSimpleIcons = () => {
+ if (!simpleIconsPromise) simpleIconsPromise = import('simple-icons');
+ return simpleIconsPromise;
+};
export default {
name: 'Icon',
@@ -59,8 +64,12 @@ export default {
return {
broken: false, // If true, was unable to resolve icon
attemptedFallback: false,
+ siPath: '', // Resolved SVG path for simple-icons (set async)
};
},
+ watch: {
+ icon: { immediate: true, handler: 'resolveSimpleIcon' },
+ },
methods: {
/* Determine icon type, e.g. local or remote asset, SVG, favicon, font-awesome, etc */
determineImageType(img) {
@@ -89,7 +98,7 @@ export default {
case 'custom-favicon': return this.getCustomFavicon(url, img);
case 'generative': return this.getGenerativeIcon(url);
case 'mdi': return img; // Material design icons
- case 'simple-icons': return this.getSimpleIcon(img);
+ // case 'simple-icons': return this.getSimpleIcon(img);
case 'home-lab-icons': return this.getHomeLabIcon(img);
case 'selfhst-icons': return this.getSelfhstIcon(img); // selfh.st/icons
case 'svg': return img; // Local SVG icon
@@ -187,15 +196,21 @@ export default {
const host = encodeURI(url) || Math.random().toString();
return (cdn || iconCdns.generative).replace('{icon}', asciiHash(host));
},
- /* Returns the SVG path content */
- getSimpleIcon(img) {
- const imageName = img.charAt(3).toUpperCase() + img.slice(4);
- const icon = simpleicons[`si${imageName}`];
+ /* Loads SVG path for simple-icons ID. Only loads SI module on first use */
+ async resolveSimpleIcon() {
+ if (this.iconType !== 'si' || !this.icon) {
+ this.siPath = '';
+ return;
+ }
+ const mod = await loadSimpleIcons();
+ const imageName = this.icon.charAt(3).toUpperCase() + this.icon.slice(4);
+ const icon = mod[`si${imageName}`];
if (!icon) {
this.imageNotFound(`No icon was found for '${imageName}' in Simple Icons`);
- return null;
+ this.siPath = '';
+ return;
}
- return icon.path;
+ this.siPath = icon.path;
},
getSelfhstIcon(img, cdn) {
const imageName = img.slice(3).toLocaleLowerCase();
@@ -306,8 +321,6 @@ export default {
fill: currentColor;
}
}
- /* Simple Icons. Height is set explicitly so the global `a svg { height: 1rem }`
- * default in global-styles.scss doesn't squash them. */
.item-icon .simple-icons {
width: 2rem;
height: 2rem;
diff --git a/src/utils/logging/ErrorHandler.js b/src/utils/logging/ErrorHandler.js
index 19eca54a..d1d795f5 100644
--- a/src/utils/logging/ErrorHandler.js
+++ b/src/utils/logging/ErrorHandler.js
@@ -1,6 +1,6 @@
-import * as Sentry from '@sentry/vue';
import { warningMsg, statusMsg, statusErrorMsg } from '@/utils/logging/CoolConsole';
import { sessionStorageKeys } from '@/utils/config/defaults';
+import { reportError } from '@/utils/logging/SentryRef';
/* Makes the current time, like hh:mm:ss */
const makeTime = () => {
@@ -25,7 +25,7 @@ const appendToErrorLog = (msg) => {
export const ErrorHandler = function handler(msg, errorStack) {
warningMsg(msg, errorStack); // Print to console
appendToErrorLog(msg); // Save to local storage
- Sentry.captureMessage(`[USER-WARN] ${msg}`); // Report to bug tracker (if enabled)
+ reportError(`[USER-WARN] ${msg}`); // Report to bug tracker (if enabled)
};
/* Similar to error handler, but for recording general info */
diff --git a/src/utils/logging/ErrorReporting.js b/src/utils/logging/ErrorReporting.js
index 0c034272..5b237732 100644
--- a/src/utils/logging/ErrorReporting.js
+++ b/src/utils/logging/ErrorReporting.js
@@ -9,34 +9,30 @@
import $store from '@/store';
import { sentryDsn } from '@/utils/config/defaults';
+import { setSentryInstance } from '@/utils/logging/SentryRef';
const ErrorReporting = async (app, router) => {
- // Fetch users config
const appConfig = $store.getters.appConfig || {};
- // Check if error reporting is enabled. Only proceed if user has turned it on.
- if (appConfig.enableErrorReporting) {
- // Get current app version
- const appVersion = import.meta.env.VITE_APP_VERSION ? `Dashy@${import.meta.env.VITE_APP_VERSION}` : '';
- // Import Sentry
- const { default: Sentry } = await import('@sentry/vue');
- const { Integrations } = await import('@sentry/tracing');
- // Get the Data Source Name for your or Dashy's Sentry instance
- const dsn = appConfig.sentryDsn || sentryDsn;
- // Initialize Sentry
- Sentry.init({
- app,
- dsn,
- integrations: [
- new Integrations.BrowserTracing({
- routingInstrumentation: Sentry.vueRouterInstrumentation(router),
- }),
- ],
- tracesSampleRate: 1.0,
- release: appVersion,
- });
- } else {
- // Error reporting has not been enabled by the user. Do Nothing.
- }
+ if (!appConfig.enableErrorReporting) return;
+
+ const appVersion = import.meta.env.VITE_APP_VERSION ? `Dashy@${import.meta.env.VITE_APP_VERSION}` : '';
+ const Sentry = await import('@sentry/vue');
+ const { Integrations } = await import('@sentry/tracing');
+ const dsn = appConfig.sentryDsn || sentryDsn;
+
+ Sentry.init({
+ app,
+ dsn,
+ integrations: [
+ new Integrations.BrowserTracing({
+ routingInstrumentation: Sentry.vueRouterInstrumentation(router),
+ }),
+ ],
+ tracesSampleRate: 1.0,
+ release: appVersion,
+ });
+
+ setSentryInstance(Sentry);
};
export default ErrorReporting;
diff --git a/src/utils/logging/SentryRef.js b/src/utils/logging/SentryRef.js
new file mode 100644
index 00000000..cafe93dc
--- /dev/null
+++ b/src/utils/logging/SentryRef.js
@@ -0,0 +1,14 @@
+/**
+ * Handle for lazy-loading Sentry
+ * So we never load Sentry unless the user has explicitly enabled error reporting
+ */
+
+let sentryInstance = null;
+
+export const setSentryInstance = (instance) => {
+ sentryInstance = instance;
+};
+
+export const reportError = (msg) => {
+ if (sentryInstance) sentryInstance.captureMessage(msg);
+};