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

added "logger" to user-store

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-07-05 20:19:47 +03:00
parent 4270ec4240
commit deea97ec5c

View File

@ -1,3 +1,4 @@
import path from "path"
import { app, remote } from "electron" import { app, remote } from "electron"
import { computed, observable, reaction, toJS } from "mobx"; import { computed, observable, reaction, toJS } from "mobx";
import Config from "conf" import Config from "conf"
@ -6,6 +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";
export interface UserStoreModel { export interface UserStoreModel {
lastSeenAppVersion: string; lastSeenAppVersion: string;
@ -34,6 +36,10 @@ export class UserStore extends Singleton {
downloadMirror: "default", downloadMirror: "default",
}; };
get name() {
return path.dirname(this.storeConfig.path);
}
@computed get hasNewAppVersion() { @computed get hasNewAppVersion() {
return semver.gt(getAppVersion(), this.lastSeenAppVersion); return semver.gt(getAppVersion(), this.lastSeenAppVersion);
} }
@ -44,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;
} }
@ -59,6 +65,7 @@ export class UserStore extends Singleton {
configName: "lens-user-store", configName: "lens-user-store",
migrations: migrations, migrations: migrations,
cwd: (app || remote.app).getPath("userData"), cwd: (app || remote.app).getPath("userData"),
watch: true, // enable onDidChange()-callback
}); });
this.fromStore(this.storeConfig.store); this.fromStore(this.storeConfig.store);
} }
@ -66,11 +73,13 @@ export class UserStore extends Singleton {
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 });
this.fromStore(data); 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);
this.storeConfig.store = 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<UserStoreModel> = {}) { protected fromStore(data: Partial<UserStoreModel> = {}) {
const { lastSeenAppVersion, seenContexts, preferences } = data const { lastSeenAppVersion, seenContexts, preferences } = data
if (lastSeenAppVersion) { if (lastSeenAppVersion) {