show notification when offline

This commit is contained in:
Mads Rasmussen
2025-01-23 14:37:54 +01:00
parent 776e7313d0
commit 1db821ffcb
3 changed files with 51 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import type { UmbAppContextConfig } from './app-context-config.interface.js';
import { UmbNetworkConnectionStatusManager } from './network-connection-status.manager.js';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
@@ -13,6 +14,8 @@ export class UmbAppContext extends UmbContextBase<UmbAppContext> {
this.#serverUrl = config.serverUrl;
this.#backofficePath = config.backofficePath;
this.#serverConnection = config.serverConnection;
new UmbNetworkConnectionStatusManager(this);
}
getBackofficePath() {

View File

@@ -0,0 +1,46 @@
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
import {
UMB_NOTIFICATION_CONTEXT,
type UmbNotificationContext,
type UmbNotificationHandler,
} from '@umbraco-cms/backoffice/notification';
export class UmbNetworkConnectionStatusManager extends UmbControllerBase {
#notificationContext?: UmbNotificationContext;
#offlineNotification?: UmbNotificationHandler;
#localize = new UmbLocalizationController(this);
constructor(host: UmbControllerHost) {
super(host);
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
this.#notificationContext = notificationContext;
});
window.addEventListener('online', () => this.#onOnline());
window.addEventListener('offline', () => this.#onOffline());
}
#onOnline() {
this.#offlineNotification?.close();
}
#onOffline() {
this.#offlineNotification = this.#notificationContext?.stay('danger', {
data: {
headline: this.#localize.term('speechBubbles_offlineHeadline'),
message: this.#localize.term('speechBubbles_offlineMessage'),
},
});
}
override destroy() {
this.#offlineNotification?.close();
this.removeEventListener('online', () => this.#onOnline());
this.removeEventListener('offline', () => this.#onOffline());
super.destroy();
}
}

View File

@@ -1488,6 +1488,8 @@ export default {
preventCleanupDisableError: 'An error occurred while disabling version cleanup for %0%',
copySuccessMessage: 'Your system information has successfully been copied to the clipboard',
cannotCopyInformation: 'Could not copy your system information to the clipboard',
offlineHeadline: 'Offline',
offlineMessage: 'You are currently offline. Please check your internet connection.',
},
stylesheet: {
addRule: 'Add style',