mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
user-store: more fixes 2
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
397d7c5137
commit
9244e8f58e
@ -1,6 +1,6 @@
|
||||
import path from "path"
|
||||
import { app, remote } from "electron"
|
||||
import { computed, observable, reaction, toJS } from "mobx";
|
||||
import { observable, reaction, toJS } from "mobx";
|
||||
import Config from "conf"
|
||||
import semver from "semver"
|
||||
import migrations from "../migrations/user-store"
|
||||
@ -40,31 +40,36 @@ export class UserStore extends Singleton {
|
||||
return path.basename(this.storeConfig.path);
|
||||
}
|
||||
|
||||
@computed get hasNewAppVersion() {
|
||||
get hasNewAppVersion() {
|
||||
return semver.gt(getAppVersion(), this.lastSeenAppVersion);
|
||||
}
|
||||
|
||||
get storeModel() {
|
||||
const storeModel = { ...this.storeConfig.store };
|
||||
Reflect.deleteProperty(storeModel, "__internal__"); // fixme: avoid "external-internals"
|
||||
return storeModel;
|
||||
}
|
||||
|
||||
saveLastSeenAppVersion() {
|
||||
this.lastSeenAppVersion = getAppVersion();
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
this.init();
|
||||
}
|
||||
|
||||
async init() {
|
||||
/*await*/ this.load();
|
||||
protected async init() {
|
||||
await this.load();
|
||||
this.bindEvents();
|
||||
this.isReady = true;
|
||||
}
|
||||
|
||||
saveLastSeenAppVersion() {
|
||||
this.lastSeenAppVersion = getAppVersion();
|
||||
}
|
||||
|
||||
// todo: use "conf" as pseudo-async for more future-proof usages
|
||||
protected async load() {
|
||||
this.storeConfig = new Config<UserStoreModel>({
|
||||
configName: "lens-user-store",
|
||||
migrations: migrations,
|
||||
cwd: (app || remote.app).getPath("userData"),
|
||||
cwd: (app || remote.app).getPath("userData"), // todo: move to main process + with ipc.invoke
|
||||
watch: true, // enable onDidChange()-callback
|
||||
});
|
||||
const data = this.storeConfig.store;
|
||||
@ -76,16 +81,22 @@ export class UserStore extends Singleton {
|
||||
// refresh from file-system updates
|
||||
this.storeConfig.onDidAnyChange((data, oldValue) => {
|
||||
if (!isEqual(this.toJSON(), data)) {
|
||||
console.info(`[STORE]: [UPDATE] ${this.name} from file-system`, { data, oldValue });
|
||||
console.info(`[STORE]: [UPDATE] from ${this.name}`, { data, oldValue });
|
||||
this.fromStore(data);
|
||||
}
|
||||
});
|
||||
|
||||
// refresh config file from runtime
|
||||
reaction(() => this.toJSON(), model => {
|
||||
if (!isEqual(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
|
||||
reaction(() => this.toJSON(), (model: UserStoreModel) => {
|
||||
if (!isEqual(this.storeModel, model)) {
|
||||
console.info(`[STORE]: [SAVE] ${this.name} from runtime update`, {
|
||||
data: model,
|
||||
oldValue: this.storeModel
|
||||
});
|
||||
// fixme: https://github.com/sindresorhus/conf/issues/114
|
||||
Object.entries(model).forEach(([key, value]) => {
|
||||
this.storeConfig.set(key, value);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -114,6 +125,8 @@ export class UserStore extends Singleton {
|
||||
lastSeenAppVersion: this.lastSeenAppVersion,
|
||||
seenContexts: Array.from(this.seenContexts),
|
||||
preferences: this.preferences,
|
||||
}, {
|
||||
recurseEverything: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import path from "path";
|
||||
import Config from "conf";
|
||||
import { isTestEnv } from "../common/vars";
|
||||
|
||||
@ -15,8 +14,7 @@ function infoLog(...args: any[]) {
|
||||
export function migration<S = any>({ version, run }: MigrationOpts) {
|
||||
return {
|
||||
[version]: (storeConfig: Config<S>) => {
|
||||
const storeName = path.dirname(storeConfig.path);
|
||||
infoLog(`STORE MIGRATION (${storeName}): ${version}`,);
|
||||
infoLog(`STORE MIGRATION (${storeConfig.path}): ${version}`,);
|
||||
run(storeConfig, infoLog);
|
||||
}
|
||||
};
|
||||
|
||||
@ -30,6 +30,8 @@
|
||||
import marked from 'marked'
|
||||
import {readFileSync} from 'fs'
|
||||
import { getStaticPath } from "../../../common/register-static"
|
||||
import { userStore } from "../../../common/user-store"
|
||||
import { tracker } from "../../../common/tracker"
|
||||
|
||||
export default {
|
||||
name: 'WhatsNewPage',
|
||||
@ -46,7 +48,11 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
toLanding: async function() {
|
||||
await this.$store.dispatch("updateLastSeenAppVersion")
|
||||
if(userStore.hasNewAppVersion) {
|
||||
userStore.saveLastSeenAppVersion();
|
||||
tracker.event("app", "whats-new-seen")
|
||||
}
|
||||
// await this.$store.dispatch("updateLastSeenAppVersion")
|
||||
this.$router.push({
|
||||
name: "landing-page",
|
||||
}).catch(err => {})
|
||||
|
||||
@ -9,6 +9,8 @@ import BootstrapVue from 'bootstrap-vue'
|
||||
import App from './App'
|
||||
import router from './router'
|
||||
import store from './store'
|
||||
import { userStore } from "../../common/user-store"
|
||||
import { when } from "mobx"
|
||||
|
||||
const promiseIpc = new PromiseIpc({maxTimeoutMs: 6000});
|
||||
|
||||
@ -27,17 +29,15 @@ Vue.mixin({
|
||||
})
|
||||
|
||||
// any initialization we want to do for app state
|
||||
setTimeout(() => {
|
||||
store.dispatch('init', ).catch((error) => {
|
||||
console.error(error)
|
||||
}).finally(() => {
|
||||
/* eslint-disable no-new */
|
||||
console.log("start vue")
|
||||
new Vue({
|
||||
components: { App },
|
||||
store,
|
||||
router,
|
||||
template: '<App/>'
|
||||
}).$mount('#app')
|
||||
})
|
||||
}, 0)
|
||||
setTimeout(async () => {
|
||||
await when(() => userStore.isReady);
|
||||
|
||||
await store.dispatch('init')
|
||||
console.log("start vue")
|
||||
new Vue({
|
||||
components: { App },
|
||||
store,
|
||||
router,
|
||||
template: '<App/>'
|
||||
}).$mount('#app')
|
||||
})
|
||||
|
||||
@ -1,23 +1,7 @@
|
||||
export function auth ( to, from, store ) {
|
||||
if(!store.getters.isLoggedIn){
|
||||
console.log("router: guard: auth: activated");
|
||||
return {
|
||||
path: '/login'
|
||||
}
|
||||
}
|
||||
}
|
||||
import { userStore } from "../../../../common/user-store"
|
||||
|
||||
export function eula ( to, from, store ) {
|
||||
if(!store.getters.isEulaAccepted){
|
||||
console.log("router: guard: eula: activated");
|
||||
return {
|
||||
path: '/accept-eula'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function whatsNew( to, from, store ) {
|
||||
if(store.getters.showWhatsNew){
|
||||
export function whatsNew() {
|
||||
if(userStore.hasNewAppVersion){
|
||||
console.log("router: guard: whatsNew: activated");
|
||||
return {
|
||||
path: '/whats-new'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user