1
+ // Wait for ComfyUI to be ready
1
2
const app = window . comfyAPI ?. app ?. app ;
2
- console . log ( "[ComfyStream] Launcher extension loading, app:" , app ) ;
3
-
4
- if ( ! app ) {
5
- console . error ( "[ComfyStream] Failed to get app instance!" ) ;
6
- }
3
+ console . log ( "[ComfyStream] Initializing with app:" , app ) ;
7
4
8
5
async function controlServer ( action ) {
6
+ console . log ( "[ComfyStream] Controlling server with action:" , action ) ;
9
7
try {
10
8
const response = await fetch ( '/comfystream/control' , {
11
9
method : 'POST' ,
@@ -18,6 +16,7 @@ async function controlServer(action) {
18
16
19
17
if ( ! response . ok ) {
20
18
const errorText = await response . text ( ) ;
19
+ console . error ( "[ComfyStream] Server returned error response:" , response . status , errorText ) ;
21
20
try {
22
21
const errorData = JSON . parse ( errorText ) ;
23
22
throw new Error ( errorData . error || `Server error: ${ response . status } ` ) ;
@@ -36,77 +35,94 @@ async function controlServer(action) {
36
35
}
37
36
}
38
37
39
- // Register our custom widget
40
- app . registerExtension ( {
41
- name : "ComfyStream.LauncherButton" ,
42
- async beforeRegisterNodeDef ( nodeType , nodeData ) {
43
- // Only handle our launcher node
44
- if ( nodeData . name !== "ComfyStreamLauncher" ) return ;
38
+ async function openUI ( ) {
39
+ console . log ( "[ComfyStream] Attempting to open UI" ) ;
40
+ try {
41
+ const response = await fetch ( '/launch_comfystream' , {
42
+ method : 'POST' ,
43
+ headers : {
44
+ 'Content-Type' : 'application/json' ,
45
+ 'Accept' : 'application/json'
46
+ } ,
47
+ body : JSON . stringify ( { } )
48
+ } ) ;
45
49
46
- console . log ( "[ComfyStream] Processing ComfyStreamLauncher node" ) ;
47
-
48
- // Add launch method to handle server communication
49
- nodeType . prototype . launchComfyStream = async function ( ) {
50
- console . log ( "[ComfyStream] launchComfyStream called" ) ;
50
+ if ( ! response . ok ) {
51
+ const errorText = await response . text ( ) ;
52
+ console . error ( "[ComfyStream] UI launch returned error response:" , response . status , errorText ) ;
51
53
try {
52
- const response = await fetch ( '/launch_comfystream' , {
53
- method : 'POST' ,
54
- headers : {
55
- 'Content-Type' : 'application/json' ,
56
- 'Accept' : 'application/json'
57
- } ,
58
- body : JSON . stringify ( {
59
- node_id : this . id
60
- } )
61
- } ) ;
62
-
63
- if ( ! response . ok ) {
64
- const errorText = await response . text ( ) ;
65
- try {
66
- const errorData = JSON . parse ( errorText ) ;
67
- throw new Error ( errorData . error || `Server error: ${ response . status } ` ) ;
68
- } catch ( e ) {
69
- throw new Error ( `Server error: ${ response . status } - ${ errorText } ` ) ;
70
- }
71
- }
72
-
73
- const data = await response . json ( ) ;
74
- console . log ( "[ComfyStream] Launch response:" , data ) ;
75
- if ( ! data . success ) {
76
- throw new Error ( data . error || 'Unknown error launching ComfyStream' ) ;
77
- }
78
- } catch ( error ) {
79
- console . error ( '[ComfyStream] Error launching ComfyStream:' , error ) ;
80
- app . ui . dialog . show ( 'Error' , error . message || 'Failed to launch ComfyStream' ) ;
54
+ const errorData = JSON . parse ( errorText ) ;
55
+ throw new Error ( errorData . error || `Server error: ${ response . status } ` ) ;
56
+ } catch ( e ) {
57
+ throw new Error ( `Server error: ${ response . status } - ${ errorText } ` ) ;
81
58
}
82
- } ;
59
+ }
83
60
84
- // Override the onNodeCreated method
85
- const onNodeCreated = nodeType . prototype . onNodeCreated ;
86
- console . log ( "[ComfyStream] Original onNodeCreated:" , onNodeCreated ) ;
87
-
88
- nodeType . prototype . onNodeCreated = function ( ) {
89
- console . log ( "[ComfyStream] onNodeCreated called" ) ;
90
- // Call the original onNodeCreated if it exists
91
- if ( onNodeCreated ) {
92
- console . log ( "[ComfyStream] Calling original onNodeCreated" ) ;
93
- onNodeCreated . apply ( this ) ;
61
+ const data = await response . json ( ) ;
62
+ console . log ( "[ComfyStream] Launch response:" , data ) ;
63
+ if ( ! data . success ) {
64
+ throw new Error ( data . error || 'Unknown error launching ComfyStream' ) ;
65
+ }
66
+ } catch ( error ) {
67
+ console . error ( '[ComfyStream] Error launching ComfyStream:' , error ) ;
68
+ app . ui . dialog . show ( 'Error' , error . message || 'Failed to launch ComfyStream' ) ;
69
+ throw error ;
70
+ }
71
+ }
72
+
73
+ // Register our extension
74
+ const extension = {
75
+ name : "ComfyStream.Menu" ,
76
+
77
+ // Define commands that will be used by menu items
78
+ commands : [
79
+ {
80
+ id : "ComfyStream.OpenUI" ,
81
+ icon : "pi pi-external-link" ,
82
+ label : "Open ComfyStream UI" ,
83
+ function : openUI
84
+ } ,
85
+ {
86
+ id : "ComfyStream.StartServer" ,
87
+ icon : "pi pi-play" ,
88
+ label : "Start ComfyStream Server" ,
89
+ function : async ( ) => {
90
+ await controlServer ( 'start' ) ;
91
+ }
92
+ } ,
93
+ {
94
+ id : "ComfyStream.StopServer" ,
95
+ icon : "pi pi-stop" ,
96
+ label : "Stop ComfyStream Server" ,
97
+ function : async ( ) => {
98
+ await controlServer ( 'stop' ) ;
99
+ }
100
+ } ,
101
+ {
102
+ id : "ComfyStream.RestartServer" ,
103
+ icon : "pi pi-refresh" ,
104
+ label : "Restart ComfyStream Server" ,
105
+ function : async ( ) => {
106
+ await controlServer ( 'restart' ) ;
94
107
}
108
+ }
109
+ ] ,
95
110
96
- // Add all four buttons
97
- const buttons = [
98
- [ "Open UI" , ( ) => this . launchComfyStream ( ) ] ,
99
- [ "Start Server" , ( ) => controlServer ( 'start' ) ] ,
100
- [ "Stop Server" , ( ) => controlServer ( 'stop' ) ] ,
101
- [ "Restart Server" , ( ) => controlServer ( 'restart' ) ]
102
- ] ;
111
+ // Define where these commands appear in the menu
112
+ menuCommands : [
113
+ {
114
+ path : [ "ComfyStream" ] ,
115
+ commands : [
116
+ "ComfyStream.OpenUI" ,
117
+ null , // Separator
118
+ "ComfyStream.StartServer" ,
119
+ "ComfyStream.StopServer" ,
120
+ "ComfyStream.RestartServer"
121
+ ]
122
+ }
123
+ ]
124
+ } ;
103
125
104
- // Add each button
105
- buttons . forEach ( ( [ name , callback ] ) => {
106
- const widget = this . addWidget ( "button" , name , null , callback ) ;
107
- widget . serialize = false ;
108
- } ) ;
109
- console . log ( "[ComfyStream] Node setup complete" ) ;
110
- } ;
111
- }
112
- } ) ;
126
+ console . log ( "[ComfyStream] Registering extension:" , extension ) ;
127
+ app . registerExtension ( extension ) ;
128
+ console . log ( "[ComfyStream] Extension registered" ) ;
0 commit comments