diff --git a/.dockerignore b/.dockerignore index 7605079..30358b3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,4 @@ node_modules docs scripts src-tauri/target -build \ No newline at end of file +build diff --git a/.prettierignore b/.prettierignore index 3897265..a573fbb 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,7 @@ node_modules .env .env.* !.env.example +/src-tauri/target # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml diff --git a/Dockerfile b/Dockerfile index 5d904a8..98151c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y #COPY package*.json ./ -#RUN npm install && npm install --save-dev @tauri-apps/cli +#RUN npm install && npm install --save-dev @tauri-apps/cli #COPY . . @@ -26,6 +26,6 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y #VOLUME [ "/app/src-tauri/target/release/bundle/deb/" ] VOLUME [ "/app"] -CMD npm install && npm install --save-dev @tauri-apps/cli && npm run tauri build +CMD npm install && npm install --save-dev @tauri-apps/cli && npm run tauri build #CMD npm run tauri build diff --git a/README.md b/README.md index 63553de..3c1163b 100644 --- a/README.md +++ b/README.md @@ -83,14 +83,14 @@ And yes, help and improve if you find something. - To use another url, use the commandline parameters - ```bash + ``` -h eg. `http://192.168.1.1/` -w eg. `ws://192.168.1.1/websocket` ``` - To start in fullscreen mode - ```bash + ``` -f ``` diff --git a/src/lib/commons/Values.ts b/src/lib/commons/Values.ts index d9365f3..922dd80 100644 --- a/src/lib/commons/Values.ts +++ b/src/lib/commons/Values.ts @@ -15,6 +15,8 @@ export class Values { public stepsBaby = writable(0.05); public stepsExtrusion = writable(10); public stepsExtrusionSpeed = writable(3); + public fileMetadata = writable(null); + public largestAbsoluteThumbnailPath = writable(''); public constructor(moonrakerClient: MoonrakerClient) { // super(); @@ -23,13 +25,14 @@ export class Values { this.clock = this.createClock(); } - public async getFileMetadata(filename: string): Promise { + public async getFileMetadata(relativeFilename: string): Promise { const requestMetadata = new JsonRpcRequest({ method: 'server.files.metadata', params: { - filename: filename + filename: relativeFilename } }); + const response = await client.sendRequest(requestMetadata); let metadata: IFileMetadata | null = null; @@ -42,6 +45,26 @@ export class Values { return metadata; } + public async getThumbnails(relativeFilename: string): Promise { + const request = new JsonRpcRequest({ + method: 'server.files.thumbnails', + params: { + filename: relativeFilename + } + }); + + const response = await client.sendRequest(request); + let thumbnails: IThumbnail[] | null = null; + + if (response.error === undefined) { + thumbnails = response.result as IThumbnail[]; + } else { + console.warn('getThumbnails.response.error: ', response.error); + } + + return thumbnails; + } + public async getLargestAbsoluteThumbnailPath(moonrakerApi: URL, thumbnails: IThumbnail[]): Promise { let path = ''; diff --git a/src/lib/moonraker/MoonrakerClient.ts b/src/lib/moonraker/MoonrakerClient.ts index da8f960..732a8ad 100644 --- a/src/lib/moonraker/MoonrakerClient.ts +++ b/src/lib/moonraker/MoonrakerClient.ts @@ -283,13 +283,14 @@ export class MoonrakerClient extends EventTarget { } if (print_stats.info !== undefined) { const info = print_stats.info; - if (info?.current_layer !== undefined) { + if (info.current_layer !== undefined) { + // console.log('print_stats.info: ', print_stats.info); // console.log('print_stats.info.current_layer: ', print_stats.info?.current_layer); - this.printStats.Info.CurrentLayer.set(info?.current_layer); + this.printStats.Info.CurrentLayer.set(info.current_layer); } - if (info?.total_layer !== undefined) { + if (info.total_layer !== undefined) { // console.log('print_stats.info.total_layer: ', print_stats.info?.total_layer); - this.printStats.Info.TotalLayer.set(info?.total_layer); + this.printStats.Info.TotalLayer.set(info.total_layer); } } } diff --git a/src/lib/moonraker/modules/PrintStats.ts b/src/lib/moonraker/modules/PrintStats.ts index a277784..29c9f5e 100644 --- a/src/lib/moonraker/modules/PrintStats.ts +++ b/src/lib/moonraker/modules/PrintStats.ts @@ -11,6 +11,6 @@ export class PrintStats { } export class Info { - public TotalLayer = writable(0); - public CurrentLayer = writable(0); + public TotalLayer = writable(null); + public CurrentLayer = writable(null); } diff --git a/src/lib/moonraker/types/IFileMetadata.ts b/src/lib/moonraker/types/IFileMetadata.ts index 4b5ac03..35d8387 100644 --- a/src/lib/moonraker/types/IFileMetadata.ts +++ b/src/lib/moonraker/types/IFileMetadata.ts @@ -1,21 +1,27 @@ import type { IThumbnail } from './IThumbnail'; export interface IFileMetadata { - print_start_time: null; - job_id: null; - size: number; - modified: number; - slicer: string; - slicer_version: string; - layer_height: number; - first_layer_height: number; - object_height: number; - filament_total: number; - estimated_time: number; thumbnails: IThumbnail[]; - first_layer_bed_temp: number; - first_layer_extr_temp: number; - gcode_start_byte: number; - gcode_end_byte: number; - filename: string; + estimated_time: number; // 12771 + filament_name: string; // "Geeetech PLA N0.4" + filament_total: number; // 19084 + filament_type: string; // "PLA" + filament_weight_total: number; // 56.96 + filename: string; // "swx2-led-light v8_prusa_PLA_L0.2_F0.97_S80.gcode" + first_layer_bed_temp: number; // 65 + first_layer_extr_temp: number; // 210 + first_layer_height: number; // 0.2 + gcode_end_byte: number; //6482519 + gcode_start_byte: number; // 67056 + job_id: string; // "000088" + layer_count: number; // 85 + layer_height: number; // 0.2 + modified: number; // 1701163957.4757094 + nozzle_diameter: number; // 0.4 + object_height: number; // 17 + print_start_time: number; // 1701269472.5509927 + size: number; // 6494120 + slicer: string; // "PrusaSlicer" + slicer_version: string; // "2.7.0+win64" + uuid: string; // "7cfa8f87-13e4-4578-9ac7-e79296a2b279" } diff --git a/src/lib/moonraker/types/INotifyStatusUpdateParams.ts b/src/lib/moonraker/types/INotifyStatusUpdateParams.ts index a2f7a5c..786682a 100644 --- a/src/lib/moonraker/types/INotifyStatusUpdateParams.ts +++ b/src/lib/moonraker/types/INotifyStatusUpdateParams.ts @@ -21,5 +21,5 @@ export interface INotifyStatusUpdateParams { display_status: IProgress; motion_report: IMotionReport; configfile: IConfigFile; - quadGantryLevel: IQuadGantryLevel + quadGantryLevel: IQuadGantryLevel; } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 48cfd8a..5f3de1f 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,7 +1,7 @@
diff --git a/src/routes/printstate/+page.svelte b/src/routes/printstate/+page.svelte index b1bc197..f43d2f2 100644 --- a/src/routes/printstate/+page.svelte +++ b/src/routes/printstate/+page.svelte @@ -3,8 +3,6 @@ import BottomNavigation from '$lib/BottomNavigation.svelte'; import StatusLine from '$lib/StatusLine.svelte'; - let moonrakerApi = bootParams.moonrakerApi; - let maxAcceleration = moonraker.toolhead.MaxAcceleration; let toolheadPosition = moonraker.motionReport.LivePosition; let nozzleTemp = moonraker.extruder.Temperature; @@ -19,59 +17,51 @@ let speedFactor = moonraker.gcodeMove.SpeedFactor; let extrudeFactor = moonraker.gcodeMove.ExtrudeFactor; + // let printStatsState = writable('standby'); let printStatsState = moonraker.printStats.State; let printStatsFilename = moonraker.printStats.Filename; let printStatsPrintDuration = moonraker.printStats.PrintDuration; let filamentUsed = moonraker.printStats.FilamentUsed; let currentLayer = moonraker.printStats.Info.CurrentLayer; let totalLayer = moonraker.printStats.Info.TotalLayer; - + let fileMeta = values.fileMetadata; let clockFormatter = values.clockFormatter; - let progress = moonraker.displayStatus.Progress; - let selectedFile = ''; - let selectedFileThumbnailPath = ''; - let remainingDuration = 0; + let selectedFileThumbnailPath = values.largestAbsoluteThumbnailPath; + let dynamicRemainingTime = 0; + let dynamicEta = ''; let filamentTotal = 0; - let estimatedTime = 0; - let layerHeight = 0; - let objectHeight = 0; - let eta = ''; - let confirmCancelPrint = false; + let printStartTime = 0; + let estimatedTime = 0; + let estimatedETA = ' '; - $: updatePropertiesOnPrintingFile($printStatsFilename); - - function updatePropertiesOnPrintingFile(name: string) { - if (name !== '') { - selectedFile = name; - - let meta = values.getFileMetadata(selectedFile); - meta.then(async (m) => { - if (m !== null) { - estimatedTime = m.estimated_time; - filamentTotal = m.filament_total; - layerHeight = m.layer_height; - objectHeight = m.object_height; - selectedFileThumbnailPath = await values.getLargestAbsoluteThumbnailPath($moonrakerApi, m.thumbnails); - } - }); + $: { + if ($fileMeta !== null) { + filamentTotal = $fileMeta.filament_total; + printStartTime = $fileMeta.print_start_time; + estimatedTime = $fileMeta.estimated_time; } } - $: updateEta($progress); + $: { + estimatedETA = clockFormatter.format(new Date((Math.floor(Date.now() / 1000.0) + estimatedTime) * 1000)); + console.log(estimatedETA); + console.log(estimatedTime); + } + + $: { + updateEta($progress); // TODO update on pause + } function updateEta(progress: number) { - console.log('progress', progress, 'duration', $printStatsPrintDuration); if (progress > 0 && $printStatsPrintDuration > 60) { // wait 60sec before update eta dynamic - remainingDuration = Math.floor($printStatsPrintDuration / progress - $printStatsPrintDuration); - eta = clockFormatter.format(new Date((Math.floor(Date.now() / 1000.0) + remainingDuration) * 1000)); + dynamicRemainingTime = Math.floor($printStatsPrintDuration / progress - $printStatsPrintDuration); + dynamicEta = clockFormatter.format(new Date((Math.floor(Date.now() / 1000.0) + dynamicRemainingTime) * 1000)); } else { - remainingDuration = estimatedTime; - eta = clockFormatter.format(new Date((Math.floor(Date.now() / 1000.0) + remainingDuration) * 1000)); + dynamicEta = estimatedETA; } - console.log('eta', eta); } @@ -140,17 +130,17 @@ {$maxAcceleration.toFixed(0)} mm/s² - Pressure - {$pressureAdvance.toFixed(3)} x + PA + {$pressureAdvance.toFixed(3)} {/if}
- {#if selectedFile !== '' || $printStatsState !== 'standby'} + {#if $printStatsFilename !== '' || $printStatsState !== 'standby'}
- {#if !selectedFileThumbnailPath} + {#if $selectedFileThumbnailPath === ''}

No Preview @@ -159,33 +149,45 @@ {selectedFile} + src="{$selectedFileThumbnailPath}" + alt="{$printStatsFilename}" /> {/if} - - {#if $printStatsState === 'standby' || $printStatsState === 'cancelled' || $printStatsState === 'complete' || $printStatsState === 'error'} + {#if $printStatsState === 'standby'} - - + + + {:else if $printStatsState === 'cancelled' || $printStatsState === 'complete' || $printStatsState === 'error'} + + + + + + + + + + + + + + + + {:else if $printStatsState === 'printing' || $printStatsState === 'paused'} - + - @@ -206,9 +208,9 @@ class="flex h-14 w-full items-center justify-center rounded-l-lg bg-neutral-700 px-3 py-2 font-semibold text-neutral-500 drop-shadow-md active:bg-red-500 disabled:opacity-50"> Load - {#if selectedFile !== ''} + {#if $printStatsFilename !== ''}
Remaining{Math.round(remainingDuration / 60)} minETA{estimatedETA}
Filament {(filamentTotal / 1000.0).toFixed(1)} m
Duration{Math.round($printStatsPrintDuration / 60)} min
Layer{$currentLayer}
Progress{($progress * 100.0).toFixed(1)} %
Filament{($filamentUsed / 1000.0).toFixed(1)} m
ETA{eta}{dynamicEta}
Layer {$currentLayer} / {$totalLayer}
Progress {($progress * 100.0).toFixed(1)} %