Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add warning for outdated browsers #1537

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"axios": "^0.27.0",
"codemirror": "^6.0.1",
"core-js": "^3.16.0",
"detect-browser": "^5.3.0",
"echarts": "^5.2.2",
"echarts-gl": "^2.0.8",
"hls.js": "^1.3.3",
Expand Down
4 changes: 4 additions & 0 deletions src/locales/de.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"App": {
"Notifications": {
"BrowserWarnings": {
"Headline": "Veralteter Browser",
"Description": "Die verwendete {name} Version ({version}) ist veraltet und wird nicht vollständig unterstützt. Mainsail benötigt die Version {minVersion} oder höher."
},
"DependencyDescription": "Die momentane {name} Version unterstützt nicht alle Funktionen von Mainsail. Aktualisiere {name} mindestens auf Version {neededVersion}.",
"DependencyName": "Abhängigkeit: {name}",
"DismissAll": "Alles verwerfen",
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"App": {
"Notifications": {
"BrowserWarnings": {
"Headline": "Outdated Browser",
"Description": "{name} is outdated and not fully supported. The current version is {version}, but Mainsail requires version {minVersion} or higher."
},
"DependencyDescription": "The current {name} version does not support all features of Mainsail. Update {name} to at least {neededVersion}.",
"DependencyName": "Dependency: {name}",
"DismissAll": "Dismiss all",
Expand Down
52 changes: 51 additions & 1 deletion src/store/gui/notifications/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import i18n from '@/plugins/i18n.js'
import { RootStateDependency } from '@/store/types'
import { sha256 } from 'js-sha256'
import { PrinterStateKlipperConfigWarning } from '@/store/printer/types'
import { detect } from 'detect-browser'
import semver from 'semver'
import { minBrowserVersions } from '@/store/variables'

export const getters: GetterTree<GuiNotificationState, any> = {
getNotifications: (state, getters) => {
Expand All @@ -22,12 +25,15 @@ export const getters: GetterTree<GuiNotificationState, any> = {
// moonraker warnings
notifications = notifications.concat(getters['getNotificationsMoonrakerWarnings'])

// moonraker failed compontents
// moonraker failed components
notifications = notifications.concat(getters['getNotificationsMoonrakerFailedComponents'])

// klipper warnings
notifications = notifications.concat(getters['getNotificationsKlipperWarnings'])

// browser warnings
notifications = notifications.concat(getters['getNotificationsBrowserWarnings'])

const mapType = {
normal: 2,
high: 1,
Expand Down Expand Up @@ -270,6 +276,50 @@ export const getters: GetterTree<GuiNotificationState, any> = {
return notifications
},

getNotificationsBrowserWarnings: (state, getters, rootState) => {
const notifications: GuiNotificationStateEntry[] = []

const browser = detect()
const date = rootState.server.system_boot_at ?? new Date()

// stop here, because no browser detected
if (browser === null) return notifications

// output browser information to console
window.console.debug(`Browser: ${browser.name} ${browser.version}, OS: ${browser.os}`)

// find browser requirement
const minBrowserVersion = minBrowserVersions.find(
(entry) => entry.name.toLowerCase() === browser.name.toLowerCase()
)

// stop here, because no browser requirement found
if (minBrowserVersion === undefined) return notifications

if (
semver.valid(browser.version) &&
semver.valid(minBrowserVersion.version) &&
semver.gt(minBrowserVersion.version, browser.version ?? '0.0.0')
) {
notifications.push({
id: `browserWarning/${minBrowserVersion.name}/${minBrowserVersion.version}`,
priority: 'critical',
title: i18n.t('App.Notifications.BrowserWarnings.Headline').toString(),
description: i18n
.t('App.Notifications.BrowserWarnings.Description', {
name: minBrowserVersion.name,
version: browser.version,
minVersion: minBrowserVersion.version,
})
.toString(),
date,
dismissed: false,
} as GuiNotificationStateEntry)
}

return notifications
},

getDismiss: (state, getters, rootState) => {
const currentTime = new Date()
const systemBootAt = rootState.server.system_boot_at ?? new Date()
Expand Down
1 change: 1 addition & 0 deletions src/store/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const defaultPrimaryColor = '#2196f3'

export const minKlipperVersion = 'v0.11.0-97'
export const minMoonrakerVersion = 'v0.8.0-38'
export const minBrowserVersions = [{ name: 'safari', version: '16.5.2' }]

export const colorArray = ['#F44336', '#8e379d', '#03DAC5', '#3F51B5', '#ffde03', '#009688', '#E91E63']

Expand Down