Skip to content

Commit b83fa74

Browse files
author
legionfu
committed
导入时,每个选项增加延时,按顺序设置,防止多个同时触发卡死UI
1 parent 36d1257 commit b83fa74

File tree

2 files changed

+70
-61
lines changed

2 files changed

+70
-61
lines changed

javascript/state.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ state.core = (function () {
7070
'setting_sd_model_checkpoint': 'setting_sd_model_checkpoint',
7171
};
7272

73-
const Image_extensions = [".png", ".jpg"]
73+
const Image_extensions = [".png", ".jpg", ".jpeg"]
7474

7575
let store = null;
7676
let timer = null;

javascript/state.utils.js

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
window.state = window.state || {};
22
state = window.state;
3+
let selectingQueue = 0; // 默认都延时一下再开始触发
34

45
state.utils = {
56

@@ -325,79 +326,87 @@ state.utils = {
325326
try {
326327
let value = store.get(id);
327328
if (value ) { //&& value != 'None'
328-
let input = select.querySelector('input');
329-
state.utils.triggerMouseEvent(input, 'focus');
330-
329+
330+
selectingQueue += 1;
331331
setTimeout(() => {
332-
let items = Array.from(select.querySelectorAll('ul li'));
333-
let localized_value = this.getTranslation(value)
334-
let successed = false
335-
for (li of items){
336-
// li.lastChild.wholeText.trim() === value
337-
if (localized_value.replace(/^\s+|\s+$/g,"") === li.lastChild.wholeText.trim().replace(/^\s+|\s+$/g,"")) {
338-
state.utils.triggerMouseEvent(li, 'mousedown');
339-
successed = true
340-
break
341-
}
342-
}
343332

344-
let hash_pos = localized_value.search(/\[[0-9A-Fa-f]{10}\]/)
345-
if(!successed){ // && hash_pos != -1 找不到对应选项 并且选项里有10位哈希值
333+
let input = select.querySelector('input');
334+
state.utils.triggerMouseEvent(input, 'focus');
335+
336+
setTimeout(() => {
337+
let items = Array.from(select.querySelectorAll('ul li'));
338+
let localized_value = this.getTranslation(value)
339+
let successed = false
346340
for (li of items){
347-
348-
// 去掉Hash比较
349-
let text = li.lastChild.wholeText.trim()
350-
let localized_value_no_hash = localized_value.replace(/\[[0-9A-Fa-f]{10}\]/,"").replace(/^\s+|\s+$/g,"")
351-
let text_no_hash = text.replace(/\[[0-9A-Fa-f]{10}\]/, "").replace(/^\s+|\s+$/g,"")
352-
353-
if (localized_value_no_hash === text_no_hash) {
341+
// li.lastChild.wholeText.trim() === value
342+
if (localized_value.replace(/^\s+|\s+$/g,"") === li.lastChild.wholeText.trim().replace(/^\s+|\s+$/g,"")) {
343+
state.utils.triggerMouseEvent(li, 'mousedown');
354344
successed = true
345+
break
355346
}
356-
357-
// 只比较Hash
358-
if(!successed){
359-
let hash_str = localized_value.substring(hash_pos,hash_pos+12).replace(/^\s+|\s+$/g,"")
360-
let text_hash_pos = text.search(/\[[0-9A-Fa-f]{10}\]/)
361-
let text_hash = text.substring(text_hash_pos, text_hash_pos+12).replace(/^\s+|\s+$/g,"")
362-
if (hash_str === text_hash) {
347+
}
348+
349+
let hash_pos = localized_value.search(/\[[0-9A-Fa-f]{10}\]/)
350+
if(!successed){ // && hash_pos != -1 找不到对应选项 并且选项里有10位哈希值
351+
for (li of items){
352+
353+
// 去掉Hash比较
354+
let text = li.lastChild.wholeText.trim()
355+
let localized_value_no_hash = localized_value.replace(/\[[0-9A-Fa-f]{10}\]/,"").replace(/^\s+|\s+$/g,"")
356+
let text_no_hash = text.replace(/\[[0-9A-Fa-f]{10}\]/, "").replace(/^\s+|\s+$/g,"")
357+
358+
if (localized_value_no_hash === text_no_hash) {
363359
successed = true
364360
}
365-
}
361+
362+
// 只比较Hash
363+
if(!successed){
364+
let hash_str = localized_value.substring(hash_pos,hash_pos+12).replace(/^\s+|\s+$/g,"")
365+
let text_hash_pos = text.search(/\[[0-9A-Fa-f]{10}\]/)
366+
let text_hash = text.substring(text_hash_pos, text_hash_pos+12).replace(/^\s+|\s+$/g,"")
367+
if (hash_str === text_hash) {
368+
successed = true
369+
}
370+
}
366371

367-
if(successed){
368-
state.utils.triggerMouseEvent(li, 'mousedown');
369-
state.core.actions.output_warning(
370-
`The option '${value}' was not found, and has been replaced with '${li.lastChild.wholeText.trim()}'!`)
371-
break
372+
if(successed){
373+
state.utils.triggerMouseEvent(li, 'mousedown');
374+
state.core.actions.output_warning(
375+
`The option '${value}' was not found, and has been replaced with '${li.lastChild.wholeText.trim()}'!`)
376+
break
377+
}
372378
}
373379
}
374-
}
375380

376-
if(!successed && items.length > 0) // 下拉框一个选项都没找到说明就没有这个下拉框,可能是界面设置把下拉框替换成了radio button
377-
{
378-
let option_name = store.prefix + id
379-
if(option_name === "state-setting_sd_model_checkpoint"){
380-
// 大模型找不到就只用warning提示,因为不影响运行
381-
state.core.actions.output_warning(`The option \'${value}\' was not found!`)
382-
}
383-
else{
384-
state.core.actions.output_error(`\'${option_name}\' import failed! The option \'${value}\' was not found!`)
385-
}
386-
if(hash_pos != -1){
387-
let model_name = value
388-
let hash_str = localized_value.substring(hash_pos,hash_pos+12)
389-
state.utils.searchCheckPointByHash(hash_str).then( downloadUrl => {
390-
if(downloadUrl != undefined){
391-
let warning_str = encodeURIComponent(`click to download \
392-
<a style ='text-decoration:underline;color:cornflowerblue;', href='${downloadUrl}'> ${model_name} </a>`)
393-
state.core.actions.output_warning(warning_str)
394-
}
395-
});
381+
if(!successed && items.length > 0) // 下拉框一个选项都没找到说明就没有这个下拉框,可能是界面设置把下拉框替换成了radio button
382+
{
383+
let option_name = store.prefix + id
384+
if(option_name === "state-setting_sd_model_checkpoint"){
385+
// 大模型找不到就只用warning提示,因为不影响运行
386+
state.core.actions.output_warning(`The option \'${value}\' was not found!`)
387+
}
388+
else{
389+
state.core.actions.output_error(`\'${option_name}\' import failed! The option \'${value}\' was not found!`)
390+
}
391+
if(hash_pos != -1){
392+
let model_name = value
393+
let hash_str = localized_value.substring(hash_pos,hash_pos+12)
394+
state.utils.searchCheckPointByHash(hash_str).then( downloadUrl => {
395+
if(downloadUrl != undefined){
396+
let warning_str = encodeURIComponent(`click to download \
397+
<a style ='text-decoration:underline;color:cornflowerblue;', href='${downloadUrl}'> ${model_name} </a>`)
398+
state.core.actions.output_warning(warning_str)
399+
}
400+
});
401+
}
396402
}
397-
}
398403

399-
state.utils.triggerMouseEvent(input, 'blur');
400-
}, 100);
404+
state.utils.triggerMouseEvent(input, 'blur');
405+
selectingQueue -= 1;
406+
console.log(`selectingQueue = ${selectingQueue}`)
407+
}, 100);
408+
409+
}, selectingQueue * 200)
401410
}
402411

403412
setTimeout(() => {

0 commit comments

Comments
 (0)