Skip to content

Commit 55474ce

Browse files
wip refactor
1 parent 2972142 commit 55474ce

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

components/Launcher.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424
const infra_store = use_infra_store()
2525
const site_key = useRuntimeConfig().public.RECAPTCHA_SITE_KEY
2626
27+
if (import.meta.client) {
28+
if (infra_store.is_captcha_validated) {
29+
infra_store.create_backend()
30+
}
31+
}
2732
watch(
2833
() => infra_store.is_captcha_validated,
2934
(value, oldValue) => {
30-
if (value && !oldValue && process.client) {
35+
if (value && !oldValue && import.meta.client) {
3136
infra_store.create_backend()
3237
}
3338
},

stores/geode.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
22
import Status from "@ogw_f/utils/status.js"
3-
import appMode from "@ogw_f/utils/app_mode.js"
43

54
export const use_geode_store = defineStore("geode", {
65
state: () => ({
7-
port: "443",
6+
port: "99",
87
request_counter: 0,
98
status: Status.NOT_CONNECTED,
109
}),

stores/infra.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { useStorage } from "@vueuse/core"
2-
import isElectron from "is-electron"
32
import Status from "@ogw_f/utils/status.js"
4-
import { appMode, getAppMode } from "@ogw_f/utils/app_mode.js"
53

64
export const use_infra_store = defineStore("infra", {
75
state: () => ({
86
app_mode: getAppMode(),
97
ID: useStorage("ID", ""),
10-
is_captcha_validated: this.app_mode != appMode.CLOUD ? true : false,
8+
is_captcha_validated: true,
119
status: Status.NOT_CREATED,
1210
}),
1311
getters: {
@@ -44,42 +42,43 @@ export const use_infra_store = defineStore("infra", {
4442
},
4543
actions: {
4644
async create_backend() {
45+
console.log("create_backend")
4746
if (this.status === Status.CREATED) return
4847
return navigator.locks.request("infra.create_backend", async (lock) => {
4948
this.status = Status.CREATING
5049
if (this.status === Status.CREATED) return
5150
console.log("LOCK GRANTED !", lock)
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)
51+
// if (this.app_mode != appMode.BROWSER) {
52+
const geode_store = use_geode_store()
53+
const viewer_store = use_viewer_store()
54+
const feedback_store = use_feedback_store()
55+
if (this.app_mode == appMode.CLOUD) {
56+
const back_port = await window.electronAPI.run_back(geode_store.port)
57+
geode_store.$patch({ default_local_port: back_port })
58+
const viewer_port = await window.electronAPI.run_viewer(
59+
viewer_store.port,
60+
)
61+
viewer_store.$patch({ default_local_port: viewer_port })
62+
} else {
63+
const { data, error } = await useFetch(this.lambda_url, {
64+
method: "POST",
65+
})
66+
if (error.value || !data.value) {
67+
this.status = Status.NOT_CREATED
68+
feedback_store.server_error = true
69+
return
7670
}
71+
this.ID = data.value.ID
72+
localStorage.setItem("ID", data.value.ID)
7773
}
74+
// }
7875
this.status = Status.CREATED
76+
console.log("this.status", this.status)
7977
return this.create_connection()
8078
})
8179
},
8280
async create_connection() {
81+
console.log("create_connection")
8382
await use_viewer_store().ws_connect()
8483
await use_geode_store().do_ping()
8584
return

stores/viewer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import vtkWSLinkClient from "@kitware/vtk.js/IO/Core/WSLinkClient"
33
import "@kitware/vtk.js/Rendering/OpenGL/Profiles/Geometry"
44
import schemas from "@geode/opengeodeweb-viewer/schemas.json"
55
import Status from "@ogw_f/utils/status.js"
6-
import appMode from "@ogw_f/utils/app_mode.js"
76

87
export const use_viewer_store = defineStore("viewer", {
98
state: () => ({
10-
port: "443",
9+
port: "99",
1110
client: {},
1211
config: null,
1312
picking_mode: false,

utils/app_mode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import isElectron from "is-electron"
22

3-
const appMode = {
3+
export const appMode = {
44
DESKTOP: "DESKTOP",
55
BROWSER: "BROWSER",
66
CLOUD: "CLOUD",
77
}
88

9-
function getAppMode() {
9+
export function getAppMode() {
1010
if (isElectron()) {
1111
return appMode.DESKTOP
1212
}

0 commit comments

Comments
 (0)