Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rvion committed Dec 7, 2023
1 parent c647997 commit 4be45e2
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
5 changes: 4 additions & 1 deletion library/CushyStudio/default/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ app({
],
},
}),
negative: ui.prompt({ default: 'nsfw, nude, girl, woman, human' }),
negative: ui.prompt({
startCollapsed: true,
default: 'nsfw, nude, girl, woman, human',
}),
model: ui_model(ui),
latent: ui_latent(ui),
sampler: ui_sampler(ui),
Expand Down
17 changes: 14 additions & 3 deletions src/controls/Widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,13 @@ export class Widget_prompt implements IRequest<'prompt', Widget_prompt_opts, Wid
if (serial) {
this.state = serial
} else {
this.state = { type:'prompt', id: this.id, active: true, /*text: '',*/ tokens: [] }

this.state = {
type:'prompt',
collapsed: input.startCollapsed,
id: this.id,
active: true,
tokens: []
}
const def = input.default
if (def != null) {
if (typeof def === 'string') {
Expand Down Expand Up @@ -275,7 +280,13 @@ export class Widget_promptOpt implements IRequest<'promptOpt', Widget_promptOpt_
if (serial) {
this.state = serial
} else {
this.state = { type:'promptOpt', id: this.id, active: false, /*text: '',*/ tokens: [] }
this.state = {
type:'promptOpt',
collapsed: input.startCollapsed,
id: this.id,
active: false,
tokens: []
}
const def = input.default
if (def != null) {
if (typeof def === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/db/LiveTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class LiveTable<T extends BaseInstanceFields, L extends LiveInstance<T, L
// ⏸️ console.log(`[🦜] find:`, { findSQL, instances })
return instances
}
insert = (row: Partial<T>): L => {
private insert = (row: Partial<T>): L => {
// 0 check that row is valid
if (Array.isArray(row)) throw new Error('insert does not support arrays')
if (typeof row !== 'object') throw new Error('insert does not support non-objects')
Expand Down
40 changes: 40 additions & 0 deletions src/shell/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { mkdirSync } = require('fs')

START()

process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
Expand Down Expand Up @@ -90,6 +92,44 @@ async function START() {
},
})
mainWindow.maximize()
mkdirSync('outputs/_downloads', { recursive: true })
// https://www.electronjs.org/docs/latest/api/download-item
// https://www.electronjs.org/docs/latest/api/download-item#class-downloaditem

const pathe = require('pathe')
mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
const originalFileName = item.getFilename()
const finalFileName = `${Date.now()}-${originalFileName}`
const relativePath = `outputs/_downloads/${finalFileName}`

// Set the save path, making Electron not to prompt a save dialog.
item.setSavePath(relativePath)

item.on('updated', (event, state) => {
if (state === 'interrupted') {
console.log('Download is interrupted but can be resumed')
} else if (state === 'progressing') {
if (item.isPaused()) {
console.log('Download is paused')
} else {
console.log(`Received bytes: ${item.getReceivedBytes()}`)
}
}
})
item.once('done', (event, state) => {
if (state === 'completed') {
console.log('Download successfully')
mainWindow.webContents.send('filedownloaded', {
fileName: finalFileName,
originalFilename: originalFileName,
relativePath: relativePath,
absolutePath: pathe.resolve(relativePath),
})
} else {
console.log(`Download failed: ${state}`)
}
})
})

// Open DevTools automatically
// mainWindow.webContents.openDevTools()
Expand Down
23 changes: 22 additions & 1 deletion src/utils/electron/ElectronUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import type { STATE } from '../../state/state'
import { asAbsolutePath } from '../fs/pathUtils'

export class ElectronUtils {
constructor(public st: STATE) {
//
const ipcRenderer = window.require('electron').ipcRenderer
ipcRenderer.on(
'filedownloaded',
(
_ev,
json: {
originalFilename: string
fileName: string
absolutePath: string
relativePath: string
},
) => {
// console.log(`[👙] `, {ev, json})
st.db.media_images.create({
infos: {
type: 'image-local',
absPath: asAbsolutePath(json.absolutePath),
},
})
},
)
}

toggleDevTools = () => {
Expand Down

0 comments on commit 4be45e2

Please sign in to comment.