Skip to content
Merged

Next #210

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a729fa5
feat(stores): app_mode wip
JulienChampagnol Jul 18, 2025
2e75985
recaptcha enabled only in cloud mode
JulienChampagnol Jul 21, 2025
2972142
appMode
JulienChampagnol Jul 21, 2025
55474ce
wip refactor
JulienChampagnol Jul 24, 2025
77872ac
Merge branch 'master' of https://github.com/Geode-solutions/OpenGeode…
JulienChampagnol Jul 24, 2025
f0e6644
JulienChampagnol Jul 24, 2025
72a3f32
wip refactor
JulienChampagnol Jul 25, 2025
6074c6b
Merge branch 'master' of https://github.com/Geode-solutions/OpenGeode…
JulienChampagnol Jul 25, 2025
f59be22
stores & composables
JulienChampagnol Jul 30, 2025
5ed4e17
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
JulienChampagnol Jul 30, 2025
3071551
feat(app_mode): wip fix unit tests
JulienChampagnol Jul 30, 2025
d6a742d
Apply prepare changes
JulienChampagnol Jul 30, 2025
15dd9fc
import.meta.client
JulienChampagnol Jul 30, 2025
0e42f4b
Merge branch 'feat/refactor_stores_and_app_lifecycle' of https://gith…
JulienChampagnol Jul 30, 2025
5efeabc
tests passing
JulienChampagnol Jul 31, 2025
b391011
Merge pull request #207 from Geode-solutions/feat/refactor_stores_and…
JulienChampagnol Jul 31, 2025
0442e98
fix(app_launch): revert recaptcha
JulienChampagnol Jul 31, 2025
c70a1fa
fix(app_launch): revert recaptcha
JulienChampagnol Jul 31, 2025
0b180a3
Merge branch 'feat/refactor_stores_and_app_lifecycle' of https://gith…
JulienChampagnol Jul 31, 2025
c7e7976
Merge pull request #208 from Geode-solutions/feat/refactor_stores_and…
JulienChampagnol Jul 31, 2025
d4d391f
fix(typo): Recaptcha component
JulienChampagnol Jul 31, 2025
a54d0aa
Merge pull request #209 from Geode-solutions/feat/refactor_stores_and…
JulienChampagnol Jul 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
watch(
() => infra_store.is_captcha_validated,
(value, oldValue) => {
if (value && !oldValue && process.client) {
if (value && !oldValue && import.meta.client) {
infra_store.create_backend()
}
},
Expand Down
9 changes: 5 additions & 4 deletions components/Recaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
})

