|
1 | 1 | import { useStorage } from "@vueuse/core" |
2 | 2 | import isElectron from "is-electron" |
3 | 3 | import Status from "@ogw_f/utils/status.js" |
| 4 | +import { appMode, getAppMode } from "@ogw_f/utils/app_mode.js" |
4 | 5 |
|
5 | 6 | export const use_infra_store = defineStore("infra", { |
6 | 7 | state: () => ({ |
| 8 | + app_mode: getAppMode(), |
7 | 9 | ID: useStorage("ID", ""), |
8 | | - is_captcha_validated: false, |
| 10 | + is_captcha_validated: this.app_mode != appMode.CLOUD ? true : false, |
9 | 11 | status: Status.NOT_CREATED, |
10 | 12 | }), |
11 | 13 | getters: { |
12 | | - is_cloud() { |
13 | | - return !isElectron() && useRuntimeConfig().public.APP_ENV === "production" |
14 | | - }, |
15 | 14 | domain_name() { |
16 | | - if (this.is_cloud) { |
| 15 | + if (this.app_mode == appMode.CLOUD) { |
17 | 16 | return useRuntimeConfig().public.API_URL |
18 | 17 | } else { |
19 | 18 | return "localhost" |
@@ -50,27 +49,31 @@ export const use_infra_store = defineStore("infra", { |
50 | 49 | this.status = Status.CREATING |
51 | 50 | if (this.status === Status.CREATED) return |
52 | 51 | console.log("LOCK GRANTED !", lock) |
53 | | - const geode_store = use_geode_store() |
54 | | - const viewer_store = use_viewer_store() |
55 | | - const feedback_store = use_feedback_store() |
56 | | - if (isElectron()) { |
57 | | - const back_port = await window.electronAPI.run_back(geode_store.port) |
58 | | - geode_store.$patch({ default_local_port: back_port }) |
59 | | - const viewer_port = await window.electronAPI.run_viewer( |
60 | | - viewer_store.port, |
61 | | - ) |
62 | | - viewer_store.$patch({ default_local_port: viewer_port }) |
63 | | - } else { |
64 | | - const { data, error } = await useFetch(this.lambda_url, { |
65 | | - method: "POST", |
66 | | - }) |
67 | | - if (error.value || !data.value) { |
68 | | - this.status = Status.NOT_CREATED |
69 | | - feedback_store.server_error = true |
70 | | - return |
| 52 | + if (this.app_mode != appMode.BROWSER) { |
| 53 | + const geode_store = use_geode_store() |
| 54 | + const viewer_store = use_viewer_store() |
| 55 | + const feedback_store = use_feedback_store() |
| 56 | + if (isElectron()) { |
| 57 | + const back_port = await window.electronAPI.run_back( |
| 58 | + geode_store.port, |
| 59 | + ) |
| 60 | + geode_store.$patch({ default_local_port: back_port }) |
| 61 | + const viewer_port = await window.electronAPI.run_viewer( |
| 62 | + viewer_store.port, |
| 63 | + ) |
| 64 | + viewer_store.$patch({ default_local_port: viewer_port }) |
| 65 | + } else { |
| 66 | + const { data, error } = await useFetch(this.lambda_url, { |
| 67 | + method: "POST", |
| 68 | + }) |
| 69 | + if (error.value || !data.value) { |
| 70 | + this.status = Status.NOT_CREATED |
| 71 | + feedback_store.server_error = true |
| 72 | + return |
| 73 | + } |
| 74 | + this.ID = data.value.ID |
| 75 | + localStorage.setItem("ID", data.value.ID) |
71 | 76 | } |
72 | | - this.ID = data.value.ID |
73 | | - localStorage.setItem("ID", data.value.ID) |
74 | 77 | } |
75 | 78 | this.status = Status.CREATED |
76 | 79 | return this.create_connection() |
|
0 commit comments