From 4cb68488b768fe2a00fd14ef80687e839455fb5c Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Tue, 3 Aug 2021 19:14:46 +0200 Subject: [PATCH] feature: add logo favicon and progress favicon in logo color Signed-off-by: Stefan Dej --- src/App.vue | 150 ++++++++++-------- .../panels/Machine/ConfigFilesPanel.vue | 8 +- src/store/files/getters.ts | 6 +- src/store/printer/getters.ts | 2 +- 4 files changed, 95 insertions(+), 71 deletions(-) diff --git a/src/App.vue b/src/App.vue index 2db0648f..996a773d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,11 +40,12 @@ import Component from 'vue-class-component' import TheSidebar from "@/components/TheSidebar.vue"; import BaseMixin from "@/components/mixins/base"; import TheTopbar from "@/components/TheTopbar.vue"; -import {Mixins,Watch} from "vue-property-decorator"; +import {Mixins, Vue, Watch} from "vue-property-decorator"; import TheUpdateDialog from "@/components/TheUpdateDialog.vue"; import TheConnectingDialog from "@/components/TheConnectingDialog.vue"; import TheSelectPrinterDialog from "@/components/TheSelectPrinterDialog.vue"; import TheEditor from "@/components/TheEditor.vue"; +import MainsailLogo from "@/components/ui/MainsailLogo.vue"; @Component({ components: { @@ -74,6 +75,10 @@ export default class App extends Mixins(BaseMixin) { return this.$store.getters["files/getCustomStylesheet"] } + get customFavicons () { + return this.$store.getters["files/getCustomFavicons"] ?? null + } + get language () { return this.$store.state.gui.general.language } @@ -82,6 +87,10 @@ export default class App extends Mixins(BaseMixin) { return this.$store.state.printer.print_stats?.filename ?? "" } + get logoColor () { + return this.$store.state.gui.theme.logo + } + get primaryColor () { return this.$store.state.gui.theme.primary } @@ -106,6 +115,10 @@ export default class App extends Mixins(BaseMixin) { } } + get print_percent () { + return Math.round(this.$store.getters["printer/getPrintPercent"] * 100) + } + @Watch('language') languageChanged(newVal: string) { this.$i18n.locale = newVal; @@ -137,78 +150,91 @@ export default class App extends Mixins(BaseMixin) { this.$vuetify.theme.currentTheme.primary = newVal }) } -} -/*export default Vue.extend({ - computed: { - print_percent () { - return this.$store.getters["printer/getPrintPercent"] - }, - defaultFavicons () { - return this.$store.getters["files/getFavicons"] - }, - }, - methods: { - /!*drawFavicon(val: number) { - const favicon16 = document.querySelector("link[rel*='icon'][sizes='16x16']") - const favicon32 = document.querySelector("link[rel*='icon'][sizes='32x32']") + drawFavicon(val: number) { + const favicon16: HTMLLinkElement | null = document.querySelector("link[rel*='icon'][sizes='16x16']") + const favicon32: HTMLLinkElement | null = document.querySelector("link[rel*='icon'][sizes='32x32']") - if (val > 0 && val < 100 && favicon16 && favicon32) { + if (favicon16 && favicon32) { + if (this.printerIsPrinting) { let faviconSize = 64; - let canvas = document.createElement('canvas'); - canvas.width = faviconSize; - canvas.height = faviconSize; - const context = canvas.getContext('2d'); - let centerX = canvas.width / 2; - let centerY = canvas.height / 2; - let radius = 32; - let percent = (val * 100).toFixed(0); + let canvas = document.createElement('canvas') + canvas.width = faviconSize + canvas.height = faviconSize + const context = canvas.getContext('2d') + const centerX = canvas.width / 2 + const centerY = canvas.height / 2 + const radius = 32 - /!* draw the grey circle *!/ + // draw the grey circle if (context) { - context.beginPath(); - context.moveTo(centerX, centerY); - context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false); - context.closePath(); - context.fillStyle = "#ddd"; - context.fill(); - context.strokeStyle = "rgba(200, 208, 218, 0.66)"; - context.stroke(); + context.beginPath() + context.moveTo(centerX, centerY) + context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false) + context.closePath() + context.fillStyle = "#ddd" + context.fill() + context.strokeStyle = "rgba(200, 208, 218, 0.66)" + context.stroke() - /!* draw the green circle based on percentage *!/ - let startAngle = 1.5 * Math.PI; - let endAngle = 0; - let unitValue = (Math.PI - 0.5 * Math.PI) / 25; - if (percent >= 0 && percent <= 25) endAngle = startAngle + (percent * unitValue); - else if (percent > 25 && percent <= 50) endAngle = startAngle + (percent * unitValue); - else if (percent > 50 && percent <= 75) endAngle = startAngle + (percent * unitValue); - else if (percent > 75 && percent <= 100) endAngle = startAngle + (percent * unitValue); + // draw the green circle based on percentage + let startAngle = 1.5 * Math.PI + let endAngle = 0 + let unitValue = (Math.PI - 0.5 * Math.PI) / 25 + if (val >= 0 && val <= 25) endAngle = startAngle + (val * unitValue) + else if (val > 25 && val <= 50) endAngle = startAngle + (val * unitValue) + else if (val > 50 && val <= 75) endAngle = startAngle + (val * unitValue) + else if (val > 75 && val <= 100) endAngle = startAngle + (val * unitValue) - context.beginPath(); - context.moveTo(centerX, centerY); - context.arc(centerX, centerY, radius, startAngle, endAngle, false); - context.closePath(); - context.fillStyle = "#e41313"; - context.fill(); + context.beginPath() + context.moveTo(centerX, centerY) + context.arc(centerX, centerY, radius, startAngle, endAngle, false) + context.closePath() + context.fillStyle = this.logoColor + context.fill() favicon16.href = canvas.toDataURL('image/png') favicon32.href = canvas.toDataURL('image/png') } - } else if (favicon16 && favicon32) { - const [favicon16Default, favicon32Default] = this.defaultFavicons - favicon16.href = favicon16Default - favicon32.href = favicon32Default + } else if (this.customFavicons) { + const [favicon16Path, favicon32Path] = this.customFavicons + favicon16.href = favicon16Path + favicon32.href = favicon32Path + } else { + const favicon = 'data:image/svg+xml;base64,' + btoa( + '' + + '' + + '' + + '' + + '' + + '' + + '' + ) + + favicon16.href = favicon + favicon32.href = favicon } - },*!/ - }, - watch: { - /!*print_percent() { - this.drawFavicon(this.print_percent); - }, - defaultFavicons() { - this.drawFavicon(this.print_percent); - }*!/ - }, -})*/ + } + } + + @Watch('customFavicons') + customFaviconsChanged() { + this.drawFavicon(this.print_percent) + } + + @Watch('logoColor') + logoColorChanged() { + this.drawFavicon(this.print_percent) + } + + @Watch('print_percent') + print_percentChanged(newVal: number) { + this.drawFavicon(newVal) + } + + mounted() { + this.drawFavicon(this.print_percent) + } +} diff --git a/src/components/panels/Machine/ConfigFilesPanel.vue b/src/components/panels/Machine/ConfigFilesPanel.vue index 69bcf3aa..eb74c44f 100644 --- a/src/components/panels/Machine/ConfigFilesPanel.vue +++ b/src/components/panels/Machine/ConfigFilesPanel.vue @@ -618,8 +618,8 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { renameDirectoryAction() { this.dialogRenameDirectory.show = false; this.$socket.emit('server.files.move', { - source: this.absolutePath+"/"+this.dialogRenameDirectory.item.filename, - dest: this.absolutePath+"/"+this.dialogRenameDirectory.newName + source: (this.absolutePath+"/"+this.dialogRenameDirectory.item.filename).slice(1), + dest: (this.absolutePath+"/"+this.dialogRenameDirectory.newName).slice(1) }, { action: 'files/getMove' }); } @@ -668,8 +668,8 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { renameFileAction() { this.dialogRenameFile.show = false this.$socket.emit('server.files.move', { - source: this.absolutePath+"/"+this.dialogRenameFile.item.filename, - dest: this.absolutePath+"/"+this.dialogRenameFile.newName + source: (this.absolutePath+"/"+this.dialogRenameFile.item.filename).slice(1), + dest: (this.absolutePath+"/"+this.dialogRenameFile.newName).slice(1), }, { action: 'files/getMove' }) } diff --git a/src/store/files/getters.ts b/src/store/files/getters.ts index eaa7eb0d..1dbf7eee 100644 --- a/src/store/files/getters.ts +++ b/src/store/files/getters.ts @@ -45,21 +45,19 @@ export const getters: GetterTree = { return getters['getThemeFileUrl'](acceptName, acceptExtensions) ?? null }, - getFavicons: (state, getters, rootState, rootGetters) => { + getCustomFavicons: (state, getters) => { const acceptName16 = "favicon-32x32" const acceptName32 = "favicon-32x32" const acceptExtensions = ['png', 'svg'] const favicon16 = getters['getThemeFileUrl'](acceptName16, acceptExtensions) - const favicon16Default = '/img/icons/favicon-16x16.png' const favicon32 = getters['getThemeFileUrl'](acceptName32, acceptExtensions) - const favicon32Default = '/img/icons/favicon-32x32.png' if (favicon16 && favicon32) return [favicon16, favicon32] else if (favicon16) return [favicon16, favicon16] else if (favicon32) return [favicon32, favicon32] - return [favicon16Default, favicon32Default] + return null }, getDiskUsage: (state) => (path: string) => { diff --git a/src/store/printer/getters.ts b/src/store/printer/getters.ts index 9a8a4cb7..c65f93b0 100644 --- a/src/store/printer/getters.ts +++ b/src/store/printer/getters.ts @@ -28,7 +28,7 @@ export const getters: GetterTree = { if (currentPosition > 0 && maxPosition > 0) return 1 / maxPosition * currentPosition; } - return state.virtual_sdcard.progress + return state.virtual_sdcard?.progress ?? 0 }, getPositions: (state) => {