2022-08-11 08:21:30 +00:00
|
|
|
import { writable, readable, type Writable } from 'svelte/store';
|
2022-07-08 13:38:19 +02:00
|
|
|
|
2022-07-06 11:02:36 +02:00
|
|
|
interface AppSession {
|
2022-07-22 20:48:04 +00:00
|
|
|
ipv4: string | null,
|
|
|
|
ipv6: string | null,
|
2022-07-08 13:38:19 +02:00
|
|
|
version: string | null,
|
2022-07-06 11:02:36 +02:00
|
|
|
userId: string | null,
|
|
|
|
teamId: string | null,
|
|
|
|
permission: string,
|
|
|
|
isAdmin: boolean,
|
|
|
|
whiteLabeled: boolean,
|
|
|
|
whiteLabeledDetails: {
|
|
|
|
icon: string | null,
|
|
|
|
},
|
|
|
|
tokens: {
|
|
|
|
github: string | null,
|
|
|
|
gitlab: string | null,
|
|
|
|
}
|
|
|
|
}
|
2022-08-09 15:28:26 +00:00
|
|
|
interface AddToast {
|
|
|
|
type?: "info" | "success" | "error",
|
|
|
|
message: string,
|
|
|
|
timeout?: number | undefined
|
|
|
|
}
|
2022-07-06 11:02:36 +02:00
|
|
|
export const loginEmail: Writable<string | undefined> = writable()
|
|
|
|
export const appSession: Writable<AppSession> = writable({
|
2022-07-22 20:48:04 +00:00
|
|
|
ipv4: null,
|
|
|
|
ipv6: null,
|
2022-07-08 13:38:19 +02:00
|
|
|
version: null,
|
2022-07-06 11:02:36 +02:00
|
|
|
userId: null,
|
|
|
|
teamId: null,
|
|
|
|
permission: 'read',
|
|
|
|
isAdmin: false,
|
|
|
|
whiteLabeled: false,
|
|
|
|
whiteLabeledDetails: {
|
|
|
|
icon: null
|
|
|
|
},
|
|
|
|
tokens: {
|
|
|
|
github: null,
|
|
|
|
gitlab: null
|
|
|
|
}
|
|
|
|
});
|
|
|
|
export const disabledButton: Writable<boolean> = writable(false);
|
|
|
|
export const status: Writable<any> = writable({
|
|
|
|
application: {
|
|
|
|
isRunning: false,
|
|
|
|
isExited: false,
|
|
|
|
loading: false,
|
|
|
|
initialLoading: true
|
|
|
|
},
|
|
|
|
service: {
|
2022-07-21 12:43:53 +00:00
|
|
|
isRunning: false,
|
|
|
|
isExited: false,
|
2022-07-06 11:02:36 +02:00
|
|
|
loading: false,
|
2022-07-21 12:43:53 +00:00
|
|
|
initialLoading: true
|
2022-07-18 07:45:29 +00:00
|
|
|
},
|
2022-07-06 11:02:36 +02:00
|
|
|
database: {
|
2022-07-21 12:43:53 +00:00
|
|
|
isRunning: false,
|
|
|
|
isExited: false,
|
2022-07-06 11:02:36 +02:00
|
|
|
loading: false,
|
2022-07-21 12:43:53 +00:00
|
|
|
initialLoading: true
|
2022-07-06 11:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export const features = readable({
|
|
|
|
beta: window.localStorage.getItem('beta') === 'true',
|
|
|
|
latestVersion: window.localStorage.getItem('latestVersion')
|
|
|
|
});
|
2022-07-18 07:45:29 +00:00
|
|
|
|
|
|
|
export const location: Writable<null | string> = writable(null)
|
|
|
|
export const setLocation = (resource: any) => {
|
|
|
|
if (GITPOD_WORKSPACE_URL && resource.exposePort) {
|
|
|
|
const { href } = new URL(GITPOD_WORKSPACE_URL);
|
|
|
|
const newURL = href
|
|
|
|
.replace('https://', `https://${resource.exposePort}-`)
|
|
|
|
.replace(/\/$/, '');
|
2022-08-11 08:18:17 +00:00
|
|
|
return location.set(newURL)
|
|
|
|
} else if (CODESANDBOX_HOST){
|
|
|
|
const newURL = `https://${CODESANDBOX_HOST.replace(/\$PORT/,resource.exposePort)}`
|
|
|
|
return location.set(newURL)
|
2022-07-18 07:45:29 +00:00
|
|
|
}
|
2022-08-11 08:18:17 +00:00
|
|
|
return location.set(resource.fqdn)
|
2022-08-09 15:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const toasts: any = writable([])
|
|
|
|
|
|
|
|
export const dismissToast = (id: number) => {
|
|
|
|
toasts.update((all: any) => all.filter((t: any) => t.id !== id))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const addToast = (toast: AddToast) => {
|
|
|
|
// Create a unique ID so we can easily find/remove it
|
|
|
|
// if it is dismissible/has a timeout.
|
|
|
|
const id = Math.floor(Math.random() * 10000)
|
|
|
|
|
|
|
|
// Setup some sensible defaults for a toast.
|
|
|
|
const defaults = {
|
|
|
|
id,
|
|
|
|
type: 'info',
|
|
|
|
timeout: 2000,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the toast to the top of the list of toasts
|
|
|
|
const t = { ...defaults, ...toast }
|
|
|
|
toasts.update((all: any) => [t, ...all])
|
|
|
|
|
|
|
|
// If toast is dismissible, dismiss it after "timeout" amount of time.
|
|
|
|
if (t.timeout) setTimeout(() => dismissToast(id), t.timeout)
|
2022-07-18 07:45:29 +00:00
|
|
|
}
|