@@ -5,7 +5,7 @@ import { Thumbnail } from '@/store/files/types'
55import { RootState } from '../types'
66import { chartConfiguration } from '@/globals'
77import { TinyColor } from '@ctrl/tinycolor'
8- import { get } from 'lodash-es'
8+ import { get , isFinite } from 'lodash-es'
99import { getThumb } from '../helpers'
1010
1111export const getters : GetterTree < SocketState , RootState > = {
@@ -120,21 +120,37 @@ export const getters: GetterTree<SocketState, RootState> = {
120120 * Returns an object representing the time estimates of a current print.
121121 */
122122 getTimeEstimates : ( state ) => ( type : 'slicer' | 'file' | 'filament' | 'totals' ) : TimeEstimates => {
123- const progress = ( state . printer . display_status . progress && ! isNaN ( state . printer . display_status . progress ) )
124- ? state . printer . display_status . progress
125- : 0
126- // state.printer.print_stats.total_duration
127- const duration = ( state . printer . print_stats . print_duration && ! isNaN ( state . printer . print_stats . print_duration ) )
128- ? state . printer . print_stats . print_duration
129- : 0
130-
131- const usedFilament = ( state . printer . print_stats . filament_used && ! isNaN ( state . printer . print_stats . filament_used ) )
132- ? state . printer . print_stats . filament_used
133- : 0
134-
135- const estimatedFilament = ( state . printer . current_file . filament_total && ! isNaN ( state . printer . current_file . filament_total ) )
136- ? state . printer . current_file . filament_total
137- : 0
123+ const progress = (
124+ ! state . printer . virtual_sdcard . progress ||
125+ isNaN ( + state . printer . virtual_sdcard . progress ) ||
126+ ! isFinite ( + state . printer . virtual_sdcard . progress )
127+ )
128+ ? 0
129+ : state . printer . virtual_sdcard . progress
130+
131+ const duration = (
132+ ! state . printer . print_stats . print_duration ||
133+ isNaN ( + state . printer . print_stats . print_duration ) ||
134+ ! isFinite ( + state . printer . print_stats . print_duration )
135+ )
136+ ? 0
137+ : state . printer . print_stats . print_duration
138+
139+ const usedFilament = (
140+ ! state . printer . print_stats . filament_used ||
141+ isNaN ( + state . printer . print_stats . filament_used ) ||
142+ ! isFinite ( + state . printer . print_stats . filament_used )
143+ )
144+ ? 0
145+ : state . printer . print_stats . filament_used
146+
147+ const estimatedFilament = (
148+ ! state . printer . current_file . filament_total ||
149+ isNaN ( + state . printer . current_file . filament_total ) ||
150+ ! isFinite ( + state . printer . current_file . filament_total )
151+ )
152+ ? 0
153+ : state . printer . current_file . filament_total
138154
139155 let timeLeft = 0
140156 let totalDuration = 0
@@ -161,11 +177,25 @@ export const getters: GetterTree<SocketState, RootState> = {
161177 break
162178 }
163179 default : { // totals only.
164- totalDuration = duration / ( progress * 100 ) - duration
165- timeLeft = totalDuration - duration
180+ totalDuration = 0
181+ timeLeft = 0
166182 }
167183 }
168184
185+ totalDuration = (
186+ isNaN ( + totalDuration ) ||
187+ ! isFinite ( + totalDuration )
188+ )
189+ ? 0
190+ : totalDuration
191+
192+ timeLeft = (
193+ isNaN ( + timeLeft ) ||
194+ ! isFinite ( + timeLeft )
195+ )
196+ ? 0
197+ : timeLeft
198+
169199 const o = {
170200 type,
171201 progress : ( progress * 100 ) . toFixed ( ) ,
0 commit comments