Skip to content

Commit

Permalink
refresh the vae menu on when refreshing the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahAlfaraj committed Jun 5, 2023
1 parent d24a8e9 commit 4a0d45b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
2 changes: 0 additions & 2 deletions after_detailer/src/after_detailer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SpMenu,
SpSliderWithLabel,
} from '../../ultimate_sd_upscaler/src/elements'
// import * as sdapi from '../../sdapi_py_re'

import { AStore } from '../../main/src/astore'
import { ui_config, model_list } from './config'
Expand Down Expand Up @@ -141,7 +140,6 @@ export class AfterDetailerComponent extends React.Component<{
</sp-label>
<button
className="btnSquare refreshButton"
id="btnResetSettings"
title="Refresh the After Detailer Extension"
onClick={this.handleRefresh}
></button>
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ async function refreshUI() {

g_controlnet_max_models = await control_net.requestControlNetMaxUnits()
await control_net.initializeControlNetTab(g_controlnet_max_models)
await main.populateVAE()
} catch (e) {
console.warn(e)
}
Expand Down
67 changes: 45 additions & 22 deletions main/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SpMenu } from '../../ultimate_sd_upscaler/src/elements'

import { getExtensionUrl } from '../../utility/sdapi/python_replacement'
import * as api from '../../utility/api'

declare let g_sd_url: string
// class SDStore extends AStore {
// constructor(data: any) {
// super(data)
Expand All @@ -24,9 +24,10 @@ import * as api from '../../utility/api'

const default_values: any = {
vae_model_list: [],
current_vae: '',
}

export const sd_store = new AStore(default_values)
export const store = new AStore(default_values)

@observer
export class VAEComponent extends React.Component<{
Expand All @@ -41,41 +42,63 @@ export class VAEComponent extends React.Component<{
console.warn('changeVAEModel: vae_model: ', vae_model, e)
}
}
handleRefresh() {
populateVAE()
}
render(): React.ReactNode {
return (
<SpMenu
title="vae models"
items={sd_store.data.vae_model_list}
// disabled={script_store.disabled}
// style="width: 199px; margin-right: 5px"
label_item="Select A VAE"
// id={'model_list'}
onChange={(id: any, value: any) => {
// script_store.setSelectedScript(value.item)
console.log('onChange value: ', value)
this.changeVAEModel(value.item)
}}
></SpMenu>
<div style={{ display: 'flex' }}>
<SpMenu
title="vae models"
items={store.data.vae_model_list}
// disabled={script_store.disabled}
// style="width: 199px; margin-right: 5px"
label_item="Select A VAE"
// id={'model_list'}
selected_index={store.data.vae_model_list.indexOf(
store.data.current_vae
)}
onChange={(id: any, value: any) => {
// script_store.setSelectedScript(value.item)
console.log('onChange value: ', value)
this.changeVAEModel(value.item)
}}
></SpMenu>
<button
className="btnSquare refreshButton"
title="Refresh VAE Models List"
onClick={this.handleRefresh}
></button>
</div>
)
}
}
const vaeContainerNode = document.getElementById('settingsVAEContainer')!
const vaeRoot = ReactDOM.createRoot(vaeContainerNode)

let vae_model_list = ['None']
declare let g_sd_url: string
// let vae_model_list = ['None']

async function requestGetVAE() {
const full_url = `${g_sd_url}/sdapi/v1/options`

async function populateVAE() {
const options = await api.requestGet(full_url)
return options?.sd_vae
}
export async function populateVAE() {
const extension_url = getExtensionUrl()

const full_url = `${extension_url}/vae/list`

const vae_models = await api.requestGet(full_url)

console.log('populateVAE vae_models: ', vae_models)
// vae_model_list = vae_models
sd_store.updateProperty('vae_model_list', vae_models)
store.updateProperty('vae_model_list', vae_models)

const current_vae = await requestGetVAE()
if (current_vae && vae_models.includes(current_vae)) {
store.updateProperty('current_vae', current_vae)
}
}
populateVAE()
// populateVAE()

vaeRoot.render(
<React.StrictMode>
Expand Down
1 change: 0 additions & 1 deletion ultimate_sd_upscaler/src/ultimate_sd_upscaler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ export class UltimateSDUpscalerForm extends React.Component<{
</sp-label>
<button
className="btnSquare refreshButton"
id="btnResetSettings"
title="Refresh the Ultimte SD Upscale script"
onClick={this.handleRefresh}
></button>
Expand Down

0 comments on commit 4a0d45b

Please sign in to comment.