From a8823cfe27761997f48daaabf31f83f0af78ad4f Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 11:10:12 +0300 Subject: [PATCH 1/9] formatting --- index.js | 73 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index bae03b7..c2a5d49 100644 --- a/index.js +++ b/index.js @@ -38,6 +38,7 @@ const io = require('./utility/io') const dummy = require('./utility/dummy') const general = require('./utility/general') const thumbnail = require('./thumbnail') +const note = require('./utility/notification') let g_horde_generator = new horde_native.hordeGenerator() //REFACTOR: move to session.js @@ -3629,7 +3630,7 @@ async function deleteNoneSelected(viewer_objects) { g_viewer_manager.initImageLayersJson = {} g_viewer_manager.outputImages = [] // - + g_generation_session.image_paths_to_layers = {} }) } catch (e) { @@ -3669,10 +3670,25 @@ document ) console.log(`metadata_jsons[${i}]: `, metadata_jsons[i]) - const img_container = thumbnail.Thumbnail.wrapImgInContainer(img,'viewer-image-container') - thumbnail.Thumbnail.addSPButtonToContainer(img_container,'svg_sp_btn', 'place the image on the canvas', moveHistoryImageToLayer, img) - thumbnail.Thumbnail.addSPButtonToContainer(img_container,'svg_sp_btn_datadownload', 'download history data to current settings', getHistoryMetadata, img) - container.appendChild(img_container) + const img_container = thumbnail.Thumbnail.wrapImgInContainer( + img, + 'viewer-image-container' + ) + thumbnail.Thumbnail.addSPButtonToContainer( + img_container, + 'svg_sp_btn', + 'place the image on the canvas', + moveHistoryImageToLayer, + img + ) + thumbnail.Thumbnail.addSPButtonToContainer( + img_container, + 'svg_sp_btn_datadownload', + 'download history data to current settings', + getHistoryMetadata, + img + ) + container.appendChild(img_container) i++ } } catch (e) { @@ -3680,35 +3696,32 @@ document } }) - function getHistoryMetadata(img){ - // debugger - //auto fill the ui with metadata - const metadata_json = JSON.parse( - img.dataset.metadata_json_string - ) - console.log('metadata_json: ', metadata_json) - // document.querySelector('#tiSeed').value = metadata_json.Seed +function getHistoryMetadata(img) { + // debugger + //auto fill the ui with metadata + const metadata_json = JSON.parse(img.dataset.metadata_json_string) + console.log('metadata_json: ', metadata_json) + // document.querySelector('#tiSeed').value = metadata_json.Seed - //extract auto_metadata into the preset metadata - function convertAutoMetadataToPresset(metadata_json) { - metadata_json['seed'] = - metadata_json?.auto_metadata?.Seed - } - convertAutoMetadataToPresset(metadata_json) - document.querySelector('#historySeedLabel').textContent = - metadata_json?.seed - // autoFillInSettings(metadata_json) - g_ui_settings.autoFillInSettings(metadata_json) + //extract auto_metadata into the preset metadata + function convertAutoMetadataToPresset(metadata_json) { + metadata_json['seed'] = metadata_json?.auto_metadata?.Seed } + convertAutoMetadataToPresset(metadata_json) + document.querySelector('#historySeedLabel').textContent = + metadata_json?.seed + // autoFillInSettings(metadata_json) + g_ui_settings.autoFillInSettings(metadata_json) +} - async function moveHistoryImageToLayer(img){ - let image_path = img.dataset.path - const image_path_escape = image_path.replace(/\o/g, '/o') //escape string "\o" in "\output" +async function moveHistoryImageToLayer(img) { + let image_path = img.dataset.path + const image_path_escape = image_path.replace(/\o/g, '/o') //escape string "\o" in "\output" - // load the image from "data:image/png;base64," base64_str - const base64_image = img.src.replace('data:image/png;base64,', '') - await base64ToFile(base64_image) - } + // load the image from "data:image/png;base64," base64_str + const base64_image = img.src.replace('data:image/png;base64,', '') + await base64ToFile(base64_image) +} document .getElementById('btnImageSearch') From 5d16bfefcaa78a6f300fceca8f62a36fe46bd940 Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 11:20:37 +0300 Subject: [PATCH 2/9] deprecate createSolidLayer instead use the descriptor method --- psapi.js | 1 + utility/layer.js | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/psapi.js b/psapi.js index 7945cae..4830c2b 100644 --- a/psapi.js +++ b/psapi.js @@ -9,6 +9,7 @@ const storage = require('uxp').storage const fs = storage.localFileSystem async function createSolidLayer(r, g, b) { + console.warn('this function is deprecated') await executeAsModal(async () => { const result = await batchPlay( [ diff --git a/utility/layer.js b/utility/layer.js index b48cf72..8df7dfd 100644 --- a/utility/layer.js +++ b/utility/layer.js @@ -240,7 +240,29 @@ const makeBackgroundLayerDesc = () => ({ // }, }) -async function createBackgroundLayer() { +const createSolidLayerDesc = (r, g, b) => ({ + _obj: 'make', + _target: [ + { + _ref: 'contentLayer', + }, + ], + using: { + _obj: 'contentLayer', + type: { + _obj: 'solidColorLayer', + color: { + _obj: 'RGBColor', + red: r, + grain: g, + blue: b, + }, + }, + }, + _options: { + dialogOptions: 'dontDisplay', + }, +}) try { const has_background = await hasBackgroundLayer() if (has_background) { From c097ba85e147ddf6c99b2bd7e2fd9058c9e4b0b0 Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 11:21:14 +0300 Subject: [PATCH 3/9] add an option to choose the background layer color --- utility/layer.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/utility/layer.js b/utility/layer.js index 8df7dfd..90f2755 100644 --- a/utility/layer.js +++ b/utility/layer.js @@ -263,6 +263,7 @@ const createSolidLayerDesc = (r, g, b) => ({ dialogOptions: 'dontDisplay', }, }) +async function createBackgroundLayer(r = 255, g = 255, b = 255) { try { const has_background = await hasBackgroundLayer() if (has_background) { @@ -270,12 +271,15 @@ const createSolidLayerDesc = (r, g, b) => ({ return null } await executeAsModal(async () => { - await createNewLayerCommand('background') //create layer + // await createNewLayerCommand('background') //create layer //make the layer into background - const result = await batchPlay([makeBackgroundLayerDesc()], { - synchronousExecution: true, - modalBehavior: 'execute', - }) + const result = await batchPlay( + [createSolidLayerDesc(r, g, b), makeBackgroundLayerDesc()], + { + synchronousExecution: true, + modalBehavior: 'execute', + } + ) }) } catch (e) { console.warn(e) @@ -294,4 +298,6 @@ module.exports = { Layer, hasBackgroundLayer, createBackgroundLayer, + createSolidLayerDesc, + makeBackgroundLayerDesc, } From 4d081dbf5087e841ae62c7037e77eb8bbc51afc8 Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 11:23:48 +0300 Subject: [PATCH 4/9] add a notification utility class for display error messages to the user --- utility/notification.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 utility/notification.js diff --git a/utility/notification.js b/utility/notification.js new file mode 100644 index 0000000..dd4133c --- /dev/null +++ b/utility/notification.js @@ -0,0 +1,9 @@ +const dialog_box = require('../dialog_box') +const { createBackgroundLayer } = require('./layer') +class Notification { + static {} +} + +module.exports = { + Notification, +} From 8be47f74fd224f4715e183ec99f990eb8547846f Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 11:25:11 +0300 Subject: [PATCH 5/9] error messages for when webui is offline and when webui api flag is missing --- utility/notification.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/utility/notification.js b/utility/notification.js index dd4133c..20fece0 100644 --- a/utility/notification.js +++ b/utility/notification.js @@ -2,6 +2,46 @@ const dialog_box = require('../dialog_box') const { createBackgroundLayer } = require('./layer') class Notification { static {} + static async webuiIsOffline() { + const r1 = await dialog_box.prompt( + "Automatic1111 is Offline, make sure it's running in the background", + '', + ['Cancel', 'How To', 'OK'] + ) + + try { + if (r1 === 'Cancel') { + /* cancelled or No */ + console.log('cancel') + } else if (r1 === 'OK') { + console.log('ok') + } else if (r1 === 'How To') { + console.log('How to') + } + } catch (e) { + console.warn(e) + } + } + static async webuiAPIMissing() { + const r1 = await dialog_box.prompt( + "Automatic1111 is running, but you've forgotten to add --api flag, so the plugin can communicate with it", + '', + ['Cancel', 'How To', 'OK'] + ) + + try { + if (r1 === 'Cancel') { + /* cancelled or No */ + console.log('cancel') + } else if (r1 === 'OK') { + console.log('ok') + } else if (r1 === 'How To') { + console.log('How to') + } + } catch (e) { + console.warn(e) + } + } } module.exports = { From ecd34a83d4ba16f49a76e2a5aaf52563f3da8ffb Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 11:25:33 +0300 Subject: [PATCH 6/9] error message for when background layer is missing --- utility/notification.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utility/notification.js b/utility/notification.js index 20fece0..e42ae7f 100644 --- a/utility/notification.js +++ b/utility/notification.js @@ -42,6 +42,25 @@ class Notification { console.warn(e) } } + static async backgroundLayerIsMissing() { + const r1 = await dialog_box.prompt( + 'You need a white background layer present in your document', + '', + ['Cancel', 'Create'] + ) + + try { + if (r1 === 'Cancel') { + /* cancelled or No */ + console.log('cancel') + } else if (r1 === 'Create') { + await createBackgroundLayer() + console.log('create background layer') + } + } catch (e) { + console.warn(e) + } + } } module.exports = { From 12562abf9f20cc86485bb0b544e735bae8200ff1 Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj Date: Mon, 20 Feb 2023 14:52:28 +0300 Subject: [PATCH 7/9] create a sub tab menu that link viewer, history, and image search tabs --- index.html | 349 +++++++++++++++++++++++++++++++++-------------------- index.js | 29 ++++- 2 files changed, 247 insertions(+), 131 deletions(-) diff --git a/index.html b/index.html index 0f6659f..8f7afbc 100644 --- a/index.html +++ b/index.html @@ -117,7 +117,7 @@ flex-wrap: wrap; } - .thumbnail-image-button{ + .thumbnail-image-button { display: none; /* background-color: #495b79; */ color: white; @@ -134,24 +134,24 @@ } .thumbnail-image-button:nth-child(2) { - border-color:green; - bottom:0; - left:0; + border-color: green; + bottom: 0; + left: 0; } .thumbnail-image-button:nth-child(3) { - border-color:pink; - bottom:0; - right:0; + border-color: pink; + bottom: 0; + right: 0; } .thumbnail-image-button:nth-child(4) { - border-color:yellow; - top:0; - left:0; + border-color: yellow; + top: 0; + left: 0; } .thumbnail-image-button:nth-child(5) { - border-color:red; - top:0; - right:0; + border-color: red; + top: 0; + right: 0; } .column-item { @@ -582,9 +582,17 @@
Viewer
-
+ + +
Prompts library
@@ -615,126 +623,191 @@
-
- View your generated images on the canvas +
+ + Viewer + History + Image Search +
-
-
- - - - - -
- - - - - -
- -
-
- - - + + + +
- - Progress... - -
- +
+
+ + + +
+ + Progress... + +
+ + +
+
+ + Thumbnail Size: + + Square 1:1 +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
-
- - Thumbnail Size: - - Square 1:1 --> +
+
+
+ +
+ history of all the images you generated +
+ Seed:00000000000 +
-
+
+
+ +
+
-
-
- -
-
-
- -
-
-
- -
+
+
-
history of all the images you generated Image Search -
-
+
-
Prompt Shortcut: a single word that represent a @@ -1318,15 +1390,32 @@
Edit Text -