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

user-store: more fixes

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-07-05 21:10:31 +03:00
parent 9d42b2c025
commit 397d7c5137

View File

@ -7,7 +7,7 @@ import migrations from "../migrations/user-store"
import Singleton from "./utils/singleton"; import Singleton from "./utils/singleton";
import { getAppVersion } from "./utils/app-version"; import { getAppVersion } from "./utils/app-version";
import { tracker } from "./tracker"; import { tracker } from "./tracker";
import logger from "../main/logger"; import isEqual from "lodash/isEqual"
export interface UserStoreModel { export interface UserStoreModel {
lastSeenAppVersion: string; lastSeenAppVersion: string;
@ -37,7 +37,7 @@ export class UserStore extends Singleton {
}; };
get name() { get name() {
return path.dirname(this.storeConfig.path); return path.basename(this.storeConfig.path);
} }
@computed get hasNewAppVersion() { @computed get hasNewAppVersion() {
@ -50,7 +50,7 @@ export class UserStore extends Singleton {
} }
async init() { async init() {
await this.load(); /*await*/ this.load();
this.bindEvents(); this.bindEvents();
this.isReady = true; this.isReady = true;
} }
@ -68,21 +68,25 @@ export class UserStore extends Singleton {
watch: true, // enable onDidChange()-callback watch: true, // enable onDidChange()-callback
}); });
const data = this.storeConfig.store; const data = this.storeConfig.store;
logger.debug(`[STORE]: ${this.name} loaded with`, data); console.info(`[STORE]: [LOADED] ${this.storeConfig.path}`, data);
this.fromStore(data); this.fromStore(data);
} }
protected bindEvents() { protected bindEvents() {
// refresh from file-system updates // refresh from file-system updates
this.storeConfig.onDidAnyChange((data, oldValue) => { this.storeConfig.onDidAnyChange((data, oldValue) => {
logger.debug(`[STORE]: ${this.name} sync from file-system`, { data, oldValue }); if (!isEqual(this.toJSON(), data)) {
this.fromStore(data); console.info(`[STORE]: [UPDATE] ${this.name} from file-system`, { data, oldValue });
this.fromStore(data);
}
}); });
// refresh config file from runtime // refresh config file from runtime
reaction(() => this.toJSON(), model => { reaction(() => this.toJSON(), model => {
logger.debug(`[STORE]: ${this.name} sync from app-runtime`, model); if (!isEqual(this.storeConfig.store, model)) {
this.storeConfig.store = model; console.info(`[STORE]: [UPDATE] ${this.name} to file-system from runtime model`, model);
this.storeConfig.store = model; // fixme: actual save to fs won't happen
}
}); });
// track telemetry availability // track telemetry availability