Skip to content

feat: download bed mesh image #1656

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

Merged
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
18 changes: 5 additions & 13 deletions src/components/settings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ import { readFileAsTextAsync } from '@/util/file-system-entry'
import { EventBus } from '@/eventBus'
import { isFluiddContent, toFluiddContent } from '@/util/fluidd-content'
import { getAllLocales } from '@/plugins/i18n'
import downloadUrl from '@/util/download-url'

@Component({
components: {}
})
@Component({})
export default class GeneralSettings extends Mixins(StateMixin) {
@Ref('instanceName')
readonly instanceNameElement!: VInput
Expand Down Expand Up @@ -630,17 +629,10 @@ export default class GeneralSettings extends Mixins(StateMixin) {
const backupData = toFluiddContent('settings-backup', data)
const backupDataAsString = JSON.stringify(backupData)

const link = document.createElement('a')
const filename = `backup-fluidd-v${import.meta.env.VERSION}-${this.instanceName}.json`
const url = `data:text/plain;charset=utf-8,${encodeURIComponent(backupDataAsString)}`

link.href = `data:text/plain;charset=utf-8,${encodeURIComponent(backupDataAsString)}`
link.download = `backup-fluidd-v${import.meta.env.VERSION}-${this.instanceName}.json`
link.target = '_blank'

document.body.appendChild(link)

link.click()

document.body.removeChild(link)
downloadUrl(filename, url)
}
} catch (e) {
consola.error('[Settings] backup failed', e)
Expand Down
21 changes: 5 additions & 16 deletions src/components/widgets/bedmesh/BedMeshCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@
{{ $t('app.general.btn.calibrate') }}
</app-btn>

<v-tooltip
v-if="canCopyImage"
bottom
>
<v-tooltip bottom>
<template #activator="{ on, attrs }">
<app-btn
v-bind="attrs"
icon
:disabled="!hasMeshLoaded"
v-on="on"
@click="copyImage()"
@click="downloadImage()"
>
<v-icon dense>
$screenshot
</v-icon>
</app-btn>
</template>
<span>{{ $t('app.bedmesh.tooltip.copy_image') }}</span>
<span>{{ $t('app.bedmesh.tooltip.download_image') }}</span>
</v-tooltip>

<app-btn
Expand Down Expand Up @@ -228,16 +225,8 @@ export default class BedMeshCard extends Mixins(StateMixin, ToolheadMixin, Brows
return this.$typedGetters['mesh/getCurrentMeshData']
}

get canCopyImage () {
return (
typeof navigator.clipboard === 'object' &&
typeof navigator.clipboard.write === 'function' &&
typeof ClipboardItem === 'function'
)
}

copyImage () {
this.bedMeshChart.copyImage()
downloadImage () {
this.bedMeshChart.downloadImage()
}
}
</script>
19 changes: 11 additions & 8 deletions src/components/widgets/bedmesh/BedMeshChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { ECharts, EChartsOption, GraphicComponentOption } from 'echarts'
import { merge, cloneDeepWith } from 'lodash-es'
import BrowserMixin from '@/mixins/browser'
import type { BedSize } from '@/store/printer/types'
import downloadUrl from '@/util/download-url'

@Component({})
export default class BedMeshChart extends Mixins(BrowserMixin) {
Expand Down Expand Up @@ -241,16 +242,18 @@ export default class BedMeshChart extends Mixins(BrowserMixin) {
return opts
}

async copyImage () {
const image = await fetch(this.chart.getDataURL({ type: 'png', backgroundColor: '#262629' }))

const blob = await image.blob()
async downloadImage () {
const url = this.chart.getDataURL({
type: 'png',
backgroundColor: '#262629'
})

const data = [
new ClipboardItem({ 'image/png': blob })
]
const filename = [
'bedmesh',
this.$typedState.printer.printer.bed_mesh?.profile_name
].filter(x => x).join('-')

await navigator.clipboard.write(data)
downloadUrl(filename, url)
}
}
</script>
Expand Down
1 change: 0 additions & 1 deletion src/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Profil löschen
load: Profil laden
save: Fügt das Mesh Profil der printer.cfg hinzu
copy_image: Bett-Mesh-Abbildung kopieren
chart:
label:
current: Aktuell
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ app:
delete: Delete Profile
load: Load Profile
save: Commits calibrated profile to printer.cfg
copy_image: Copy bed mesh image
download_image: Download bed mesh image
chart:
label:
current: Actual
Expand Down
1 change: 0 additions & 1 deletion src/locales/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Elimina el perfil
load: Cargar el perfil
save: Guarda el perfil de calibracion en el archivo printer.cfg
copy_image: Copiar imagen de la malla de cama
chart:
label:
current: Tª
Expand Down
1 change: 0 additions & 1 deletion src/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ app:
delete: Supprime le profil
load: Charger le profil
save: Enregistrer le profil calibré dans 'printer.cfg'
copy_image: Copier l'image du bed mesh
chart:
label:
current: Courant
Expand Down
1 change: 0 additions & 1 deletion src/locales/hu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Profil törlése
load: Profil betöltése
save: A kalibrált profil a printer.cfg fájlba íródik
copy_image: Ágyhálós kép másolása
chart:
label:
current: Aktuális
Expand Down
1 change: 0 additions & 1 deletion src/locales/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Elimina profilo
load: Carica profilo
save: Salva il profilo calibrato in printer.cfg
copy_image: Copia immagine mesh
chart:
label:
current: Effettivo
Expand Down
1 change: 0 additions & 1 deletion src/locales/ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ app:
not_loaded: メッシュを読込しない
tooltip:
calibrate: 新しいキャリブレーションを開始し、プロファイル'default'として保存します
copy_image: ベッドメッシュ画像をコピー
delete: プロファイルを削除します。
load: プロファイルを読込み
save: キャリブレーションされたプロファイルをprinter.cfgに書込みします。
Expand Down
1 change: 0 additions & 1 deletion src/locales/ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ app:
delete: 프로파일을 삭제합니다
load: 프로파일 불러오기
save: 캘리브레이션이 된 프로파일을 printer.cfg에 적용합니다
copy_image: 베드 메쉬 이미지 복사
chart:
label:
current: 현재 온도
Expand Down
1 change: 0 additions & 1 deletion src/locales/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Verwijder profiel
load: Laad profiel
save: Slaat afgesteld profiel op naar printer.cfg
copy_image: Kopieer bed mesh afbeelding
chart:
label:
current: Huidig
Expand Down
1 change: 0 additions & 1 deletion src/locales/pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ app:
delete: Usuń profil
load: Wczytaj profil
save: Zapisuje skalibrowany profil do pliku printer.cfg
copy_image: Skopiuj obraz siatki stołu
chart:
label:
current: Aktualnie
Expand Down
1 change: 0 additions & 1 deletion src/locales/pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Eliminar perfil
load: Carregar perfil
save: Guard perfil calibrado no ficheiro printer.cfg
copy_image: Copiar imagem da malha da cama
chart:
label:
current: Corrente
Expand Down
1 change: 0 additions & 1 deletion src/locales/pt_BR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ app:
not_loaded: Nenhuma malha carregada
tooltip:
load: Carregar perfil
copy_image: Copiar imagem da malha da cama
calibrate: Começa uma nova calibração, salvando o perfil como 'default'
delete: Apagar perfil
save: Salva perfil calibrado no arquivo printer.cfg
Expand Down
1 change: 0 additions & 1 deletion src/locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Удалить профиль
load: Загрузить профиль
save: Сохранить данные откалиброванного профиля в printer.cfg
copy_image: Скопировать изображение сетки кровати
chart:
label:
current: Текущая
Expand Down
1 change: 0 additions & 1 deletion src/locales/sl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Zbriši profil
load: Naloži profil
save: Shrani kalibriran profil v printer.cfg.
copy_image: Kopiraj sliko posteljne mreže
chart:
label:
current: Dejansko
Expand Down
1 change: 0 additions & 1 deletion src/locales/ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ app:
என்று சேமிக்கிறது
delete: சுயவிவரத்தை நீக்கு
load: சுயவிவரத்தை ஏற்றவும்
copy_image: படுக்கை கண்ணி படத்தை நகலெடுக்கவும்
label:
active: செயலில்
base: காரம்
Expand Down
1 change: 0 additions & 1 deletion src/locales/tr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ app:
delete: Profili Sil
load: Profil Yükle
save: Kalibre edilmiş profili printer.cfg'ye kaydeder
copy_image: Yatak örgüsü görüntüsünü kopyala
chart:
label:
current: Gerçek
Expand Down
1 change: 0 additions & 1 deletion src/locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app:
delete: Видалити профіль
load: Завантажити профіль
save: Зберегти калібрований профіль в printer.cfg
copy_image: Скопіюйте сітчасте зображення ліжка
chart:
label:
current: Поточне значення
Expand Down
18 changes: 4 additions & 14 deletions src/mixins/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { FileWithPath } from '@/types'
import { consola } from 'consola'
import { v4 as uuidv4 } from 'uuid'
import type { AppUser } from '@/store/auth/types'
import downloadUrl from '@/util/download-url'

@Component
export default class FilesMixin extends Vue {
Expand Down Expand Up @@ -147,20 +148,9 @@ export default class FilesMixin extends Vue {
*/
async downloadFile (filename: string, path: string) {
// Grab a oneshot.
try {
const url = await this.createFileUrlWithToken(filename, path)

// Create a link, handle its click - and finally remove it again.
const link = document.createElement('a')
link.href = url
link.setAttribute('download', filename)
link.setAttribute('target', '_blank')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} catch {
// Likely a 401.
}
const url = await this.createFileUrlWithToken(filename, path)

downloadUrl(filename, url)
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/util/download-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { consola } from 'consola'

const downloadUrl = (filename: string, url: string) => {
try {
// Create a link, handle its click - and finally remove it again.
const link = document.createElement('a')

link.href = url
link.download = filename
link.target = '_blank'

document.body.appendChild(link)

link.click()

document.body.removeChild(link)
} catch (error) {
consola.error('[DownloadUrl] error', error)
}
}

export default downloadUrl