@ -462,9 +462,29 @@ function ImageGenContent(): JSX.Element {
const [ params , actualSetParams ] = useState < any > (
const [ params , actualSetParams ] = useState < any > (
getModelDefaultParams ( ImageGenerationModels . stableDiffusion )
getModelDefaultParams ( ImageGenerationModels . stableDiffusion )
)
)
const [ initialized , setInitialized ] = useState ( false )
const [ prompt , setPrompt ] = useState ( [ '' ] as string [ ] )
const [ prompt , setPrompt ] = useState ( [ '' ] as string [ ] )
const [ promptLines , setPromptLines ] = useState ( [ 1 ] as number [ ] )
const [ promptLines , setPromptLines ] = useState ( [ 1 ] as number [ ] )
const [ savedPrompt , setSavedPrompt ] = useRememberedValue ( 'imagegen-prompt' , [ '' ] as string [ ] )
const [ negPrompt , setNegPrompt ] = useRememberedValue ( 'imagegen-negativeprompt' , '' )
const [ negPrompt , setNegPrompt ] = useRememberedValue ( 'imagegen-negativeprompt' , '' )
const [ notiEnabled , setNotiEnabled ] = useRememberedValue < boolean > ( 'imagegen-enable-notification' , false )
// Sync prompt and savedPrompt
useEffect ( ( ) = > {
if ( ! initialized ) {
setInitialized ( true )
return // Ignore default value
}
if ( prompt != savedPrompt ) {
setSavedPrompt ( prompt )
}
} , [ prompt ] )
useEffect ( ( ) = > {
if ( savedPrompt != prompt ) {
setPrompt ( savedPrompt )
}
} , [ savedPrompt ] )
// Queue remaining toast
// Queue remaining toast
const queueToastId = React . useRef < any > ( null ) ;
const queueToastId = React . useRef < any > ( null ) ;
@ -675,7 +695,7 @@ function ImageGenContent(): JSX.Element {
} )
} )
. catch ( ( error ) = > {
. catch ( ( error ) = > {
logError ( error )
logError ( error )
toast . error ( ` Error: ${ error . message } - Unable to reach N ovelAI servers. Please wait for a moment and try again` , {
toast . error ( ` Error: ${ error . message } - Unable to reach N aifu servers. Please wait for a moment and try again` , {
toastId : 'promptSuggesionError'
toastId : 'promptSuggesionError'
} )
} )
} )
} )
@ -1049,6 +1069,18 @@ function ImageGenContent(): JSX.Element {
setImages ( [ newImages , . . . images ] )
setImages ( [ newImages , . . . images ] )
}
}
lastGenerationParams = paramString
lastGenerationParams = paramString
if ( notiEnabled ) {
const notification = new Notification ( 'Naifu' , {
body : 'Image generation completed' ,
icon : newImages [ 0 ] . url ,
image : newImages [ 0 ] . url ,
tag : 'imagegen-complete'
} )
notification . onclick = ( ) = > {
window . focus ( )
}
}
}
}
}
}
)
)
@ -1136,6 +1168,18 @@ function ImageGenContent(): JSX.Element {
setImages ( [ newImages , . . . images ] )
setImages ( [ newImages , . . . images ] )
setRerollImageInfo ( newImages [ 0 ] )
setRerollImageInfo ( newImages [ 0 ] )
lastGenerationParams = paramString
lastGenerationParams = paramString
if ( notiEnabled ) {
const notification = new Notification ( 'Naifu' , {
body : 'Image generation completed' ,
icon : newImages [ 0 ] . url ,
image : newImages [ 0 ] . url ,
tag : 'imagegen-complete'
} )
notification . onclick = ( ) = > {
window . focus ( )
}
}
}
}
resolve ( { images : newImages , seeds : masks.map ( ( m ) = > m . seed ) } )
resolve ( { images : newImages , seeds : masks.map ( ( m ) = > m . seed ) } )
}
}
@ -2596,6 +2640,8 @@ function ImageGenContent(): JSX.Element {
params = { params }
params = { params }
setParams = { setParams }
setParams = { setParams }
model = { selectedModel }
model = { selectedModel }
notiEnabled = { notiEnabled }
setNotiEnabled = { setNotiEnabled }
initImage = { initImage }
initImage = { initImage }
setInitImage = { setInitImage }
setInitImage = { setInitImage }
negPrompt = { negPrompt }
negPrompt = { negPrompt }
@ -3234,6 +3280,8 @@ function GenerationOptions(props: {
params : any
params : any
setParams : React.Dispatch < React.SetStateAction < any > >
setParams : React.Dispatch < React.SetStateAction < any > >
children? : JSX.Element | JSX . Element [ ]
children? : JSX.Element | JSX . Element [ ]
notiEnabled : boolean
setNotiEnabled : ( b : boolean ) = > void
initImage : Buffer | undefined
initImage : Buffer | undefined
setInitImage : React.Dispatch < React.SetStateAction < Buffer | undefined > >
setInitImage : React.Dispatch < React.SetStateAction < Buffer | undefined > >
negPrompt : string
negPrompt : string
@ -3243,6 +3291,31 @@ function GenerationOptions(props: {
} ) : JSX . Element {
} ) : JSX . Element {
const [ selectedResolution , setSelectedResolution ] = useState ( 0 )
const [ selectedResolution , setSelectedResolution ] = useState ( 0 )
const siteTheme = useRecoilValue ( SiteTheme )
const siteTheme = useRecoilValue ( SiteTheme )
const [ notiEnabled , setLocalNotiEnabled ] = useState ( false )
useEffect ( ( ) = > {
setLocalNotiEnabled ( props . notiEnabled )
} , [ props . notiEnabled ] )
const setNotiEnabled = useCallback ( ( b : boolean ) = > {
if ( typeof window !== "undefined" ) {
if ( window . Notification . permission === 'denied' ) {
toast . warn ( "You've disabled Notification in browser settings." )
} else {
if ( window . Notification . permission !== 'granted' && b ) {
window . Notification . requestPermission ( ) . then ( ( res ) = > {
if ( res === 'granted' ) {
props . setNotiEnabled ( true )
} else {
props . setNotiEnabled ( false )
}
} )
} else {
props . setNotiEnabled ( b )
}
}
}
} , [ ] )
useEffect ( ( ) = > {
useEffect ( ( ) = > {
if ( props . params . width && props . params . height ) {
if ( props . params . width && props . params . height ) {
@ -3267,6 +3340,21 @@ function GenerationOptions(props: {
const stableDiffusionSettings = (
const stableDiffusionSettings = (
< >
< >
< BorderBox >
< FlexRow >
< Title > Notification < / Title >
< / FlexRow >
< Checkbox
label = { 'Enable Notification' }
checkedText = { 'Notification will be displayed when image generation is completed.' }
uncheckedText = { 'Notification will be displayed when image generation is completed.' }
value = { notiEnabled }
setValue = { setNotiEnabled }
alternate
/ >
< / BorderBox >
< FlexColSpacer min = { 20 } max = { 20 } / >
< BorderBox >
< BorderBox >
< FlexRow >
< FlexRow >
< Title > Image Resolution < / Title >
< Title > Image Resolution < / Title >