-
Hoppscotch
+
{{
+ platform.instance.displayConfig.displayName
+ }}
- On-prem
+
+ Default
app
@@ -235,6 +253,7 @@ import {
InstanceSwitcherService,
InstanceType,
} from "~/services/instance-switcher.service"
+import { platform } from "~/platform"
import IconLucideGlobe from "~icons/lucide/globe"
import IconLucideCheck from "~icons/lucide/check"
@@ -285,7 +304,7 @@ const connectionError = computed(() => {
})
const isVendored = computed(() => {
- return currentInstance.value?.type === "vendored"
+ return currentInstance.value?.type === platform.instance.instanceType
})
const isValidUrl = computed(() => {
diff --git a/packages/hoppscotch-common/src/platform/index.ts b/packages/hoppscotch-common/src/platform/index.ts
index b79e475b..cec460c4 100644
--- a/packages/hoppscotch-common/src/platform/index.ts
+++ b/packages/hoppscotch-common/src/platform/index.ts
@@ -21,6 +21,7 @@ import { BackendPlatformDef } from "./backend"
import { OrganizationPlatformDef } from "./organization"
import { KernelIO } from "./kernel-io"
import { AdditionalLinksPlatformDef } from "./additionalLinks"
+import { InstancePlatformDef } from "./instance"
export type PlatformDef = {
ui?: UIPlatformDef
@@ -31,6 +32,7 @@ export type PlatformDef = {
// NOTE: To be deprecated
// io: IOPlatformDef
kernelIO: KernelIO
+ instance: InstancePlatformDef
sync: {
environments: EnvironmentsPlatformDef
collections: CollectionsPlatformDef
diff --git a/packages/hoppscotch-common/src/platform/instance.ts b/packages/hoppscotch-common/src/platform/instance.ts
new file mode 100644
index 00000000..98e8fbbe
--- /dev/null
+++ b/packages/hoppscotch-common/src/platform/instance.ts
@@ -0,0 +1,10 @@
+export type InstancePlatformDef = {
+ instanceType: "vendored"
+ displayConfig: {
+ displayName: string
+ description: string
+ version: string
+ connectingMessage: string
+ connectedMessage: string
+ }
+}
diff --git a/packages/hoppscotch-common/src/services/instance-switcher.service.ts b/packages/hoppscotch-common/src/services/instance-switcher.service.ts
index e874bfdc..9b109133 100644
--- a/packages/hoppscotch-common/src/services/instance-switcher.service.ts
+++ b/packages/hoppscotch-common/src/services/instance-switcher.service.ts
@@ -4,6 +4,7 @@ import { computed } from "vue"
import { LazyStore } from "@tauri-apps/plugin-store"
import { download, load, clear, remove } from "@hoppscotch/plugin-appload"
import { useToast } from "~/composables/toast"
+import { platform } from "~/platform"
const STORE_PATH = "hopp.store.json"
const MAX_RECENT_INSTANCES = 10
@@ -39,21 +40,26 @@ export class InstanceSwitcherService extends Service
{
private store!: LazyStore
private toast = useToast()
+ public getVendoredInstance(): VendoredInstance {
+ const { instanceType, displayConfig } = platform.instance
+ const { displayName, version } = displayConfig
+
+ return {
+ type: instanceType,
+ displayName,
+ version,
+ }
+ }
+
override async onServiceInit(): Promise {
this.store = new LazyStore(STORE_PATH)
await this.store.init()
await this.loadRecentInstances()
if (this.inVendoredEnvironment()) {
- const instance: VendoredInstance = {
- type: "vendored",
- displayName: "Hoppscotch",
- version: "25.5.1",
- }
-
this.state$.next({
status: "connected",
- instance,
+ instance: this.getVendoredInstance(),
})
this.emit(this.state$.value)
} else {
@@ -113,26 +119,25 @@ export class InstanceSwitcherService extends Service {
this.state$.next({
status: "connecting",
- target: "Vendored",
+ target: this.getVendoredInstance().displayName,
})
this.emit(this.state$.value)
try {
- const instance: VendoredInstance = {
- type: "vendored",
- displayName: "Hoppscotch",
- version: "25.5.1",
- }
-
this.state$.next({
status: "connected",
- instance,
+ instance: this.getVendoredInstance(),
})
this.emit(this.state$.value)
await this.saveCurrentState()
- this.toast.success("Connecting to Vendored")
+ this.toast.success(
+ platform.instance.displayConfig.connectingMessage.replace(
+ "{instanceName}",
+ this.getVendoredInstance().displayName
+ )
+ )
const loadResponse = await load({
bundleName: "Hoppscotch",
@@ -140,17 +145,24 @@ export class InstanceSwitcherService extends Service {
})
if (!loadResponse.success) {
- throw new Error("Failed to load vendored bundle")
+ throw new Error(
+ `Failed to load ${this.getVendoredInstance().type} bundle`
+ )
}
- this.toast.success("Connected to Vendored")
+ this.toast.success(
+ platform.instance.displayConfig.connectedMessage.replace(
+ "{instanceName}",
+ this.getVendoredInstance().displayName
+ )
+ )
return true
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : String(error)
this.state$.next({
status: "error",
- target: "Vendored",
+ target: this.getVendoredInstance().displayName,
message: errorMessage,
})
this.emit(this.state$.value)
@@ -325,7 +337,10 @@ export class InstanceSwitcherService extends Service {
public isCurrentlyVendored(): boolean {
const state = this.state$.value
- return state.status === "connected" && state.instance.type === "vendored"
+ return (
+ state.status === "connected" &&
+ state.instance.type === this.getVendoredInstance().type
+ )
}
public isCurrentlyConnectedTo(serverUrl: string): boolean {
diff --git a/packages/hoppscotch-desktop/src/views/Home.vue b/packages/hoppscotch-desktop/src/views/Home.vue
index 47d82cd1..fbfcb5e1 100644
--- a/packages/hoppscotch-desktop/src/views/Home.vue
+++ b/packages/hoppscotch-desktop/src/views/Home.vue
@@ -105,6 +105,11 @@ import IconLucideDownload from "~icons/lucide/download";
const APP_STORE_PATH = "hoppscotch-desktop.store";
+// `InstanceSwitcherService` store path.
+// NOTE: This should be removed eventually,
+// right now this is part 1/5 of HFE-864
+const INSTANCE_STORE_PATH = "hopp.store.json";
+
enum AppState {
LOADING = "loading",
UPDATE_AVAILABLE = "update_available",
@@ -214,16 +219,37 @@ const loadVendored = async () => {
try {
statusMessage.value = "Loading application...";
+ // Standardized vendored instance data.
+ // NOTE: This should be removed eventually,
+ // right now this is part 1/5 of HFE-864
const vendoredInstance: VendoredInstance = {
type: "vendored",
- displayName: "Vendored",
- version: "vendored"
+ displayName: "Hoppscotch",
+ version: "25.5.1"
};
- await saveConnectionState({
+ const connectionState: ConnectionState = {
status: "connected",
instance: vendoredInstance
- });
+ };
+
+ // Save to current app store.
+ // NOTE: This is existing behavior
+ await saveConnectionState(connectionState);
+
+ // ALSO save to `InstanceSwitcherService` store,
+ // NOTE: This should be removed eventually,
+ // right now this is part 1/5 of HFE-864
+ try {
+ const instanceStore = new LazyStore(INSTANCE_STORE_PATH);
+ await instanceStore.init();
+ await instanceStore.set("connectionState", connectionState);
+ await instanceStore.save();
+ console.log("Successfully saved vendored state to `InstanceSwitcherService` store");
+ } catch (instanceStoreError) {
+ console.error("Failed to save to `InstanceSwitcherService` store:", instanceStoreError);
+ // Don't need to fail the flow if this fails.
+ }
console.log("Loading vendored app...");
const loadResp = await load({
diff --git a/packages/hoppscotch-selfhost-web/src/main.ts b/packages/hoppscotch-selfhost-web/src/main.ts
index 39927b1f..cf865cef 100644
--- a/packages/hoppscotch-selfhost-web/src/main.ts
+++ b/packages/hoppscotch-selfhost-web/src/main.ts
@@ -78,6 +78,16 @@ async function initApp() {
},
auth: platformDefs.auth.get(kernelMode),
kernelIO,
+ instance: {
+ instanceType: 'vendored',
+ displayConfig: {
+ displayName: 'Hoppscotch',
+ description: 'On-Prem',
+ version: '25.5.1',
+ connectingMessage: 'Connecting to On-prem',
+ connectedMessage: 'Connected to On-prem'
+ }
+ },
sync: {
environments: platformDefs.environments.get(kernelMode),
collections: platformDefs.collections.get(kernelMode),