mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fully injectable-ize BaseStore so that ApplicationBuilder tests work
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
cf0ca414ea
commit
01d3914b5a
@ -1,154 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import mockFs from "mock-fs";
|
|
||||||
import type { BaseStoreDependencies } from "../base-store/base-store";
|
|
||||||
import { BaseStore } from "../base-store/base-store";
|
|
||||||
import { action, comparer, makeObservable, observable, toJS } from "mobx";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
||||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
|
||||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
|
||||||
import loggerInjectable from "../logger.injectable";
|
|
||||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
|
||||||
ipcMain: {
|
|
||||||
on: jest.fn(),
|
|
||||||
off: jest.fn(),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
interface TestStoreModel {
|
|
||||||
a: string;
|
|
||||||
b: string;
|
|
||||||
c: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestStore extends BaseStore<TestStoreModel> {
|
|
||||||
@observable a = "";
|
|
||||||
@observable b = "";
|
|
||||||
@observable c = "";
|
|
||||||
|
|
||||||
constructor(deps: BaseStoreDependencies) {
|
|
||||||
super(deps, {
|
|
||||||
configName: "test-store",
|
|
||||||
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
|
||||||
syncOptions: {
|
|
||||||
equals: comparer.structural,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
makeObservable(this);
|
|
||||||
this.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@action updateAll(data: TestStoreModel) {
|
|
||||||
this.a = data.a;
|
|
||||||
this.b = data.b;
|
|
||||||
this.c = data.c;
|
|
||||||
}
|
|
||||||
|
|
||||||
@action fromStore(data: Partial<TestStoreModel> = {}) {
|
|
||||||
this.a = data.a || "";
|
|
||||||
this.b = data.b || "";
|
|
||||||
this.c = data.c || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
onSync(data: TestStoreModel) {
|
|
||||||
super.onSync(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
async saveToFile(model: TestStoreModel) {
|
|
||||||
return super.saveToFile(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJSON(): TestStoreModel {
|
|
||||||
const data: TestStoreModel = {
|
|
||||||
a: this.a,
|
|
||||||
b: this.b,
|
|
||||||
c: this.c,
|
|
||||||
};
|
|
||||||
|
|
||||||
return toJS(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("BaseStore", () => {
|
|
||||||
let store: TestStore;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
const mainDi = getDiForUnitTesting({ doGeneralOverrides: true });
|
|
||||||
|
|
||||||
mainDi.override(directoryForUserDataInjectable, () => "some-user-data-directory");
|
|
||||||
mainDi.permitSideEffects(getConfigurationFileModelInjectable);
|
|
||||||
|
|
||||||
const mockOpts = {
|
|
||||||
"some-user-data-directory": {
|
|
||||||
"test-store.json": JSON.stringify({}),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mockFs(mockOpts);
|
|
||||||
|
|
||||||
store = new TestStore({
|
|
||||||
directoryForUserData: mainDi.inject(directoryForUserDataInjectable),
|
|
||||||
getConfigurationFileModel: mainDi.inject(getConfigurationFileModelInjectable),
|
|
||||||
logger: mainDi.inject(loggerInjectable),
|
|
||||||
storeMigrationVersion: mainDi.inject(storeMigrationVersionInjectable),
|
|
||||||
migrations: {},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
mockFs.restore();
|
|
||||||
store.disableSync();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("persistence", () => {
|
|
||||||
it("persists changes to the filesystem", () => {
|
|
||||||
store.updateAll({
|
|
||||||
a: "foo", b: "bar", c: "hello",
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = JSON.parse(readFileSync("some-user-data-directory/test-store.json").toString());
|
|
||||||
|
|
||||||
expect(data).toMatchObject({ a: "foo", b: "bar", c: "hello" });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("persists transaction only once", () => {
|
|
||||||
const fileSpy = jest.spyOn(store, "saveToFile");
|
|
||||||
|
|
||||||
store.updateAll({
|
|
||||||
a: "foo", b: "bar", c: "hello",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(fileSpy).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("persists changes one-by-one without transaction", () => {
|
|
||||||
const fileSpy = jest.spyOn(store, "saveToFile");
|
|
||||||
|
|
||||||
store.a = "a";
|
|
||||||
store.b = "b";
|
|
||||||
|
|
||||||
expect(fileSpy).toHaveBeenCalledTimes(2);
|
|
||||||
|
|
||||||
const data = JSON.parse(readFileSync("some-user-data-directory/test-store.json").toString());
|
|
||||||
|
|
||||||
expect(data).toMatchObject({ a: "a", b: "b", c: "" });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("persists changes coming via onSync (sync from different process)", () => {
|
|
||||||
const fileSpy = jest.spyOn(store, "saveToFile");
|
|
||||||
|
|
||||||
store.onSync({ a: "foo", b: "", c: "bar" });
|
|
||||||
|
|
||||||
expect(store.toJSON()).toMatchObject({ a: "foo", b: "", c: "bar" });
|
|
||||||
|
|
||||||
expect(fileSpy).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -122,8 +122,6 @@ describe("cluster-store", () => {
|
|||||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||||
|
|
||||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||||
|
|
||||||
clusterStore.unregisterIpcListener();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@ -3,19 +3,19 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import path from "path";
|
|
||||||
import type Config from "conf";
|
import type Config from "conf";
|
||||||
import type { Migrations, Options as ConfOptions } from "conf/dist/source/types";
|
import type { Migrations, Options as ConfOptions } from "conf/dist/source/types";
|
||||||
import { ipcMain, ipcRenderer } from "electron";
|
|
||||||
import type { IEqualsComparer } from "mobx";
|
import type { IEqualsComparer } from "mobx";
|
||||||
import { makeObservable, reaction, runInAction } from "mobx";
|
import { makeObservable, reaction } from "mobx";
|
||||||
import type { Disposer } from "../utils";
|
import { disposer, isPromiseLike, toJS } from "../utils";
|
||||||
import { isPromiseLike, toJS } from "../utils";
|
import { broadcastMessage } from "../ipc";
|
||||||
import { broadcastMessage, ipcMainOn, ipcRendererOn } from "../ipc";
|
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
import { kebabCase } from "lodash";
|
import { kebabCase } from "lodash";
|
||||||
import type { GetConfigurationFileModel } from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
import type { GetConfigurationFileModel } from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||||
import type { Logger } from "../logger";
|
import type { Logger } from "../logger";
|
||||||
|
import type { PersistStateToConfig } from "./save-to-file";
|
||||||
|
import type { GetBasenameOfPath } from "../path/get-basename.injectable";
|
||||||
|
import type { EnlistMessageChannelListener } from "../utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
|
||||||
export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> {
|
export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> {
|
||||||
syncOptions?: {
|
syncOptions?: {
|
||||||
@ -30,15 +30,19 @@ export interface BaseStoreDependencies {
|
|||||||
readonly storeMigrationVersion: string;
|
readonly storeMigrationVersion: string;
|
||||||
readonly directoryForUserData: string;
|
readonly directoryForUserData: string;
|
||||||
readonly migrations: Migrations<Record<string, unknown>>;
|
readonly migrations: Migrations<Record<string, unknown>>;
|
||||||
|
readonly ipcChannelPrefix: string;
|
||||||
|
readonly shouldDisableSyncInListener: boolean;
|
||||||
getConfigurationFileModel: GetConfigurationFileModel;
|
getConfigurationFileModel: GetConfigurationFileModel;
|
||||||
|
persistStateToConfig: PersistStateToConfig;
|
||||||
|
getBasenameOfPath: GetBasenameOfPath;
|
||||||
|
enlistMessageChannelListener: EnlistMessageChannelListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: T should only contain base JSON serializable types.
|
* Note: T should only contain base JSON serializable types.
|
||||||
*/
|
*/
|
||||||
export abstract class BaseStore<T extends object> {
|
export abstract class BaseStore<T extends object> {
|
||||||
protected storeConfig?: Config<T>;
|
private readonly syncDisposers = disposer();
|
||||||
protected syncDisposers: Disposer[] = [];
|
|
||||||
|
|
||||||
readonly displayName = kebabCase(this.params.configName).toUpperCase();
|
readonly displayName = kebabCase(this.params.configName).toUpperCase();
|
||||||
|
|
||||||
@ -54,7 +58,8 @@ export abstract class BaseStore<T extends object> {
|
|||||||
*/
|
*/
|
||||||
load() {
|
load() {
|
||||||
this.dependencies.logger.info(`[${this.displayName}]: LOADING ...`);
|
this.dependencies.logger.info(`[${this.displayName}]: LOADING ...`);
|
||||||
this.storeConfig = this.dependencies.getConfigurationFileModel({
|
|
||||||
|
const config = this.dependencies.getConfigurationFileModel({
|
||||||
projectName: "lens",
|
projectName: "lens",
|
||||||
projectVersion: this.dependencies.storeMigrationVersion,
|
projectVersion: this.dependencies.storeMigrationVersion,
|
||||||
cwd: this.cwd(),
|
cwd: this.cwd(),
|
||||||
@ -62,107 +67,60 @@ export abstract class BaseStore<T extends object> {
|
|||||||
migrations: this.dependencies.migrations as Migrations<T>,
|
migrations: this.dependencies.migrations as Migrations<T>,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = this.fromStore(this.storeConfig.store);
|
const res = this.fromStore(config.store);
|
||||||
|
|
||||||
if (isPromiseLike(res)) {
|
if (isPromiseLike(res)) {
|
||||||
this.dependencies.logger.error(`${this.displayName} extends BaseStore<T>'s fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`);
|
this.dependencies.logger.error(`${this.displayName} extends BaseStore<T>'s fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.enableSync();
|
this.startSyncing(config);
|
||||||
this.dependencies.logger.info(`[${this.displayName}]: LOADED from ${this.path}`);
|
this.dependencies.logger.info(`[${this.displayName}]: LOADED from ${config.path}`);
|
||||||
}
|
|
||||||
|
|
||||||
get name() {
|
|
||||||
return path.basename(this.path);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected get syncRendererChannel() {
|
|
||||||
return `store-sync-renderer:${this.path}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected get syncMainChannel() {
|
|
||||||
return `store-sync-main:${this.path}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
get path() {
|
|
||||||
return this.storeConfig?.path || "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected cwd() {
|
protected cwd() {
|
||||||
return this.dependencies.directoryForUserData;
|
return this.dependencies.directoryForUserData;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected saveToFile(model: T) {
|
private startSyncing(config: Config<T>) {
|
||||||
this.dependencies.logger.info(`[${this.displayName}]: SAVING ${this.path}`);
|
const name = this.dependencies.getBasenameOfPath(config.path);
|
||||||
|
const channelName = `${this.dependencies.ipcChannelPrefix}:${config.path}`;
|
||||||
|
|
||||||
// todo: update when fixed https://github.com/sindresorhus/conf/issues/114
|
const disableSync = () => this.syncDisposers();
|
||||||
if (this.storeConfig) {
|
const enableSync = () => {
|
||||||
for (const [key, value] of Object.entries(model)) {
|
|
||||||
this.storeConfig.set(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enableSync() {
|
|
||||||
this.syncDisposers.push(
|
this.syncDisposers.push(
|
||||||
reaction(
|
reaction(
|
||||||
() => toJS(this.toJSON()), // unwrap possible observables and react to everything
|
() => toJS(this.toJSON()), // unwrap possible observables and react to everything
|
||||||
model => this.onModelChange(model),
|
model => {
|
||||||
|
this.dependencies.persistStateToConfig(config, model);
|
||||||
|
broadcastMessage(channelName, model);
|
||||||
|
},
|
||||||
this.params.syncOptions,
|
this.params.syncOptions,
|
||||||
),
|
),
|
||||||
);
|
this.dependencies.enlistMessageChannelListener({
|
||||||
|
channel: {
|
||||||
|
id: channelName,
|
||||||
|
},
|
||||||
|
handler: (model) => {
|
||||||
|
this.dependencies.logger.silly(`[${this.displayName}]: syncing ${name}`, { model });
|
||||||
|
|
||||||
if (ipcMain) {
|
if (this.dependencies.shouldDisableSyncInListener) {
|
||||||
this.syncDisposers.push(ipcMainOn(this.syncMainChannel, (event, model: T) => {
|
disableSync();
|
||||||
this.dependencies.logger.silly(`[${this.displayName}]: SYNC ${this.name} from renderer`, { model });
|
|
||||||
this.onSync(model);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipcRenderer) {
|
|
||||||
this.syncDisposers.push(ipcRendererOn(this.syncRendererChannel, (event, model: T) => {
|
|
||||||
this.dependencies.logger.silly(`[${this.displayName}]: SYNC ${this.name} from main`, { model });
|
|
||||||
this.onSyncFromMain(model);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onSyncFromMain(model: T) {
|
|
||||||
this.applyWithoutSync(() => {
|
|
||||||
this.onSync(model);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
unregisterIpcListener() {
|
|
||||||
ipcRenderer?.removeAllListeners(this.syncMainChannel);
|
|
||||||
ipcRenderer?.removeAllListeners(this.syncRendererChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
disableSync() {
|
|
||||||
this.syncDisposers.forEach(dispose => dispose());
|
|
||||||
this.syncDisposers.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected applyWithoutSync(callback: () => void) {
|
|
||||||
this.disableSync();
|
|
||||||
runInAction(callback);
|
|
||||||
this.enableSync();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onSync(model: T) {
|
|
||||||
// todo: use "resourceVersion" if merge required (to avoid equality checks => better performance)
|
// todo: use "resourceVersion" if merge required (to avoid equality checks => better performance)
|
||||||
if (!isEqual(this.toJSON(), model)) {
|
if (!isEqual(this.toJSON(), model)) {
|
||||||
this.fromStore(model);
|
this.fromStore(model as T);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onModelChange(model: T) {
|
if (this.dependencies.shouldDisableSyncInListener) {
|
||||||
if (ipcMain) {
|
enableSync();
|
||||||
this.saveToFile(model); // save config file
|
|
||||||
broadcastMessage(this.syncRendererChannel, model);
|
|
||||||
} else {
|
|
||||||
broadcastMessage(this.syncMainChannel, model);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
enableSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
10
src/common/base-store/channel-prefix.ts
Normal file
10
src/common/base-store/channel-prefix.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
|
export const baseStoreIpcChannelPrefixInjectionToken = getInjectionToken<string>({
|
||||||
|
id: "base-store-ipc-channel-prefix-token",
|
||||||
|
});
|
||||||
10
src/common/base-store/disable-sync.ts
Normal file
10
src/common/base-store/disable-sync.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
|
export const shouldBaseStoreDisableSyncInIpcListenerInjectionToken = getInjectionToken<boolean>({
|
||||||
|
id: "should-base-store-disable-sync-in-ipc-listener-token",
|
||||||
|
});
|
||||||
12
src/common/base-store/save-to-file.ts
Normal file
12
src/common/base-store/save-to-file.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
import type Config from "conf";
|
||||||
|
|
||||||
|
export type PersistStateToConfig = <T extends object>(config: Config<T>, state: T) => void;
|
||||||
|
|
||||||
|
export const persistStateToConfigInjectionToken = getInjectionToken<PersistStateToConfig>({
|
||||||
|
id: "persist-state-to-config-token",
|
||||||
|
});
|
||||||
@ -13,6 +13,11 @@ import loggerInjectable from "../logger.injectable";
|
|||||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||||
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
||||||
import { clusterStoreMigrationInjectionToken } from "./migration-token";
|
import { clusterStoreMigrationInjectionToken } from "./migration-token";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../base-store/channel-prefix";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file";
|
||||||
|
import getBasenameOfPathInjectable from "../path/get-basename.injectable";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
|
||||||
const clusterStoreInjectable = getInjectable({
|
const clusterStoreInjectable = getInjectable({
|
||||||
id: "cluster-store",
|
id: "cluster-store",
|
||||||
@ -26,6 +31,11 @@ const clusterStoreInjectable = getInjectable({
|
|||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: di.inject(storeMigrationsInjectable, clusterStoreMigrationInjectionToken),
|
migrations: di.inject(storeMigrationsInjectable, clusterStoreMigrationInjectionToken),
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -70,11 +70,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unregisterIpcListener() {
|
|
||||||
super.unregisterIpcListener();
|
|
||||||
this.disposer();
|
|
||||||
}
|
|
||||||
|
|
||||||
pushState() {
|
pushState() {
|
||||||
this.clusters.forEach((c) => {
|
this.clusters.forEach((c) => {
|
||||||
c.pushState();
|
c.pushState();
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { action } from "mobx";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||||
import getConfigurationFileModelInjectable from "./get-configuration-file-model.injectable";
|
import getConfigurationFileModelInjectable from "./get-configuration-file-model.injectable";
|
||||||
@ -21,17 +20,20 @@ export default getGlobalOverride(getConfigurationFileModelInjectable, (di) => {
|
|||||||
assert(options.configName, "Missing options.configName");
|
assert(options.configName, "Missing options.configName");
|
||||||
|
|
||||||
const configFilePath = path.posix.join(options.cwd, options.configName);
|
const configFilePath = path.posix.join(options.cwd, options.configName);
|
||||||
|
let store: object = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
store = readJsonSync(configFilePath);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get store() {
|
get store() {
|
||||||
try {
|
return store;
|
||||||
return readJsonSync(configFilePath);
|
|
||||||
} catch {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
path: configFilePath,
|
path: configFilePath,
|
||||||
set: action((key: string, value: unknown) => {
|
set: (key: string, value: unknown) => {
|
||||||
let currentState: object;
|
let currentState: object;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -44,7 +46,8 @@ export default getGlobalOverride(getConfigurationFileModelInjectable, (di) => {
|
|||||||
...currentState,
|
...currentState,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
});
|
});
|
||||||
}),
|
store = readJsonSync(configFilePath);
|
||||||
|
},
|
||||||
} as Partial<Config> as Config<any>;
|
} as Partial<Config> as Config<any>;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,6 +11,11 @@ import getConfigurationFileModelInjectable from "../get-configuration-file-model
|
|||||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||||
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
||||||
import { hotbarStoreMigrationInjectionToken } from "./migrations-token";
|
import { hotbarStoreMigrationInjectionToken } from "./migrations-token";
|
||||||
|
import getBasenameOfPathInjectable from "../path/get-basename.injectable";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../base-store/channel-prefix";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
|
||||||
|
|
||||||
const hotbarStoreInjectable = getInjectable({
|
const hotbarStoreInjectable = getInjectable({
|
||||||
id: "hotbar-store",
|
id: "hotbar-store",
|
||||||
@ -22,6 +27,11 @@ const hotbarStoreInjectable = getInjectable({
|
|||||||
getConfigurationFileModel: di.inject(getConfigurationFileModelInjectable),
|
getConfigurationFileModel: di.inject(getConfigurationFileModelInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: di.inject(storeMigrationsInjectable, hotbarStoreMigrationInjectionToken),
|
migrations: di.inject(storeMigrationsInjectable, hotbarStoreMigrationInjectionToken),
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,6 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
equals: comparer.structural,
|
equals: comparer.structural,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +53,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
if (typeof hotbar === "number") {
|
if (typeof hotbar === "number") {
|
||||||
if (hotbar >= 0 && hotbar < this.hotbars.length) {
|
if (hotbar >= 0 && hotbar < this.hotbars.length) {
|
||||||
this._activeHotbarId = this.hotbars[hotbar].id;
|
this._activeHotbarId = this.hotbars[hotbar].id;
|
||||||
|
console.log("in _activeHotbarId", this._activeHotbarId);
|
||||||
}
|
}
|
||||||
} else if (typeof hotbar === "string") {
|
} else if (typeof hotbar === "string") {
|
||||||
if (this.findById(hotbar)) {
|
if (this.findById(hotbar)) {
|
||||||
@ -97,21 +97,19 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
this.hotbars.forEach(ensureExactHotbarItemLength);
|
this.hotbars.forEach(ensureExactHotbarItemLength);
|
||||||
|
|
||||||
if (data.activeHotbarId) {
|
if (data.activeHotbarId) {
|
||||||
this.setActiveHotbar(data.activeHotbarId);
|
this._activeHotbarId = data.activeHotbarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.activeHotbarId) {
|
if (!this.activeHotbarId) {
|
||||||
this.setActiveHotbar(0);
|
this._activeHotbarId = this.hotbars[0].id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON(): HotbarStoreModel {
|
toJSON(): HotbarStoreModel {
|
||||||
const model: HotbarStoreModel = {
|
return toJS({
|
||||||
hotbars: this.hotbars,
|
hotbars: this.hotbars,
|
||||||
activeHotbarId: this.activeHotbarId,
|
activeHotbarId: this.activeHotbarId,
|
||||||
};
|
});
|
||||||
|
|
||||||
return toJS(model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getActive(): Hotbar {
|
getActive(): Hotbar {
|
||||||
|
|||||||
@ -12,6 +12,11 @@ import loggerInjectable from "../logger.injectable";
|
|||||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||||
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
||||||
import { userStoreMigrationInjectionToken } from "./migrations-token";
|
import { userStoreMigrationInjectionToken } from "./migrations-token";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../base-store/channel-prefix";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file";
|
||||||
|
import getBasenameOfPathInjectable from "../path/get-basename.injectable";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
|
||||||
const userStoreInjectable = getInjectable({
|
const userStoreInjectable = getInjectable({
|
||||||
id: "user-store",
|
id: "user-store",
|
||||||
@ -24,6 +29,11 @@ const userStoreInjectable = getInjectable({
|
|||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: di.inject(storeMigrationsInjectable, userStoreMigrationInjectionToken),
|
migrations: di.inject(storeMigrationsInjectable, userStoreMigrationInjectionToken),
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../base-store/channel-prefix";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
|
||||||
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
import storeMigrationsInjectable from "../base-store/migrations.injectable";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file";
|
||||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||||
import loggerInjectable from "../logger.injectable";
|
import loggerInjectable from "../logger.injectable";
|
||||||
|
import getBasenameOfPathInjectable from "../path/get-basename.injectable";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||||
import { weblinkStoreMigrationInjectionToken } from "./migration-token";
|
import { weblinkStoreMigrationInjectionToken } from "./migration-token";
|
||||||
import { WeblinkStore } from "./weblink-store";
|
import { WeblinkStore } from "./weblink-store";
|
||||||
@ -19,6 +24,11 @@ const weblinkStoreInjectable = getInjectable({
|
|||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: di.inject(storeMigrationsInjectable, weblinkStoreMigrationInjectionToken),
|
migrations: di.inject(storeMigrationsInjectable, weblinkStoreMigrationInjectionToken),
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,11 @@ import directoryForUserDataInjectable from "../../../common/app-paths/directory-
|
|||||||
import getConfigurationFileModelInjectable from "../../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
import getConfigurationFileModelInjectable from "../../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
||||||
import loggerInjectable from "../../../common/logger.injectable";
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
import storeMigrationVersionInjectable from "../../../common/vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../../../common/vars/store-migration-version.injectable";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../../../common/base-store/channel-prefix";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../../common/base-store/disable-sync";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../../../common/base-store/save-to-file";
|
||||||
|
import getBasenameOfPathInjectable from "../../../common/path/get-basename.injectable";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../../../common/utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
|
||||||
const fileSystemProvisionerStoreInjectable = getInjectable({
|
const fileSystemProvisionerStoreInjectable = getInjectable({
|
||||||
id: "file-system-provisioner-store",
|
id: "file-system-provisioner-store",
|
||||||
@ -26,6 +31,11 @@ const fileSystemProvisionerStoreInjectable = getInjectable({
|
|||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: {},
|
migrations: {},
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,11 @@ import getConfigurationFileModelInjectable from "../common/get-configuration-fil
|
|||||||
import loggerInjectable from "../common/logger.injectable";
|
import loggerInjectable from "../common/logger.injectable";
|
||||||
import storeMigrationVersionInjectable from "../common/vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../common/vars/store-migration-version.injectable";
|
||||||
import type { Migrations } from "conf/dist/source/types";
|
import type { Migrations } from "conf/dist/source/types";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../common/base-store/channel-prefix";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../common/base-store/disable-sync";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../common/base-store/save-to-file";
|
||||||
|
import getBasenameOfPathInjectable from "../common/path/get-basename.injectable";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../common/utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
|
||||||
export interface ExtensionStoreParams<T extends object> extends BaseStoreParams<T> {
|
export interface ExtensionStoreParams<T extends object> extends BaseStoreParams<T> {
|
||||||
migrations?: Migrations<T>;
|
migrations?: Migrations<T>;
|
||||||
@ -53,6 +58,11 @@ export abstract class ExtensionStore<T extends object> extends BaseStore<T> {
|
|||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: migrations as Migrations<Record<string, unknown>>,
|
migrations: migrations as Migrations<Record<string, unknown>>,
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}, params);
|
}, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../../common/base-store/channel-prefix";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../common/base-store/disable-sync";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../../common/base-store/save-to-file";
|
||||||
import getConfigurationFileModelInjectable from "../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
import getConfigurationFileModelInjectable from "../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
||||||
import loggerInjectable from "../../common/logger.injectable";
|
import loggerInjectable from "../../common/logger.injectable";
|
||||||
|
import getBasenameOfPathInjectable from "../../common/path/get-basename.injectable";
|
||||||
|
import { enlistMessageChannelListenerInjectionToken } from "../../common/utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
import storeMigrationVersionInjectable from "../../common/vars/store-migration-version.injectable";
|
import storeMigrationVersionInjectable from "../../common/vars/store-migration-version.injectable";
|
||||||
import { ExtensionsStore } from "./extensions-store";
|
import { ExtensionsStore } from "./extensions-store";
|
||||||
|
|
||||||
@ -17,6 +22,11 @@ const extensionsStoreInjectable = getInjectable({
|
|||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
|
||||||
migrations: {},
|
migrations: {},
|
||||||
|
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||||
|
ipcChannelPrefix: di.inject(baseStoreIpcChannelPrefixInjectionToken),
|
||||||
|
persistStateToConfig: di.inject(persistStateToConfigInjectionToken),
|
||||||
|
enlistMessageChannelListener: di.inject(enlistMessageChannelListenerInjectionToken),
|
||||||
|
shouldDisableSyncInListener: di.inject(shouldBaseStoreDisableSyncInIpcListenerInjectionToken),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../common/base-store/disable-sync";
|
||||||
|
|
||||||
|
const shouldBaseStoreDisableSyncInIpcListenerInjectable = getInjectable({
|
||||||
|
id: "should-base-store-disable-sync-in-ipc-listener",
|
||||||
|
instantiate: () => false,
|
||||||
|
injectionToken: shouldBaseStoreDisableSyncInIpcListenerInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default shouldBaseStoreDisableSyncInIpcListenerInjectable;
|
||||||
14
src/main/base-store/ipc-channel-prefix.injectable.ts
Normal file
14
src/main/base-store/ipc-channel-prefix.injectable.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../../common/base-store/channel-prefix";
|
||||||
|
|
||||||
|
const baseStoreIpcChannelPrefixInjectable = getInjectable({
|
||||||
|
id: "base-store-ipc-channel-prefix",
|
||||||
|
instantiate: () => "store-sync-main",
|
||||||
|
injectionToken: baseStoreIpcChannelPrefixInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default baseStoreIpcChannelPrefixInjectable;
|
||||||
25
src/main/base-store/persist-state-to-config.injectable.ts
Normal file
25
src/main/base-store/persist-state-to-config.injectable.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../../common/base-store/save-to-file";
|
||||||
|
import loggerInjectable from "../../common/logger.injectable";
|
||||||
|
|
||||||
|
const persistStateToConfigInjectable = getInjectable({
|
||||||
|
id: "persist-state-to-config",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const logger = di.inject(loggerInjectable);
|
||||||
|
|
||||||
|
return (config, state) => {
|
||||||
|
logger.info(`[BASE-STORE]: saving ${config.path}...`);
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(state)) {
|
||||||
|
config.set(key, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: persistStateToConfigInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default persistStateToConfigInjectable;
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../common/base-store/disable-sync";
|
||||||
|
|
||||||
|
const shouldBaseStoreDisableSyncInIpcListenerInjectable = getInjectable({
|
||||||
|
id: "should-base-store-disable-sync-in-ipc-listener",
|
||||||
|
instantiate: () => true,
|
||||||
|
injectionToken: shouldBaseStoreDisableSyncInIpcListenerInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default shouldBaseStoreDisableSyncInIpcListenerInjectable;
|
||||||
14
src/renderer/base-store/ipc-channel-prefix.injectable.ts
Normal file
14
src/renderer/base-store/ipc-channel-prefix.injectable.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { baseStoreIpcChannelPrefixInjectionToken } from "../../common/base-store/channel-prefix";
|
||||||
|
|
||||||
|
const baseStoreIpcChannelPrefixInjectable = getInjectable({
|
||||||
|
id: "base-store-ipc-channel-prefix",
|
||||||
|
instantiate: () => "store-sync-renderer",
|
||||||
|
injectionToken: baseStoreIpcChannelPrefixInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default baseStoreIpcChannelPrefixInjectable;
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { persistStateToConfigInjectionToken } from "../../common/base-store/save-to-file";
|
||||||
|
import { noop } from "../utils";
|
||||||
|
|
||||||
|
const persistStateToConfigInjectable = getInjectable({
|
||||||
|
id: "persist-state-to-config",
|
||||||
|
instantiate: () => noop,
|
||||||
|
injectionToken: persistStateToConfigInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default persistStateToConfigInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user