Skip to content

Commit 4bf623e

Browse files
committed
refactor
1 parent 584a446 commit 4bf623e

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

electron_app/src/StableDiffusion.vue

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
import { send_to_py } from "./py_vue_bridge.js"
77
import {get_tokens} from './clip_tokeniser/clip_encoder.js'
8+
import {compute_time_remaining} from "./utils.js"
89
const moment = require('moment')
910
1011
let notification_sound = new Audio(require('@/assets/notification.mp3'))
@@ -146,29 +147,14 @@ export default {
146147
this.times.push(iter_time);
147148
let median = this.times.sort((a, b) => a - b)[Math.floor(this.times.length / 2)];
148149
let time_remaining = moment.duration(median*((100-p)*this.nb_its/100));
149-
150-
if(time_remaining > 1){
151-
if (time_remaining.hours() > 0) {
152-
this.remaining_times = `(${time_remaining.hours()}h${time_remaining.minutes()}m left)`;
153-
} else {
154-
this.remaining_times = `(${time_remaining.minutes()}m${time_remaining.seconds()}s left)`;
155-
}
156-
if (this.generation_loop) {
157-
clearInterval(this.generation_loop);
158-
}
159-
this.generation_loop = setInterval(() => {
160-
time_remaining.subtract(1, 'seconds');
161-
if (time_remaining.hours() > 0) {
162-
this.remaining_times = `(${time_remaining.hours()}h${time_remaining.minutes()}m left)`;
163-
} else {
164-
this.remaining_times = `(${time_remaining.minutes()}m${time_remaining.seconds()}s left)`;
165-
}
166-
if (time_remaining < 1) {
167-
clearInterval(this.generation_loop);
168-
this.remaining_times = "";
169-
}
170-
}, 1000);
171-
}
150+
151+
this.remaining_times = compute_time_remaining(time_remaining);
152+
clearInterval(this.generation_loop);
153+
this.generation_loop = setInterval(() => {
154+
time_remaining.subtract(1, 'seconds');
155+
this.remaining_times = compute_time_remaining(time_remaining);
156+
}, 1000);
157+
172158
}
173159
this.attached_cbs.on_progress(p, iter_time);
174160
}

electron_app/src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ function compute_n_cols() {
88
return n_col;
99
}
1010

11-
11+
function compute_time_remaining(time_remaining) {
12+
if (time_remaining.asSeconds() < 1) return "";
13+
if (time_remaining.hours() > 0) return `(${time_remaining.hours()}h${time_remaining.minutes()}m left)`;
14+
else return `(${time_remaining.minutes()}m${time_remaining.seconds()}s left)`;
15+
}
1216

1317
function simple_hash( strr ) {
1418
var hash = 0;
@@ -164,4 +168,4 @@ async function share_on_arthub(imgs , params, prompt ) {
164168

165169

166170

167-
export { compute_n_cols ,resolve_asset_illustration , simple_hash , open_popup, share_on_arthub}
171+
export { compute_n_cols , compute_time_remaining , resolve_asset_illustration , simple_hash , open_popup, share_on_arthub}

0 commit comments

Comments
 (0)