onMounted(() => {
if (process.client) {
const config = useRuntimeConfig()
if (config.public.NODE_ENV !== "production" || !infra_store.is_cloud) {
if (import.meta.client) {
if (
process.env.NODE_ENV !== "production" ||
infra_store.app_mode !== appMode.appMode.CLOUD
) {
infra_store.$patch({ is_captcha_validated: true })
}
}
})

async function submit_recaptcha(token) {
try {
const response = await $fetch.raw(
Expand Down
2 changes: 1 addition & 1 deletion components/RemoteRenderingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
}

onMounted(async () => {
if (process.client) {
if (import.meta.client) {
window.addEventListener("resize", resize)
await nextTick()
view.setContainer(viewer.value.$el)
Expand Down
5 changes: 5 additions & 0 deletions composables/api_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export function api_fetch(
const { valid, error } = validate_schema(schema, body)

if (!valid) {
if (process.env.NODE_ENV === "development") {
console.log("Bad request", error, schema, params)
console.log("schema", schema)
console.log("params", params)
}
feedback_store.add_error(400, schema.$id, "Bad request", error)
throw new Error(schema.$id.concat(": ", error))
}
Expand Down
5 changes: 5 additions & 0 deletions composables/viewer_call.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export function viewer_call(
const { valid, error } = validate_schema(schema, params)

if (!valid) {
if (process.env.NODE_ENV === "development") {
console.log("Bad request", error, schema, params)
console.log("schema", schema)
console.log("params", params)
}
feedback_store.add_error(400, schema.route, "Bad request", error)
throw new Error(schema.route.concat(": ", error))
}
Expand Down
4 changes: 3 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export default defineNuxtConfig({
SITE_BRANCH:
process.env.NODE_ENV === "production" ? process.env.SITE_BRANCH : "",
PROJECT: process.env.NODE_ENV === "production" ? process.env.PROJECT : "",
NODE_ENV: process.env.NODE_ENV,
BROWSER: process.env.BROWSER ?? false,
GEODE_PORT: process.env.GEODE_PORT ?? null,
VIEWER_PORT: process.env.VIEWER_PORT ?? null,
},
},

Expand Down
10 changes: 7 additions & 3 deletions stores/geode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ export const use_geode_store = defineStore("geode", {
}),
getters: {
protocol() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "https"
}
return "http"
},
port() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "443"
}
const GEODE_PORT = useRuntimeConfig().public.GEODE_PORT
if (GEODE_PORT != null && GEODE_PORT !== "") {
return GEODE_PORT
}
return this.default_local_port
},
base_url() {
const infra_store = use_infra_store()
let geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
if (infra_store.is_cloud) {
if (infra_store.app_mode == appMode.appMode.CLOUD) {
if (infra_store.ID == "") {
throw new Error("ID must not be empty in cloud mode")
}
Expand Down
30 changes: 14 additions & 16 deletions stores/infra.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { useStorage } from "@vueuse/core"
import isElectron from "is-electron"
import Status from "@ogw_f/utils/status.js"

export const use_infra_store = defineStore("infra", {
state: () => ({
app_mode: getAppMode(),
ID: useStorage("ID", ""),
is_captcha_validated: false,
status: Status.NOT_CREATED,
}),
getters: {
is_cloud() {
return (
!isElectron() && useRuntimeConfig().public.NODE_ENV === "production"
)
},
domain_name() {
if (this.is_cloud) {
if (this.app_mode == appMode.appMode.CLOUD) {
return useRuntimeConfig().public.API_URL
} else {
return "localhost"
}
return "localhost"
},
lambda_url() {
const geode_store = use_geode_store()
Expand Down Expand Up @@ -47,27 +41,30 @@ export const use_infra_store = defineStore("infra", {
},
actions: {
async create_backend() {
console.log("create_backend this.app_mode", this.app_mode)
if (this.status === Status.CREATED) return
return navigator.locks.request("infra.create_backend", async (lock) => {
this.status = Status.CREATING
if (this.status === Status.CREATED) return
console.log("LOCK GRANTED !", lock)
const geode_store = use_geode_store()
const viewer_store = use_viewer_store()
const feedback_store = use_feedback_store()
if (isElectron()) {
const back_port = await window.electronAPI.run_back(geode_store.port)
if (this.app_mode == appMode.appMode.DESKTOP) {
const viewer_store = use_viewer_store()
const geode_store = use_geode_store()
const back_port = await window.electronAPI.run_back(
geode_store.default_local_port,
)
geode_store.$patch({ default_local_port: back_port })
const viewer_port = await window.electronAPI.run_viewer(
viewer_store.port,
viewer_store.default_local_port,
)
viewer_store.$patch({ default_local_port: viewer_port })
} else {
} else if (this.app_mode == appMode.appMode.CLOUD) {
const { data, error } = await useFetch(this.lambda_url, {
method: "POST",
})
if (error.value || !data.value) {
this.status = Status.NOT_CREATED
const feedback_store = use_feedback_store()
feedback_store.server_error = true
return
}
Expand All @@ -79,6 +76,7 @@ export const use_infra_store = defineStore("infra", {
})
},
async create_connection() {
console.log("create_connection")
await use_viewer_store().ws_connect()
await use_geode_store().do_ping()
return
Expand Down
13 changes: 8 additions & 5 deletions stores/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ export const use_viewer_store = defineStore("viewer", {
}),
getters: {
protocol() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "wss"
} else {
return "ws"
}
},
port() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "443"
} else {
return this.default_local_port
}
const VIEWER_PORT = useRuntimeConfig().public.VIEWER_PORT
if (VIEWER_PORT != null && VIEWER_PORT !== "") {
return VIEWER_PORT
}
return this.default_local_port
},
base_url() {
const infra_store = use_infra_store()
let viewer_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
if (infra_store.is_cloud) {
if (infra_store.app_mode == appMode.appMode.CLOUD) {
if (infra_store.ID == "") {
throw new Error("ID must not be empty in cloud mode")
}
Expand Down
4 changes: 2 additions & 2 deletions test/components/Launcher.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ global.ResizeObserver = require("resize-observer-polyfill")

describe("Launcher.vue", async () => {
test(`Mount`, async () => {
const spy_infra_store = vi.spyOn(infra_store, "create_backend")
const spy_create_backend = vi.spyOn(infra_store, "create_backend")
const wrapper = await mountSuspended(Launcher, {
global: {
plugins: [vuetify],
Expand All @@ -40,6 +40,6 @@ describe("Launcher.vue", async () => {
expect(wrapper.exists()).toBe(true)
await infra_store.$patch({ is_captcha_validated: true })
flushPromises()
expect(spy_infra_store).toHaveBeenCalled()
expect(spy_create_backend).toHaveBeenCalled()
})
})
39 changes: 23 additions & 16 deletions test/stores/Geode.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,57 @@ describe("Geode Store", () => {

describe("getters", () => {
describe("protocol", () => {
test("test is_cloud true", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
expect(geode_store.protocol).toBe("https")
})

test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
expect(geode_store.protocol).toBe("http")
})
test("test app_mode DESKTOP", () => {
infra_store.app_mode = appMode.appMode.DESKTOP
expect(geode_store.protocol).toBe("http")
})
})

describe("port", () => {
test("test is_cloud true", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
expect(geode_store.port).toBe("443")
})
test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
expect(geode_store.port).toBe(geode_store.default_local_port)
})
test("test app_mode DESKTOP", () => {
infra_store.app_mode = appMode.appMode.DESKTOP
expect(geode_store.port).toBe(geode_store.default_local_port)
})

test("test override default_local_port", () => {
infra_store.is_cloud = false
infra_store.app_mode = appMode.appMode.DESKTOP
geode_store.default_local_port = "12"
expect(geode_store.port).toBe("12")
})
})

describe("base_url", () => {
test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
infra_store.domain_name = "localhost"
expect(geode_store.base_url).toBe("http://localhost:5000")
})
test("test is_cloud true", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
infra_store.ID = "123456"
infra_store.domain_name = "example.com"
expect(geode_store.base_url).toBe(
"https://example.com:443/123456/geode",
)
})
test("test is_cloud true, ID empty", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD, ID empty", () => {
infra_store.app_mode = appMode.appMode.CLOUD
infra_store.ID = ""
infra_store.domain_name = "example.com"
expect(() => geode_store.base_url).toThrowError(
Expand Down
19 changes: 10 additions & 9 deletions test/stores/Infra.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ describe("Infra Store", () => {
})
})
describe("getters", () => {
describe("is_cloud", () => {
describe("app_mode", () => {
test("test type", () => {
expectTypeOf(infra_store.is_cloud).toBeBoolean()
expectTypeOf(infra_store.app_mode).toBeString()
})
})

describe("domain_name", () => {
test("test type", () => {
expectTypeOf(infra_store.is_cloud).toBeString()
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
expect(infra_store.domain_name).toBe("localhost")
})
test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode DESKTOP", () => {
infra_store.app_mode = appMode.appMode.DESKTOP
expect(infra_store.domain_name).toBe("localhost")
})
test("test is_cloud false", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
expect(infra_store.domain_name).toBe("api.geode-solutions.com")
})
})
Expand All @@ -64,7 +65,7 @@ describe("Infra Store", () => {
test("test is cloud true", () => {
useRuntimeConfig().public.SITE_BRANCH = "/test"
useRuntimeConfig().public.PROJECT = "/project"
infra_store.is_cloud = true
infra_store.app_mode = appMode.appMode.CLOUD
expect(infra_store.lambda_url).toBe(
"https://api.geode-solutions.com:443/test/project/createbackend",
)
Expand Down
Loading