Skip to content

Commit ddbb8a7

Browse files
committed
feat: download bed mesh image
Signed-off-by: Pedro Lamas <[email protected]>
1 parent 2f9eaf0 commit ddbb8a7

File tree

22 files changed

+48
-68
lines changed

22 files changed

+48
-68
lines changed

src/components/settings/GeneralSettings.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,9 @@ import { readFileAsTextAsync } from '@/util/file-system-entry'
285285
import { EventBus } from '@/eventBus'
286286
import { isFluiddContent, toFluiddContent } from '@/util/fluidd-content'
287287
import { getAllLocales } from '@/plugins/i18n'
288+
import downloadUrl from '@/util/download-url'
288289
289-
@Component({
290-
components: {}
291-
})
290+
@Component({})
292291
export default class GeneralSettings extends Mixins(StateMixin) {
293292
@Ref('instanceName')
294293
readonly instanceNameElement!: VInput
@@ -630,17 +629,10 @@ export default class GeneralSettings extends Mixins(StateMixin) {
630629
const backupData = toFluiddContent('settings-backup', data)
631630
const backupDataAsString = JSON.stringify(backupData)
632631
633-
const link = document.createElement('a')
632+
const filename = `backup-fluidd-v${import.meta.env.VERSION}-${this.instanceName}.json`
633+
const url = `data:text/plain;charset=utf-8,${encodeURIComponent(backupDataAsString)}`
634634
635-
link.href = `data:text/plain;charset=utf-8,${encodeURIComponent(backupDataAsString)}`
636-
link.download = `backup-fluidd-v${import.meta.env.VERSION}-${this.instanceName}.json`
637-
link.target = '_blank'
638-
639-
document.body.appendChild(link)
640-
641-
link.click()
642-
643-
document.body.removeChild(link)
635+
downloadUrl(filename, url)
644636
}
645637
} catch (e) {
646638
consola.error('[Settings] backup failed', e)

src/components/widgets/bedmesh/BedMeshCard.vue

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,21 @@
1919
{{ $t('app.general.btn.calibrate') }}
2020
</app-btn>
2121

22-
<v-tooltip
23-
v-if="canCopyImage"
24-
bottom
25-
>
22+
<v-tooltip bottom>
2623
<template #activator="{ on, attrs }">
2724
<app-btn
2825
v-bind="attrs"
2926
icon
3027
:disabled="!hasMeshLoaded"
3128
v-on="on"
32-
@click="copyImage()"
29+
@click="downloadImage()"
3330
>
3431
<v-icon dense>
3532
$screenshot
3633
</v-icon>
3734
</app-btn>
3835
</template>
39-
<span>{{ $t('app.bedmesh.tooltip.copy_image') }}</span>
36+
<span>{{ $t('app.bedmesh.tooltip.download_image') }}</span>
4037
</v-tooltip>
4138

4239
<app-btn
@@ -228,16 +225,8 @@ export default class BedMeshCard extends Mixins(StateMixin, ToolheadMixin, Brows
228225
return this.$typedGetters['mesh/getCurrentMeshData']
229226
}
230227
231-
get canCopyImage () {
232-
return (
233-
typeof navigator.clipboard === 'object' &&
234-
typeof navigator.clipboard.write === 'function' &&
235-
typeof ClipboardItem === 'function'
236-
)
237-
}
238-
239-
copyImage () {
240-
this.bedMeshChart.copyImage()
228+
downloadImage () {
229+
this.bedMeshChart.downloadImage()
241230
}
242231
}
243232
</script>

src/components/widgets/bedmesh/BedMeshChart.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { ECharts, EChartsOption, GraphicComponentOption } from 'echarts'
2525
import { merge, cloneDeepWith } from 'lodash-es'
2626
import BrowserMixin from '@/mixins/browser'
2727
import type { BedSize } from '@/store/printer/types'
28+
import downloadUrl from '@/util/download-url'
2829
2930
@Component({})
3031
export default class BedMeshChart extends Mixins(BrowserMixin) {
@@ -241,16 +242,18 @@ export default class BedMeshChart extends Mixins(BrowserMixin) {
241242
return opts
242243
}
243244
244-
async copyImage () {
245-
const image = await fetch(this.chart.getDataURL({ type: 'png', backgroundColor: '#262629' }))
246-
247-
const blob = await image.blob()
245+
async downloadImage () {
246+
const url = this.chart.getDataURL({
247+
type: 'png',
248+
backgroundColor: '#262629'
249+
})
248250
249-
const data = [
250-
new ClipboardItem({ 'image/png': blob })
251-
]
251+
const filename = [
252+
'bedmesh',
253+
this.$typedState.printer.printer.bed_mesh?.profile_name
254+
].filter(x => x).join('-')
252255
253-
await navigator.clipboard.write(data)
256+
downloadUrl(filename, url)
254257
}
255258
}
256259
</script>

src/locales/de.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ app:
2222
delete: Profil löschen
2323
load: Profil laden
2424
save: Fügt das Mesh Profil der printer.cfg hinzu
25-
copy_image: Bett-Mesh-Abbildung kopieren
2625
chart:
2726
label:
2827
current: Aktuell

src/locales/en.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ app:
2222
delete: Delete Profile
2323
load: Load Profile
2424
save: Commits calibrated profile to printer.cfg
25-
copy_image: Copy bed mesh image
25+
download_image: Download bed mesh image
2626
chart:
2727
label:
2828
current: Actual

src/locales/es.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ app:
2222
delete: Elimina el perfil
2323
load: Cargar el perfil
2424
save: Guarda el perfil de calibracion en el archivo printer.cfg
25-
copy_image: Copiar imagen de la malla de cama
2625
chart:
2726
label:
2827
current:

src/locales/fr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ app:
2424
delete: Supprime le profil
2525
load: Charger le profil
2626
save: Enregistrer le profil calibré dans 'printer.cfg'
27-
copy_image: Copier l'image du bed mesh
2827
chart:
2928
label:
3029
current: Courant

src/locales/hu.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ app:
2222
delete: Profil törlése
2323
load: Profil betöltése
2424
save: A kalibrált profil a printer.cfg fájlba íródik
25-
copy_image: Ágyhálós kép másolása
2625
chart:
2726
label:
2827
current: Aktuális

src/locales/it.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ app:
2222
delete: Elimina profilo
2323
load: Carica profilo
2424
save: Salva il profilo calibrato in printer.cfg
25-
copy_image: Copia immagine mesh
2625
chart:
2726
label:
2827
current: Effettivo

src/locales/ja.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ app:
2828
not_loaded: メッシュを読込しない
2929
tooltip:
3030
calibrate: 新しいキャリブレーションを開始し、プロファイル'default'として保存します
31-
copy_image: ベッドメッシュ画像をコピー
3231
delete: プロファイルを削除します。
3332
load: プロファイルを読込み
3433
save: キャリブレーションされたプロファイルをprinter.cfgに書込みします。

0 commit comments

Comments
 (0)