diff --git a/src/common/user-store.ts b/src/common/user-store.ts index d7ba191ee1..15a9ad227c 100644 --- a/src/common/user-store.ts +++ b/src/common/user-store.ts @@ -1,3 +1,4 @@ +import path from "path" import { app, remote } from "electron" import { computed, observable, reaction, toJS } from "mobx"; import Config from "conf" @@ -6,6 +7,7 @@ import migrations from "../migrations/user-store" import Singleton from "./utils/singleton"; import { getAppVersion } from "./utils/app-version"; import { tracker } from "./tracker"; +import logger from "../main/logger"; export interface UserStoreModel { lastSeenAppVersion: string; @@ -34,6 +36,10 @@ export class UserStore extends Singleton { downloadMirror: "default", }; + get name() { + return path.dirname(this.storeConfig.path); + } + @computed get hasNewAppVersion() { return semver.gt(getAppVersion(), this.lastSeenAppVersion); } @@ -44,7 +50,7 @@ export class UserStore extends Singleton { } async init() { - /*await*/ this.load(); + await this.load(); this.bindEvents(); this.isReady = true; } @@ -59,6 +65,7 @@ export class UserStore extends Singleton { configName: "lens-user-store", migrations: migrations, cwd: (app || remote.app).getPath("userData"), + watch: true, // enable onDidChange()-callback }); this.fromStore(this.storeConfig.store); } @@ -66,11 +73,13 @@ export class UserStore extends Singleton { protected bindEvents() { // refresh from file-system updates this.storeConfig.onDidAnyChange((data, oldValue) => { + logger.debug(`[STORE]: ${this.name} sync from file-system`, { data, oldValue }); this.fromStore(data); }); // refresh config file from runtime reaction(() => this.toJSON(), model => { + logger.debug(`[STORE]: ${this.name} sync from app-runtime`, model); this.storeConfig.store = model; }); @@ -80,7 +89,7 @@ export class UserStore extends Singleton { }); } - // todo: use "serializr" ? + // todo: maybe use "serializr" protected fromStore(data: Partial = {}) { const { lastSeenAppVersion, seenContexts, preferences } = data if (lastSeenAppVersion) {