1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Clean up electron-store based stores

- Add some type script types for better editor experience
- Remove redundent global of a singleton

Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
Sebastian Malton 2020-06-23 12:09:17 -04:00
parent cd66a985cc
commit 97645f4327
17 changed files with 87 additions and 107 deletions

View File

@ -197,7 +197,7 @@ describe("for a pre 2.0 config with an existing cluster", () => {
it("migrates to modern format with kubeconfig under a key", async () => { it("migrates to modern format with kubeconfig under a key", async () => {
const clusterStore = ClusterStore.getInstance() const clusterStore = ClusterStore.getInstance()
const storedCluster = clusterStore.store.get('clusters')[0] const storedCluster = clusterStore.getAllClusters()[0]
expect(storedCluster.kubeConfig).toBe('kubeconfig content') expect(storedCluster.kubeConfig).toBe('kubeconfig content')
}) })
}) })
@ -231,7 +231,7 @@ describe("for a pre 2.4.1 config with an existing cluster", () => {
it("migrates to modern format throwing out the state related data", async () => { it("migrates to modern format throwing out the state related data", async () => {
const clusterStore = ClusterStore.getInstance() const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get('clusters')[0] const storedClusterData = clusterStore.getAllClusters()[0]
expect(storedClusterData.hasOwnProperty('online')).toBe(false) expect(storedClusterData.hasOwnProperty('online')).toBe(false)
expect(storedClusterData.hasOwnProperty('accessible')).toBe(false) expect(storedClusterData.hasOwnProperty('accessible')).toBe(false)
expect(storedClusterData.hasOwnProperty('failureReason')).toBe(false) expect(storedClusterData.hasOwnProperty('failureReason')).toBe(false)
@ -264,7 +264,7 @@ describe("for a pre 2.6.0 config with a cluster that has arrays in auth config",
it("replaces array format access token and expiry into string", async () => { it("replaces array format access token and expiry into string", async () => {
const clusterStore = ClusterStore.getInstance() const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get('clusters')[0] const storedClusterData = clusterStore.getAllClusters()[0]
const kc = yaml.safeLoad(storedClusterData.kubeConfig) const kc = yaml.safeLoad(storedClusterData.kubeConfig)
expect(kc.users[0].user['auth-provider'].config['access-token']).toBe("should be string") expect(kc.users[0].user['auth-provider'].config['access-token']).toBe("should be string")
expect(kc.users[0].user['auth-provider'].config['expiry']).toBe("should be string") expect(kc.users[0].user['auth-provider'].config['expiry']).toBe("should be string")
@ -301,7 +301,7 @@ describe("for a pre 2.6.0 config with a cluster icon", () => {
it("moves the icon into preferences", async () => { it("moves the icon into preferences", async () => {
const clusterStore = ClusterStore.getInstance() const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get('clusters')[0] const storedClusterData = clusterStore.getAllClusters()[0]
expect(storedClusterData.hasOwnProperty('icon')).toBe(false) expect(storedClusterData.hasOwnProperty('icon')).toBe(false)
expect(storedClusterData.preferences.hasOwnProperty('icon')).toBe(true) expect(storedClusterData.preferences.hasOwnProperty('icon')).toBe(true)
expect(storedClusterData.preferences.icon).toBe("icon path") expect(storedClusterData.preferences.icon).toBe("icon path")
@ -338,7 +338,7 @@ describe("for a pre 2.7.0-beta.0 config without a workspace", () => {
it("adds cluster to default workspace", async () => { it("adds cluster to default workspace", async () => {
const clusterStore = ClusterStore.getInstance() const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get("clusters")[0] const storedClusterData = clusterStore.getAllClusters()[0]
expect(storedClusterData.workspace).toBe('default') expect(storedClusterData.workspace).toBe('default')
}) })
}) })

View File

@ -14,7 +14,7 @@ jest.mock("electron", () => {
// Console.log needs to be called before fs-mocks, see https://github.com/tschaub/mock-fs/issues/234 // Console.log needs to be called before fs-mocks, see https://github.com/tschaub/mock-fs/issues/234
console.log(""); console.log("");
import { userStore, User, UserPreferences, UserStore } from "../../../src/common/user-store" import { UserStore } from "../../../src/common/user-store"
describe("for an empty config", () => { describe("for an empty config", () => {
beforeEach(() => { beforeEach(() => {
@ -25,7 +25,6 @@ describe("for an empty config", () => {
} }
} }
mockFs(mockOpts) mockFs(mockOpts)
const userStore = UserStore.getInstance()
}) })
afterEach(() => { afterEach(() => {
@ -33,31 +32,31 @@ describe("for an empty config", () => {
}) })
it("allows setting and retrieving lastSeenAppVersion", async () => { it("allows setting and retrieving lastSeenAppVersion", async () => {
userStore.setLastSeenAppVersion("1.2.3"); UserStore.getInstance().setLastSeenAppVersion("1.2.3");
expect(userStore.lastSeenAppVersion()).toBe("1.2.3"); expect(UserStore.getInstance().lastSeenAppVersion()).toBe("1.2.3");
}) })
it("allows adding and listing seen contexts", async () => { it("allows adding and listing seen contexts", async () => {
userStore.storeSeenContext(['foo']) UserStore.getInstance().storeSeenContext(['foo'])
expect(userStore.getSeenContexts().length).toBe(1) expect(UserStore.getInstance().getSeenContexts().length).toBe(1)
userStore.storeSeenContext(['foo', 'bar']) UserStore.getInstance().storeSeenContext(['foo', 'bar'])
const seenContexts = userStore.getSeenContexts() const seenContexts = UserStore.getInstance().getSeenContexts()
expect(seenContexts.length).toBe(2) // check 'foo' isn't added twice expect(seenContexts.length).toBe(2) // check 'foo' isn't added twice
expect(seenContexts[0]).toBe('foo') expect(seenContexts[0]).toBe('foo')
expect(seenContexts[1]).toBe('bar') expect(seenContexts[1]).toBe('bar')
}) })
it("allows setting and getting preferences", async () => { it("allows setting and getting preferences", async () => {
userStore.setPreferences({ UserStore.getInstance().setPreferences({
httpsProxy: 'abcd://defg', httpsProxy: 'abcd://defg',
}) })
const storedPreferences = userStore.getPreferences() const storedPreferences = UserStore.getInstance().getPreferences()
expect(storedPreferences.httpsProxy).toBe('abcd://defg') expect(storedPreferences.httpsProxy).toBe('abcd://defg')
expect(storedPreferences.colorTheme).toBe('dark') // defaults to dark expect(storedPreferences.colorTheme).toBe('dark') // defaults to dark
userStore.setPreferences({ UserStore.getInstance().setPreferences({
colorTheme: 'light' colorTheme: 'light'
}) })
expect(userStore.getPreferences().colorTheme).toBe('light') expect(UserStore.getInstance().getPreferences().colorTheme).toBe('light')
}) })
}) })
@ -74,7 +73,6 @@ describe("migrations", () => {
} }
} }
mockFs(mockOpts) mockFs(mockOpts)
const userStore = UserStore.getInstance()
}) })
afterEach(() => { afterEach(() => {
@ -82,6 +80,6 @@ describe("migrations", () => {
}) })
it("sets last seen app version to 0.0.0", async () => { it("sets last seen app version to 0.0.0", async () => {
expect(userStore.lastSeenAppVersion()).toBe('0.0.0') expect(UserStore.getInstance().lastSeenAppVersion()).toBe('0.0.0')
}) })
}) })

View File

@ -1,9 +0,0 @@
const userStore = {
getPreferences: jest.fn(() => {
return {
downloadMirror: "default"
}
})
}
export { userStore };

View File

@ -10,7 +10,7 @@ import * as version270Beta1 from "./migrations/cluster-store/2.7.0-beta.1"
export class ClusterStore { export class ClusterStore {
private static instance: ClusterStore; private static instance: ClusterStore;
public store: ElectronStore; private store: ElectronStore;
private constructor() { private constructor() {
this.store = new ElectronStore({ this.store = new ElectronStore({
@ -107,7 +107,3 @@ export class ClusterStore {
ClusterStore.instance = null ClusterStore.instance = null
} }
} }
const clusterStore: ClusterStore = ClusterStore.getInstance();
export { clusterStore };

View File

@ -1,8 +1,8 @@
import * as request from "request" import * as request from "request"
import { userStore } from "../common/user-store" import { UserStore } from "../common/user-store"
export function globalRequestOpts(requestOpts: request.Options ) { export function globalRequestOpts(requestOpts: request.Options ) {
const userPrefs = userStore.getPreferences() const userPrefs = UserStore.getInstance().getPreferences()
if (userPrefs.httpsProxy) { if (userPrefs.httpsProxy) {
requestOpts.proxy = userPrefs.httpsProxy requestOpts.proxy = userPrefs.httpsProxy
} }

View File

@ -1,5 +1,5 @@
import { machineIdSync } from 'node-machine-id' import { machineIdSync } from 'node-machine-id'
import { userStore } from "../common/user-store" import { UserStore } from "../common/user-store"
import * as ua from "universal-analytics" import * as ua from "universal-analytics"
const GA_ID = "UA-159377374-1" const GA_ID = "UA-159377374-1"
@ -36,7 +36,7 @@ export class Tracker {
} }
protected telemetryAllowed() { protected telemetryAllowed() {
const userPrefs = userStore.getPreferences() const userPrefs = UserStore.getInstance().getPreferences()
return !!userPrefs.allowTelemetry return !!userPrefs.allowTelemetry
} }
} }

View File

@ -16,7 +16,7 @@ export interface UserPreferences {
export class UserStore { export class UserStore {
private static instance: UserStore; private static instance: UserStore;
public store: ElectronStore; private store: ElectronStore;
private constructor() { private constructor() {
this.store = new ElectronStore({ this.store = new ElectronStore({
@ -78,7 +78,3 @@ export class UserStore {
UserStore.instance = null UserStore.instance = null
} }
} }
const userStore: UserStore = UserStore.getInstance();
export { userStore };

View File

@ -1,5 +1,5 @@
import * as ElectronStore from "electron-store" import * as ElectronStore from "electron-store"
import { clusterStore } from "./cluster-store" import { ClusterStore } from "./cluster-store"
export interface WorkspaceData { export interface WorkspaceData {
id: string; id: string;
@ -7,6 +7,10 @@ export interface WorkspaceData {
description?: string; description?: string;
} }
interface WorkspaceStoreData {
workspaces: WorkspaceData[];
}
export class Workspace implements WorkspaceData { export class Workspace implements WorkspaceData {
public id: string public id: string
public name: string public name: string
@ -20,12 +24,19 @@ export class Workspace implements WorkspaceData {
export class WorkspaceStore { export class WorkspaceStore {
public static defaultId = "default" public static defaultId = "default"
private static instance: WorkspaceStore; private static instance: WorkspaceStore;
public store: ElectronStore; private store: ElectronStore<WorkspaceStoreData>;
private constructor() { private constructor() {
this.store = new ElectronStore({ this.store = new ElectronStore({
name: "lens-workspace-store" name: "lens-workspace-store",
}) })
if (this.store.get("workspaces", []).length === 0) {
this.store.set("workspaces", [{
id: "default",
name: "default"
}]);
}
} }
public storeWorkspace(workspace: WorkspaceData) { public storeWorkspace(workspace: WorkspaceData) {
@ -46,12 +57,16 @@ export class WorkspaceStore {
const workspaces = this.getAllWorkspaces() const workspaces = this.getAllWorkspaces()
const index = workspaces.findIndex((w) => w.id === workspace.id) const index = workspaces.findIndex((w) => w.id === workspace.id)
if (index !== -1) { if (index !== -1) {
clusterStore.removeClustersByWorkspace(workspace.id) ClusterStore.getInstance().removeClustersByWorkspace(workspace.id)
workspaces.splice(index, 1) workspaces.splice(index, 1)
this.store.set("workspaces", workspaces) this.store.set("workspaces", workspaces)
} }
} }
public getWorkspace(id: string): Workspace | null {
return this.store.get("workspaces", []).find(wsd => wsd.id == id) || null;
}
public getAllWorkspaces(): Array<Workspace> { public getAllWorkspaces(): Array<Workspace> {
const workspacesData: WorkspaceData[] = this.store.get("workspaces", []) const workspacesData: WorkspaceData[] = this.store.get("workspaces", [])

View File

@ -2,7 +2,7 @@ import { KubeConfig } from "@kubernetes/client-node"
import { PromiseIpc } from "electron-promise-ipc" import { PromiseIpc } from "electron-promise-ipc"
import * as http from "http" import * as http from "http"
import { Cluster, ClusterBaseInfo } from "./cluster" import { Cluster, ClusterBaseInfo } from "./cluster"
import { clusterStore } from "../common/cluster-store" import { ClusterStore } from "../common/cluster-store"
import * as k8s from "./k8s" import * as k8s from "./k8s"
import logger from "./logger" import logger from "./logger"
import { LensProxy } from "./proxy" import { LensProxy } from "./proxy"
@ -177,10 +177,10 @@ export class ClusterManager {
} }
try { try {
const clusterIcon = await this.uploadClusterIcon(cluster, fileUpload.name, fileUpload.path) const clusterIcon = await this.uploadClusterIcon(cluster, fileUpload.name, fileUpload.path)
clusterStore.reloadCluster(cluster); ClusterStore.getInstance().reloadCluster(cluster);
if(!cluster.preferences) cluster.preferences = {}; if(!cluster.preferences) cluster.preferences = {};
cluster.preferences.icon = clusterIcon cluster.preferences.icon = clusterIcon
clusterStore.storeCluster(cluster); ClusterStore.getInstance().storeCluster(cluster);
return {success: true, cluster: this.clusterResponse(cluster), message: ""} return {success: true, cluster: this.clusterResponse(cluster), message: ""}
} catch(error) { } catch(error) {
return {success: false, message: error} return {success: false, message: error}
@ -192,7 +192,7 @@ export class ClusterManager {
const cluster = this.getCluster(id) const cluster = this.getCluster(id)
if (cluster && cluster.preferences) { if (cluster && cluster.preferences) {
cluster.preferences.icon = null; cluster.preferences.icon = null;
clusterStore.storeCluster(cluster) ClusterStore.getInstance().storeCluster(cluster)
return {success: true, cluster: this.clusterResponse(cluster), message: ""} return {success: true, cluster: this.clusterResponse(cluster), message: ""}
} else { } else {
return {success: false, message: "Cluster not found"} return {success: false, message: "Cluster not found"}
@ -224,7 +224,7 @@ export class ClusterManager {
logger.debug(`IPC: clusterStored: ${clusterId}`) logger.debug(`IPC: clusterStored: ${clusterId}`)
const cluster = this.clusters.get(clusterId) const cluster = this.clusters.get(clusterId)
if (cluster) { if (cluster) {
clusterStore.reloadCluster(cluster); ClusterStore.getInstance().reloadCluster(cluster);
cluster.stopServer() cluster.stopServer()
} }
}); });
@ -247,7 +247,7 @@ export class ClusterManager {
const cluster = this.clusters.get(id) const cluster = this.clusters.get(id)
if (cluster) { if (cluster) {
cluster.stopServer() cluster.stopServer()
clusterStore.removeCluster(cluster.id); ClusterStore.getInstance().removeCluster(cluster.id);
this.clusters.delete(cluster.id) this.clusters.delete(cluster.id)
} }
return Array.from(this.clusters.values()) return Array.from(this.clusters.values())

View File

@ -1,7 +1,7 @@
import { ContextHandler } from "./context-handler" import { ContextHandler } from "./context-handler"
import { FeatureStatusMap } from "./feature" import { FeatureStatusMap } from "./feature"
import * as k8s from "./k8s" import * as k8s from "./k8s"
import { clusterStore } from "../common/cluster-store" import { ClusterStore } from "../common/cluster-store"
import logger from "./logger" import logger from "./logger"
import { KubeConfig, CoreV1Api, AuthorizationV1Api, V1ResourceAttributes } from "@kubernetes/client-node" import { KubeConfig, CoreV1Api, AuthorizationV1Api, V1ResourceAttributes } from "@kubernetes/client-node"
import * as fm from "./feature-manager"; import * as fm from "./feature-manager";
@ -119,20 +119,13 @@ export class Cluster implements ClusterInfo {
} }
public async refreshCluster() { public async refreshCluster() {
clusterStore.reloadCluster(this) ClusterStore.getInstance().reloadCluster(this)
this.contextHandler.setClusterPreferences(this.preferences) this.contextHandler.setClusterPreferences(this.preferences)
const connectionStatus = await this.getConnectionStatus() const connectionStatus = await this.getConnectionStatus()
if (connectionStatus == ClusterStatus.AccessGranted) { this.accessible = connectionStatus == ClusterStatus.AccessGranted;
this.accessible = true this.online = connectionStatus > ClusterStatus.Offline;
} else {
this.accessible = false
}
if (connectionStatus > ClusterStatus.Offline) {
this.online = true
} else {
this.online = false
}
if (this.accessible) { if (this.accessible) {
this.distribution = this.detectKubernetesDistribution(this.version) this.distribution = this.detectKubernetesDistribution(this.version)
this.features = await fm.getFeatures(this.contextHandler) this.features = await fm.getFeatures(this.contextHandler)
@ -145,7 +138,7 @@ export class Cluster implements ClusterInfo {
} }
public updateKubeconfig(kubeconfig: string) { public updateKubeconfig(kubeconfig: string) {
const storedCluster = clusterStore.getCluster(this.id) const storedCluster = ClusterStore.getInstance().getCluster(this.id)
if (!storedCluster) { return } if (!storedCluster) { return }
this.kubeConfig = kubeconfig this.kubeConfig = kubeconfig
@ -153,18 +146,15 @@ export class Cluster implements ClusterInfo {
} }
public getPrometheusApiPrefix() { public getPrometheusApiPrefix() {
if (!this.preferences.prometheus?.prefix) { return this.preferences.prometheus?.prefix || "";
return ""
}
return this.preferences.prometheus.prefix
} }
public save() { public save() {
clusterStore.storeCluster(this) ClusterStore.getInstance().storeCluster(this)
} }
public toClusterInfo(): ClusterInfo { public toClusterInfo(): ClusterInfo {
const clusterInfo: ClusterInfo = { return {
id: this.id, id: this.id,
workspace: this.workspace, workspace: this.workspace,
url: this.url, url: this.url,
@ -181,8 +171,7 @@ export class Cluster implements ClusterInfo {
kubeCtl: this.kubeCtl, kubeCtl: this.kubeCtl,
kubeConfig: this.kubeConfig, kubeConfig: this.kubeConfig,
preferences: this.preferences preferences: this.preferences
} };
return clusterInfo;
} }
protected async k8sRequest(path: string, opts?: request.RequestPromiseOptions) { protected async k8sRequest(path: string, opts?: request.RequestPromiseOptions) {

View File

@ -7,7 +7,7 @@ import logger from "./logger"
import initMenu from "./menu" import initMenu from "./menu"
import * as proxy from "./proxy" import * as proxy from "./proxy"
import { WindowManager } from "./window-manager"; import { WindowManager } from "./window-manager";
import { clusterStore } from "../common/cluster-store" import { ClusterStore } from "../common/cluster-store"
import { tracker } from "./tracker" import { tracker } from "./tracker"
import { ClusterManager } from "./cluster-manager"; import { ClusterManager } from "./cluster-manager";
import AppUpdater from "./app-updater" import AppUpdater from "./app-updater"
@ -57,7 +57,7 @@ async function main() {
} }
// create cluster manager // create cluster manager
clusterManager = new ClusterManager(clusterStore.getAllClusterObjects(), port) clusterManager = new ClusterManager(ClusterStore.getInstance().getAllClusterObjects(), port)
// run proxy // run proxy
try { try {
proxyServer = proxy.listen(port, clusterManager) proxyServer = proxy.listen(port, clusterManager)

View File

@ -9,7 +9,7 @@ import * as md5File from "md5-file"
import { globalRequestOpts } from "../common/request" import { globalRequestOpts } from "../common/request"
import * as lockFile from "proper-lockfile" import * as lockFile from "proper-lockfile"
import { helmCli } from "./helm-cli" import { helmCli } from "./helm-cli"
import { userStore } from "../common/user-store" import { UserStore } from "../common/user-store"
const bundledVersion = require("../../package.json").config.bundledKubectlVersion const bundledVersion = require("../../package.json").config.bundledKubectlVersion
const kubectlMap: Map<string, string> = new Map([ const kubectlMap: Map<string, string> = new Map([
@ -138,7 +138,7 @@ export class Kubectl {
logger.error(`Local kubectl is version ${version}, expected ${this.kubectlVersion}, unlinking`) logger.error(`Local kubectl is version ${version}, expected ${this.kubectlVersion}, unlinking`)
} }
catch(err) { catch(err) {
logger.error(`Local kubectl failed to run properly (${err.message}), unlinking`) logger.error(`Local kubectl failed to run properly (${err.message}), unlinking`)
} }
await fs.promises.unlink(this.path) await fs.promises.unlink(this.path)
} }
@ -288,7 +288,7 @@ export class Kubectl {
if (process.platform == "darwin") { if (process.platform == "darwin") {
return packageMirrors.get("default") // MacOS packages are only available from default return packageMirrors.get("default") // MacOS packages are only available from default
} }
const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror) const mirror = packageMirrors.get(UserStore.getInstance().getPreferences().downloadMirror)
if (mirror) { return mirror } if (mirror) { return mirror }
return packageMirrors.get("default") return packageMirrors.get("default")

View File

@ -1,6 +1,6 @@
import { LensApiRequest } from "../router" import { LensApiRequest } from "../router"
import { LensApi } from "../lens-api" import { LensApi } from "../lens-api"
import { userStore } from "../../common/user-store" import { UserStore } from "../../common/user-store"
import { getAppVersion } from "../../common/app-utils" import { getAppVersion } from "../../common/app-utils"
import { CoreV1Api, AuthorizationV1Api } from "@kubernetes/client-node" import { CoreV1Api, AuthorizationV1Api } from "@kubernetes/client-node"
import { Cluster } from "../cluster" import { Cluster } from "../cluster"
@ -81,7 +81,7 @@ class ConfigRoute extends LensApi {
const data = { const data = {
clusterName: cluster.contextName, clusterName: cluster.contextName,
lensVersion: getAppVersion(), lensVersion: getAppVersion(),
lensTheme: `kontena-${userStore.getPreferences().colorTheme}`, lensTheme: `kontena-${UserStore.getInstance().getPreferences().colorTheme}`,
kubeVersion: cluster.version, kubeVersion: cluster.version,
chartsEnabled: true, chartsEnabled: true,
isClusterAdmin: cluster.isAdmin, isClusterAdmin: cluster.isAdmin,

View File

@ -22,7 +22,7 @@
import ClusterMenuItem from "@/components/MainMenu/ClusterMenuItem"; import ClusterMenuItem from "@/components/MainMenu/ClusterMenuItem";
import AddClusterMenuItem from "@/components/MainMenu/AddClusterMenuItem"; import AddClusterMenuItem from "@/components/MainMenu/AddClusterMenuItem";
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import { clusterStore } from "@/../common/cluster-store"; import { ClusterStore } from "@/../common/cluster-store";
import * as os from "os"; import * as os from "os";
const { remote } = require('electron') const { remote } = require('electron')
@ -50,7 +50,7 @@ export default {
}, },
set: function(clusters) { set: function(clusters) {
this.$store.commit("updateClusters", clusters); this.$store.commit("updateClusters", clusters);
clusterStore.storeClusters(clusters); ClusterStore.getInstance().storeClusters(clusters);
} }
} }
}, },

View File

@ -1,6 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import { userStore } from "../../common/user-store" import { UserStore } from "../../common/user-store"
import KubeContexts from './modules/kube-contexts' import KubeContexts from './modules/kube-contexts'
import Clusters from './modules/clusters' import Clusters from './modules/clusters'
import HelmRepos from './modules/helm-repos' import HelmRepos from './modules/helm-repos'
@ -31,29 +31,24 @@ export default new Vuex.Store({
hud: { hud: {
isMenuVisible: true, isMenuVisible: true,
}, },
seenContexts: userStore.getSeenContexts(), seenContexts: UserStore.getInstance().getSeenContexts(),
lastSeenAppVersion: userStore.lastSeenAppVersion(), lastSeenAppVersion: UserStore.getInstance().lastSeenAppVersion(),
}, },
mutations: { mutations: {
storeSeenContexts(state, context) { storeSeenContexts(state, context) {
const seenContexts = userStore.storeSeenContext(context); state.seenContexts = UserStore.getInstance().storeSeenContext(context)
state.seenContexts = seenContexts
}, },
updateLastSeenAppVersion(state, appVersion) { updateLastSeenAppVersion(state, appVersion) {
state.lastSeenAppVersion = appVersion; state.lastSeenAppVersion = appVersion;
userStore.setLastSeenAppVersion(appVersion) UserStore.getInstance().setLastSeenAppVersion(appVersion)
}, },
loadPreferences(state) { loadPreferences(state) {
this.commit("savePreferences", userStore.getPreferences()); this.commit("savePreferences", UserStore.getInstance().getPreferences());
}, },
savePreferences(state, prefs) { savePreferences(state, prefs) {
if (prefs.allowTelemetry) { tracker.event("telemetry", prefs.allowTelemetry ? "enabled" : "disabled")
tracker.event("telemetry", "enabled")
} else {
tracker.event("telemetry", "disabled")
}
state.preferences = prefs; state.preferences = prefs;
userStore.setPreferences(prefs); UserStore.getInstance().setPreferences(prefs);
this.dispatch("destroyWebviews") this.dispatch("destroyWebviews")
promiseIpc.send("preferencesSaved") promiseIpc.send("preferencesSaved")
}, },

View File

@ -4,7 +4,7 @@ import { MutationTree, ActionTree, GetterTree } from "vuex"
import { PromiseIpc } from 'electron-promise-ipc' import { PromiseIpc } from 'electron-promise-ipc'
import { Tracker } from "../../../common/tracker" import { Tracker } from "../../../common/tracker"
import { remote } from "electron" import { remote } from "electron"
import { clusterStore } from "../../../common/cluster-store" import { ClusterStore } from "../../../common/cluster-store"
import { Workspace } from "../../../common/workspace-store" import { Workspace } from "../../../common/workspace-store"
const promiseIpc = new PromiseIpc( { maxTimeoutMs: 120000 } ); const promiseIpc = new PromiseIpc( { maxTimeoutMs: 120000 } );
@ -217,7 +217,7 @@ const actions: ActionTree<ClusterState, any> = {
}) })
}, },
storeCluster({commit}, cluster: ClusterInfo) { storeCluster({commit}, cluster: ClusterInfo) {
clusterStore.storeCluster(cluster); ClusterStore.getInstance().storeCluster(cluster);
commit("updateCluster", cluster) commit("updateCluster", cluster)
promiseIpc.send("clusterStored", cluster.id) promiseIpc.send("clusterStored", cluster.id)
} }

View File

@ -1,5 +1,5 @@
import { MutationTree, ActionTree, GetterTree } from "vuex" import { MutationTree, ActionTree, GetterTree } from "vuex"
import { workspaceStore, Workspace, WorkspaceData } from "../../../common/workspace-store" import { WorkspaceStore, Workspace, WorkspaceData } from "../../../common/workspace-store"
export interface WorkspaceState { export interface WorkspaceState {
workspaces: Array<Workspace>; workspaces: Array<Workspace>;
@ -7,8 +7,8 @@ export interface WorkspaceState {
} }
const state: WorkspaceState = { const state: WorkspaceState = {
workspaces: workspaceStore.getAllWorkspaces(), workspaces: WorkspaceStore.getInstance().getAllWorkspaces(),
currentWorkspace: workspaceStore.getAllWorkspaces().find((w) => w.id === "default") currentWorkspace: WorkspaceStore.getInstance().getAllWorkspaces().find((w) => w.id === "default"),
} }
const actions: ActionTree<WorkspaceState, any> = { const actions: ActionTree<WorkspaceState, any> = {
@ -27,16 +27,16 @@ const mutations: MutationTree<WorkspaceState> = {
state.currentWorkspace = workspace state.currentWorkspace = workspace
}, },
addWorkspace(state, workspace: WorkspaceData) { addWorkspace(state, workspace: WorkspaceData) {
workspaceStore.storeWorkspace(workspace) WorkspaceStore.getInstance().storeWorkspace(workspace)
state.workspaces = workspaceStore.getAllWorkspaces() state.workspaces = WorkspaceStore.getInstance().getAllWorkspaces()
}, },
updateWorkspace(state, workspace: WorkspaceData) { updateWorkspace(state, workspace: WorkspaceData) {
workspaceStore.storeWorkspace(workspace) WorkspaceStore.getInstance().storeWorkspace(workspace)
state.workspaces = workspaceStore.getAllWorkspaces() state.workspaces = WorkspaceStore.getInstance().getAllWorkspaces()
}, },
removeWorkspace(state, workspace: Workspace) { removeWorkspace(state, workspace: Workspace) {
workspaceStore.removeWorkspace(workspace) WorkspaceStore.getInstance().removeWorkspace(workspace)
state.workspaces = workspaceStore.getAllWorkspaces() state.workspaces = WorkspaceStore.getInstance().getAllWorkspaces()
} }
} }