Skip to content

Commit c4be0ff

Browse files
Merge pull request #210 from Geode-solutions/next
Next
2 parents 8b3be6c + a54d0aa commit c4be0ff

File tree

14 files changed

+125
-74
lines changed

14 files changed

+125
-74
lines changed

components/Launcher.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
watch(
2828
() => infra_store.is_captcha_validated,
2929
(value, oldValue) => {
30-
if (value && !oldValue && process.client) {
30+
if (value && !oldValue && import.meta.client) {
3131
infra_store.create_backend()
3232
}
3333
},

components/Recaptcha.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
})
2121
2222
onMounted(() => {
23-
if (process.client) {
24-
const config = useRuntimeConfig()
25-
if (config.public.NODE_ENV !== "production" || !infra_store.is_cloud) {
23+
if (import.meta.client) {
24+
if (
25+
process.env.NODE_ENV !== "production" ||
26+
infra_store.app_mode !== appMode.appMode.CLOUD
27+
) {
2628
infra_store.$patch({ is_captcha_validated: true })
2729
}
2830
}
2931
})
30-
3132
async function submit_recaptcha(token) {
3233
try {
3334
const response = await $fetch.raw(

components/RemoteRenderingView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
}
109109
110110
onMounted(async () => {
111-
if (process.client) {
111+
if (import.meta.client) {
112112
window.addEventListener("resize", resize)
113113
await nextTick()
114114
view.setContainer(viewer.value.$el)

composables/api_fetch.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export function api_fetch(
1212
const { valid, error } = validate_schema(schema, body)
1313

1414
if (!valid) {
15+
if (process.env.NODE_ENV === "development") {
16+
console.log("Bad request", error, schema, params)
17+
console.log("schema", schema)
18+
console.log("params", params)
19+
}
1520
feedback_store.add_error(400, schema.$id, "Bad request", error)
1621
throw new Error(schema.$id.concat(": ", error))
1722
}

composables/viewer_call.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export function viewer_call(
88
const { valid, error } = validate_schema(schema, params)
99

1010
if (!valid) {
11+
if (process.env.NODE_ENV === "development") {
12+
console.log("Bad request", error, schema, params)
13+
console.log("schema", schema)
14+
console.log("params", params)
15+
}
1116
feedback_store.add_error(400, schema.route, "Bad request", error)
1217
throw new Error(schema.route.concat(": ", error))
1318
}

nuxt.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export default defineNuxtConfig({
55
SITE_BRANCH:
66
process.env.NODE_ENV === "production" ? process.env.SITE_BRANCH : "",
77
PROJECT: process.env.NODE_ENV === "production" ? process.env.PROJECT : "",
8-
NODE_ENV: process.env.NODE_ENV,
8+
BROWSER: process.env.BROWSER ?? false,
9+
GEODE_PORT: process.env.GEODE_PORT ?? null,
10+
VIEWER_PORT: process.env.VIEWER_PORT ?? null,
911
},
1012
},
1113

stores/geode.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@ export const use_geode_store = defineStore("geode", {
99
}),
1010
getters: {
1111
protocol() {
12-
if (use_infra_store().is_cloud) {
12+
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
1313
return "https"
1414
}
1515
return "http"
1616
},
1717
port() {
18-
if (use_infra_store().is_cloud) {
18+
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
1919
return "443"
2020
}
21+
const GEODE_PORT = useRuntimeConfig().public.GEODE_PORT
22+
if (GEODE_PORT != null && GEODE_PORT !== "") {
23+
return GEODE_PORT
24+
}
2125
return this.default_local_port
2226
},
2327
base_url() {
2428
const infra_store = use_infra_store()
2529
let geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
26-
if (infra_store.is_cloud) {
30+
if (infra_store.app_mode == appMode.appMode.CLOUD) {
2731
if (infra_store.ID == "") {
2832
throw new Error("ID must not be empty in cloud mode")
2933
}

stores/infra.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import { useStorage } from "@vueuse/core"
2-
import isElectron from "is-electron"
32
import Status from "@ogw_f/utils/status.js"
43

54
export const use_infra_store = defineStore("infra", {
65
state: () => ({
6+
app_mode: getAppMode(),
77
ID: useStorage("ID", ""),
88
is_captcha_validated: false,
99
status: Status.NOT_CREATED,
1010
}),
1111
getters: {
12-
is_cloud() {
13-
return (
14-
!isElectron() && useRuntimeConfig().public.NODE_ENV === "production"
15-
)
16-
},
1712
domain_name() {
18-
if (this.is_cloud) {
13+
if (this.app_mode == appMode.appMode.CLOUD) {
1914
return useRuntimeConfig().public.API_URL
20-
} else {
21-
return "localhost"
2215
}
16+
return "localhost"
2317
},
2418
lambda_url() {
2519
const geode_store = use_geode_store()
@@ -47,27 +41,30 @@ export const use_infra_store = defineStore("infra", {
4741
},
4842
actions: {
4943
async create_backend() {
44+
console.log("create_backend this.app_mode", this.app_mode)
5045
if (this.status === Status.CREATED) return
5146
return navigator.locks.request("infra.create_backend", async (lock) => {
5247
this.status = Status.CREATING
5348
if (this.status === Status.CREATED) return
5449
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)
50+
if (this.app_mode == appMode.appMode.DESKTOP) {
51+
const viewer_store = use_viewer_store()
52+
const geode_store = use_geode_store()
53+
const back_port = await window.electronAPI.run_back(
54+
geode_store.default_local_port,
55+
)
6056
geode_store.$patch({ default_local_port: back_port })
6157
const viewer_port = await window.electronAPI.run_viewer(
62-
viewer_store.port,
58+
viewer_store.default_local_port,
6359
)
6460
viewer_store.$patch({ default_local_port: viewer_port })
65-
} else {
61+
} else if (this.app_mode == appMode.appMode.CLOUD) {
6662
const { data, error } = await useFetch(this.lambda_url, {
6763
method: "POST",
6864
})
6965
if (error.value || !data.value) {
7066
this.status = Status.NOT_CREATED
67+
const feedback_store = use_feedback_store()
7168
feedback_store.server_error = true
7269
return
7370
}
@@ -79,6 +76,7 @@ export const use_infra_store = defineStore("infra", {
7976
})
8077
},
8178
async create_connection() {
79+
console.log("create_connection")
8280
await use_viewer_store().ws_connect()
8381
await use_geode_store().do_ping()
8482
return

stores/viewer.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ export const use_viewer_store = defineStore("viewer", {
1616
}),
1717
getters: {
1818
protocol() {
19-
if (use_infra_store().is_cloud) {
19+
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
2020
return "wss"
2121
} else {
2222
return "ws"
2323
}
2424
},
2525
port() {
26-
if (use_infra_store().is_cloud) {
26+
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
2727
return "443"
28-
} else {
29-
return this.default_local_port
3028
}
29+
const VIEWER_PORT = useRuntimeConfig().public.VIEWER_PORT
30+
if (VIEWER_PORT != null && VIEWER_PORT !== "") {
31+
return VIEWER_PORT
32+
}
33+
return this.default_local_port
3134
},
3235
base_url() {
3336
const infra_store = use_infra_store()
3437
let viewer_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
35-
if (infra_store.is_cloud) {
38+
if (infra_store.app_mode == appMode.appMode.CLOUD) {
3639
if (infra_store.ID == "") {
3740
throw new Error("ID must not be empty in cloud mode")
3841
}

test/components/Launcher.nuxt.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ global.ResizeObserver = require("resize-observer-polyfill")
3131

3232
describe("Launcher.vue", async () => {
3333
test(`Mount`, async () => {
34-
const spy_infra_store = vi.spyOn(infra_store, "create_backend")
34+
const spy_create_backend = vi.spyOn(infra_store, "create_backend")
3535
const wrapper = await mountSuspended(Launcher, {
3636
global: {
3737
plugins: [vuetify],
@@ -40,6 +40,6 @@ describe("Launcher.vue", async () => {
4040
expect(wrapper.exists()).toBe(true)
4141
await infra_store.$patch({ is_captcha_validated: true })
4242
flushPromises()
43-
expect(spy_infra_store).toHaveBeenCalled()
43+
expect(spy_create_backend).toHaveBeenCalled()
4444
})
4545
})

0 commit comments

Comments
 (0)