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!

✨ Makes startingView configurable

Alicia Sykescc639a7e200b
diff --git a/.env b/.env
index 43ee620b..867b40cd 100644
--- a/.env
+++ b/.env
@@ -49,9 +49,6 @@
# Override the page title for the frontend app
# VITE_APP_TITLE=''
-# Set the default view to load on startup (can be `minimal`, `workspace` or `home`)
-# VITE_APP_STARTING_VIEW=home
-
# Set the Vue app routing mode (can be 'hash', 'history' or 'abstract')
# VITE_APP_ROUTING_MODE=history
diff --git a/docs/configuring.md b/docs/configuring.md
index a40325cb..ca4625ec 100644
--- a/docs/configuring.md
+++ b/docs/configuring.md
@@ -104,7 +104,7 @@ For more info, see the[Multi-Page docs](/docs/pages-and-sections.md#multi-page-s
**Field** | **Type** | **Required**| **Description**
--- | --- | --- | ---
**`language`** | `string` | _Optional_ | The 2 (or 4-digit) [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) for your language, e.g. `en` or `en-GB`. This must be a language that the app has already been [translated](https://github.com/Lissy93/dashy/tree/master/src/assets/locales) into. If your language is unavailable, Dashy will fallback to English. By default Dashy will attempt to auto-detect your language, although this may not work on some privacy browsers.
-~~**`startingView`**~~ | `enum` | _Optional_ | Which page to load by default, and on the base page or domain root. You can still switch to different views from within the UI. Can be either `default`, `minimal` or `workspace`. Defaults to `default`. NOTE: This has been replaced by an environmental variable: `VITE_APP_STARTING_VIEW` in V3 onwards
+**`startingView`** | `enum` | _Optional_ | Which view to land on when visiting `/`. One of `home`, `minimal` or `workspace`. Defaults to `home`. Applied at runtime, so no rebuild is needed. You can always switch views from the UI. (Legacy value `default` is accepted as an alias for `home`.)
**`defaultOpeningMethod`** | `enum` | _Optional_ | The default opening method for items, if no `target` is specified for a given item. Can be either `newtab`, `sametab`, `modal`, `workspace`, `clipboard`, `top` or `parent`. Defaults to `newtab`
**`statusCheck`** | `boolean` | _Optional_ | When set to `true`, Dashy will ping each of your services and display their status as a dot next to each item. This can be overridden by setting `statusCheck` under each item. Defaults to `false`
**`statusCheckInterval`** | `number` | _Optional_ | The number of seconds between checks. If set to `0` then service will only be checked on initial page load, which is usually the desired functionality. If value is less than `10` you may experience a hit in performance. Defaults to `0`
diff --git a/docs/pages-and-sections.md b/docs/pages-and-sections.md
index 6de0bf59..41936995 100644
--- a/docs/pages-and-sections.md
+++ b/docs/pages-and-sections.md
@@ -65,8 +65,6 @@ The following example shows creating a config, publishing it as a [Gist](https:/
Only top-level fields supported by sub-pages are `pageInfo` and `sections`. The `appConfig` and `pages` will always be inherited from your main `conf.yml` file. Other than that, sub-pages behave exactly the same as your default view, and can contain sections, items, widgets and page info like nav links, title and logo.
-Note that since page paths are required by the router, they are set at build-time, not run-time, and so a rebuild (happens automatically) is required for changes to page paths to take effect (this only applies to changes to the `pages` array, rebuild isn't required for editing page content).
-
### URL Structure
Every view in Dashy shares the same URL shape, so any config can be reached from any view:
diff --git a/src/main.js b/src/main.js
index a1026961..17acfb4b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -69,26 +69,21 @@ ErrorReporting(app, router);
// Mount the app
const mount = () => app.mount('#app');
-store.dispatch(Keys.INITIALIZE_CONFIG).then(() => {
+/* Handle failures of third-party auth initialization */
+const handleAuthFailure = (provider, err) => {
+ ErrorHandler(`Failed to authenticate with ${provider}`, err);
+ store.commit(Keys.CRITICAL_ERROR_MSG, `Authentication failed (${provider}). See console for details.`);
+ mount();
+};
+
+router.isReady().then(() => {
if (isOidcEnabled()) {
- initOidcAuth()
- .then(() => mount())
- .catch((e) => {
- ErrorHandler('Failed to authenticate with OIDC', e);
- });
- } else if (isKeycloakEnabled()) { // If Keycloak is enabled, initialize auth
- initKeycloakAuth()
- .then(() => mount())
- .catch((e) => {
- ErrorHandler('Failed to authenticate with Keycloak', e);
- });
- } else if (isHeaderAuthEnabled()) { // If header auth is enabled, initialize auth
- initHeaderAuth()
- .then(() => mount())
- .catch((e) => {
- ErrorHandler('Failed to authenticate with server', e);
- });
- } else { // If no third-party auth, just mount the app as normal
+ initOidcAuth().then(mount).catch((e) => handleAuthFailure('OIDC', e));
+ } else if (isKeycloakEnabled()) {
+ initKeycloakAuth().then(mount).catch((e) => handleAuthFailure('Keycloak', e));
+ } else if (isHeaderAuthEnabled()) {
+ initHeaderAuth().then(mount).catch((e) => handleAuthFailure('Header Auth', e));
+ } else {
mount();
}
});
diff --git a/src/router.js b/src/router.js
index 512fc5f3..337b67a5 100644
--- a/src/router.js
+++ b/src/router.js
@@ -13,8 +13,11 @@ import { Progress } from 'rsup-progress';
import Home from '@/views/Home.vue';
// Import helper functions, config data and defaults
+import store from '@/store';
+import Keys from '@/utils/StoreMutations';
import { isAuthEnabled, isLoggedIn, isGuestAccessEnabled } from '@/utils/auth/Auth';
import { metaTagData, startingView as defaultStartingView, routePaths } from '@/utils/config/defaults';
+import { VIEW_META } from '@/utils/config/ConfigHelpers';
import ErrorHandler from '@/utils/logging/ErrorHandler';
const progress = new Progress({ color: 'var(--progress-bar)' });
@@ -27,19 +30,11 @@ const isAuthenticated = () => {
return (!authEnabled || userLoggedIn || guestEnabled);
};
-// Get the default starting view from environmental variable
-const startingView = import.meta.env.VITE_APP_STARTING_VIEW || defaultStartingView;
-
-/**
- * Returns the component that should be rendered at the base path,
- * Defaults to Home, but the user can change this to Workspace of Minimal
- */
-const getStartingComponent = () => {
- switch (startingView) {
- case 'minimal': return () => import('./views/Minimal.vue');
- case 'workspace': return () => import('./views/Workspace.vue');
- default: return Home;
- }
+/* Resolve landing view from appConfig.startingView at runtime if set */
+const resolveStartingView = () => {
+ const raw = store.state.config?.appConfig?.startingView || defaultStartingView;
+ const view = raw === 'default' ? 'home' : raw;
+ return VIEW_META[view] ? view : 'home';
};
/* Returns the meta tags for each route */
@@ -80,11 +75,17 @@ const history = mode === 'hash'
const router = createRouter({
history,
routes: [
- { // The default view can be customized by the user
+ {
path: '/',
- name: `landing-page-${startingView}`,
- component: getStartingComponent(),
+ name: 'landing',
+ component: Home,
meta: makeMetaTags('Home Page'),
+ beforeEnter: (to, from, next) => {
+ const view = resolveStartingView();
+ if (!view || view === 'home') next();
+ // If user set `startingView`, we redirect to canonical /<view> URL
+ else next(`/${view}`);
+ },
},
// Canonical /<view>/:page?/:section? routes for each view
...makeViewRoutes(routePaths.home, 'home', Home, 'Home Page'),
@@ -143,13 +144,15 @@ const router = createRouter({
});
/**
- * Before loading a route, check if the user has authentication enabled
- * if so, then ensure that they are correctly logged in as a valid user
- * If not logged in, prevent all access and redirect them to login page
- * */
+ * On first page load, initialize and wait for the the config loading
+ * Then, if auth enabled and user not logged in yet, redirect to login page
+ */
router.beforeEach(async (to, from, next) => {
progress.start();
try {
+ if (!store.state.rootConfig && !store.state.criticalError) {
+ await store.dispatch(Keys.INITIALIZE_CONFIG);
+ }
if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });
else next();
} catch (e) {
@@ -165,5 +168,11 @@ router.afterEach((to) => {
});
});
+/* Catch navigation + lazy-import failures */
+router.onError((err) => {
+ progress.end();
+ ErrorHandler('Navigation failed. Try hard-reload (Shift + F5)', err);
+});
+
// All done - export the now configured router
export default router;
diff --git a/src/utils/config/ConfigSchema.json b/src/utils/config/ConfigSchema.json
index 5c0cd6a1..a152764b 100644
--- a/src/utils/config/ConfigSchema.json
+++ b/src/utils/config/ConfigSchema.json
@@ -188,12 +188,13 @@
"title": "Starting View",
"type": "string",
"enum": [
+ "home",
"default",
"minimal",
"workspace"
],
- "default": "default",
- "description": "Which page to load by default, and on the base page or domain root. You can still switch to different views from within the UI"
+ "default": "home",
+ "description": "Which view to land on at /. 'home' (or legacy 'default') for the standard home page, 'minimal' for the minimal start page, or 'workspace' for the workspace view. Users can switch views at any time from the UI."
},
"defaultOpeningMethod": {
"title": "Default Opening Method",