@@ -8,6 +8,7 @@ export const useInfraStore = defineStore("infra", {
88 is_captcha_validated : false ,
99 status : Status . NOT_CREATED ,
1010 microservices : [ ] ,
11+ _initialized : false ,
1112 } ) ,
1213 getters : {
1314 domain_name ( ) {
@@ -17,7 +18,7 @@ export const useInfraStore = defineStore("infra", {
1718 return "localhost"
1819 } ,
1920 lambda_url ( ) {
20- const geode_store = useGeodeStore ( )
21+ const geode_store = this . get_microservice_store ( "geode" )
2122 const public_runtime_config = useRuntimeConfig ( ) . public
2223 const url =
2324 geode_store . protocol +
@@ -31,16 +32,42 @@ export const useInfraStore = defineStore("infra", {
3132 return url
3233 } ,
3334 microservices_connected ( ) {
34- return (
35- useGeodeStore ( ) . status == Status . CONNECTED &&
36- useViewerStore ( ) . status == Status . CONNECTED
35+ return this . microservices . every (
36+ ( microservice ) => microservice . store . status === Status . CONNECTED ,
3737 )
3838 } ,
3939 microservices_busy ( ) {
40- return useGeodeStore ( ) . is_busy || useViewerStore ( ) . is_busy
40+ return this . microservices . some (
41+ ( microservice ) => microservice . store . is_busy === true ,
42+ )
4143 } ,
4244 } ,
4345 actions : {
46+ init_microservices ( ) {
47+ if ( this . _initialized ) return
48+ this . _initialized = true
49+
50+ this . microservices = [
51+ {
52+ name : "geode" ,
53+ store : useGeodeStore ( ) ,
54+ connect : ( store ) => store . do_ping ( ) ,
55+ electron_runner : "run_back" ,
56+ } ,
57+ {
58+ name : "viewer" ,
59+ store : useViewerStore ( ) ,
60+ connect : ( store ) => store . ws_connect ( ) ,
61+ electron_runner : "run_viewer" ,
62+ } ,
63+ ]
64+ } ,
65+ get_microservice_store ( name ) {
66+ const microservice = this . microservices . find (
67+ ( microservice ) => microservice . name === name ,
68+ )
69+ return microservice . store
70+ } ,
4471 async create_backend ( ) {
4572 console . log ( "create_backend this.app_mode" , this . app_mode )
4673 if ( this . status === Status . CREATED ) return
@@ -49,14 +76,13 @@ export const useInfraStore = defineStore("infra", {
4976 if ( this . status === Status . CREATED ) return
5077 console . log ( "LOCK GRANTED !" , lock )
5178 if ( this . app_mode == appMode . appMode . DESKTOP ) {
52- const viewer_store = useViewerStore ( )
53- const geode_store = useGeodeStore ( )
54- const [ back_port , viewer_port ] = await Promise . all ( [
55- window . electronAPI . run_back ( ) ,
56- window . electronAPI . run_viewer ( ) ,
57- ] )
58- geode_store . $patch ( { default_local_port : back_port } )
59- viewer_store . $patch ( { default_local_port : viewer_port } )
79+ const port_promises = this . microservices . map ( ( microservice ) =>
80+ window . electronAPI [ microservice . electron_runner ] ( ) ,
81+ )
82+ const ports = await Promise . all ( port_promises )
83+ this . microservices . forEach ( ( microservice , index ) => {
84+ microservice . store . $patch ( { default_local_port : ports [ index ] } )
85+ } )
6086 } else if ( this . app_mode == appMode . appMode . CLOUD ) {
6187 const { data, error } = await useFetch ( this . lambda_url , {
6288 method : "POST" ,
@@ -76,9 +102,15 @@ export const useInfraStore = defineStore("infra", {
76102 } ,
77103 async create_connection ( ) {
78104 console . log ( "create_connection" )
79- await useViewerStore ( ) . ws_connect ( )
80- await useGeodeStore ( ) . do_ping ( )
105+ await Promise . all (
106+ this . microservices . map ( ( microservice ) =>
107+ microservice . connect ( microservice . store ) ,
108+ ) ,
109+ )
81110 return
82111 } ,
83112 } ,
113+ share : {
114+ omit : [ "status" , "microservices" , "_initialized" ] ,
115+ } ,
84116} )
0 commit comments