11import { useStorage } from "@vueuse/core"
2- import isElectron from "is-electron"
32import Status from "@ogw_f/utils/status.js"
3+ import getCaptchaState from "@ogw_f/utils/captcha_state.js"
44
55export const use_infra_store = defineStore ( "infra" , {
66 state : ( ) => ( {
7+ app_mode : getAppMode ( ) ,
78 ID : useStorage ( "ID" , "" ) ,
8- is_captcha_validated : false ,
9+ is_captcha_validated : getCaptchaState ( ) ,
910 status : Status . NOT_CREATED ,
1011 } ) ,
1112 getters : {
12- is_cloud ( ) {
13- return (
14- ! isElectron ( ) && useRuntimeConfig ( ) . public . NODE_ENV === "production"
15- )
16- } ,
1713 domain_name ( ) {
18- if ( this . is_cloud ) {
14+ if ( this . app_mode == appMode . appMode . CLOUD ) {
1915 return useRuntimeConfig ( ) . public . API_URL
20- } else {
21- return "localhost"
2216 }
17+ return "localhost"
2318 } ,
2419 lambda_url ( ) {
2520 const geode_store = use_geode_store ( )
@@ -47,27 +42,30 @@ export const use_infra_store = defineStore("infra", {
4742 } ,
4843 actions : {
4944 async create_backend ( ) {
45+ console . log ( "create_backend this.app_mode" , this . app_mode )
5046 if ( this . status === Status . CREATED ) return
5147 return navigator . locks . request ( "infra.create_backend" , async ( lock ) => {
5248 this . status = Status . CREATING
5349 if ( this . status === Status . CREATED ) return
5450 console . log ( "LOCK GRANTED !" , lock )
55- const geode_store = use_geode_store ( )
56- const viewer_store = use_viewer_store ( )
57- const feedback_store = use_feedback_store ( )
58- if ( isElectron ( ) ) {
59- const back_port = await window . electronAPI . run_back ( geode_store . port )
51+ if ( this . app_mode == appMode . appMode . DESKTOP ) {
52+ const viewer_store = use_viewer_store ( )
53+ const geode_store = use_geode_store ( )
54+ const back_port = await window . electronAPI . run_back (
55+ geode_store . default_local_port ,
56+ )
6057 geode_store . $patch ( { default_local_port : back_port } )
6158 const viewer_port = await window . electronAPI . run_viewer (
62- viewer_store . port ,
59+ viewer_store . default_local_port ,
6360 )
6461 viewer_store . $patch ( { default_local_port : viewer_port } )
65- } else {
62+ } else if ( this . app_mode == appMode . appMode . CLOUD ) {
6663 const { data, error } = await useFetch ( this . lambda_url , {
6764 method : "POST" ,
6865 } )
6966 if ( error . value || ! data . value ) {
7067 this . status = Status . NOT_CREATED
68+ const feedback_store = use_feedback_store ( )
7169 feedback_store . server_error = true
7270 return
7371 }
@@ -79,6 +77,7 @@ export const use_infra_store = defineStore("infra", {
7977 } )
8078 } ,
8179 async create_connection ( ) {
80+ console . log ( "create_connection" )
8281 await use_viewer_store ( ) . ws_connect ( )
8382 await use_geode_store ( ) . do_ping ( )
8483 return
0 commit comments