1- import { defineStore } from 'pinia'
21import { useStorage } from '@vueuse/core'
32
43export const use_cloud_store = defineStore ( 'cloud' , {
54 state : ( ) => ( {
65 ID : useStorage ( 'ID' , '' ) ,
76 is_captcha_validated : false ,
8- is_cloud_running : false ,
97 is_connexion_launched : false ,
108 } ) ,
119 getters : {
@@ -26,20 +24,20 @@ export const use_cloud_store = defineStore('cloud', {
2624 viewer_url = viewer_url + '/ws'
2725 return viewer_url
2826 } ,
29- is_cloud_running : ( state ) => {
30- const geode_store = use_geode_store ( )
31- const websocket_store = use_websocket_store ( )
32- return state . is_cloud_running
27+ is_cloud_running : ( ) => {
28+ return use_geode_store ( ) . is_client_created && use_websocket_store ( ) . is_client_created
3329 } ,
34- is_cloud_busy : ( ) => {
35- const geode_store = use_geode_store ( )
36- const websocket_store = use_websocket_store ( )
37- return geode_store . api_busy ( ) && websocket_store . websocket_busy ( )
30+ cloud_busy : ( ) => {
31+ const api_busy = use_geode_store ( ) . api_busy
32+ const websocket_busy = use_geode_store ( ) . websocket_busy
33+ const cloud_busy = api_busy || websocket_busy
34+ return cloud_busy
3835 }
3936
4037 } ,
4138 actions : {
4239 async create_connexion ( ) {
40+ const geode_store = use_geode_store ( )
4341 if ( this . is_connexion_launched ) { return }
4442 this . is_connexion_launched = true
4543 if ( this . ID === '' || this . ID === null || typeof this . ID === 'undefined' ) {
@@ -48,22 +46,23 @@ export const use_cloud_store = defineStore('cloud', {
4846 const { data, error } = await useFetch ( `${ this . geode_url } /ping` , { method : 'POST' } )
4947 console . log ( "error" , error )
5048 if ( data . value !== null ) {
51- this . is_cloud_running = true
49+ geode_store . is_client_created = true
5250 return this . ping_task ( )
5351 } else {
5452 return this . create_backend ( )
5553 }
5654 }
5755 } ,
5856 async create_backend ( ) {
57+ const geode_store = use_geode_store ( )
5958 const errors_store = use_errors_store ( )
6059 const config = useRuntimeConfig ( )
6160 const public_runtime_config = config . public
6261 const { data, error } = await useFetch ( `${ public_runtime_config . GEODE_PROTOCOL } ://${ public_runtime_config . API_URL } :${ public_runtime_config . GEODE_PORT } ${ public_runtime_config . SITE_BRANCH } /${ public_runtime_config . PROJECT } /createbackend` , { method : 'POST' } )
6362 if ( data . value !== null ) {
6463 this . ID = data . value . ID
6564 localStorage . setItem ( 'ID' , data . value . ID )
66- this . is_cloud_running = true
65+ geode_store . is_client_created = true
6766 return this . ping_task ( )
6867 } else {
6968 console . log ( "error : " , error )
@@ -75,10 +74,11 @@ export const use_cloud_store = defineStore('cloud', {
7574 setInterval ( ( ) => this . do_ping ( ) , 10 * 1000 )
7675 } ,
7776 async do_ping ( ) {
77+ const geode_store = use_geode_store ( )
7878 const errors_store = use_errors_store ( )
7979 const { data, error } = await useFetch ( `${ this . geode_url } /ping` , { method : 'POST' } )
8080 if ( data . value !== null ) {
81- this . is_cloud_running = true
81+ geode_store . is_client_created = true
8282 } else {
8383 errors_store . server_error = true
8484 console . log ( "error : " , error )
0 commit comments