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 path from "path"
|
||||||
import { app, remote } from "electron"
|
import { app, remote } from "electron"
|
||||||
import { computed, observable, reaction, toJS } from "mobx";
|
import { observable, reaction, toJS } from "mobx";
|
||||||
import Config from "conf"
|
import Config from "conf"
|
||||||
import semver from "semver"
|
import semver from "semver"
|
||||||
import migrations from "../migrations/user-store"
|
import migrations from "../migrations/user-store"
|
||||||
@ -40,31 +40,36 @@ export class UserStore extends Singleton {
|
|||||||
return path.basename(this.storeConfig.path);
|
return path.basename(this.storeConfig.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get hasNewAppVersion() {
|
get hasNewAppVersion() {
|
||||||
return semver.gt(getAppVersion(), this.lastSeenAppVersion);
|
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() {
|
private constructor() {
|
||||||
super();
|
super();
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
protected async init() {
|
||||||
/*await*/ this.load();
|
await this.load();
|
||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
this.isReady = true;
|
this.isReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveLastSeenAppVersion() {
|
|
||||||
this.lastSeenAppVersion = getAppVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: use "conf" as pseudo-async for more future-proof usages
|
|
||||||
protected async load() {
|
protected async load() {
|
||||||
this.storeConfig = new Config<UserStoreModel>({
|
this.storeConfig = new Config<UserStoreModel>({
|
||||||
configName: "lens-user-store",
|
configName: "lens-user-store",
|
||||||
migrations: migrations,
|
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
|
watch: true, // enable onDidChange()-callback
|
||||||
});
|
});
|
||||||
const data = this.storeConfig.store;
|
const data = this.storeConfig.store;
|
||||||
@ -76,16 +81,22 @@ export class UserStore extends Singleton {
|
|||||||
// refresh from file-system updates
|
// refresh from file-system updates
|
||||||
this.storeConfig.onDidAnyChange((data, oldValue) => {
|
this.storeConfig.onDidAnyChange((data, oldValue) => {
|
||||||
if (!isEqual(this.toJSON(), data)) {
|
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);
|
this.fromStore(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// refresh config file from runtime
|
// refresh config file from runtime
|
||||||
reaction(() => this.toJSON(), model => {
|
reaction(() => this.toJSON(), (model: UserStoreModel) => {
|
||||||
if (!isEqual(this.storeConfig.store, model)) {
|
if (!isEqual(this.storeModel, model)) {
|
||||||
console.info(`[STORE]: [UPDATE] ${this.name} to file-system from runtime model`, model);
|
console.info(`[STORE]: [SAVE] ${this.name} from runtime update`, {
|
||||||
this.storeConfig.store = model; // fixme: actual save to fs won't happen
|
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,
|
lastSeenAppVersion: this.lastSeenAppVersion,
|
||||||
seenContexts: Array.from(this.seenContexts),
|
seenContexts: Array.from(this.seenContexts),
|
||||||
preferences: this.preferences,
|
preferences: this.preferences,
|
||||||
|
}, {
|
||||||
|
recurseEverything: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import path from "path";
|
|
||||||
import Config from "conf";
|
import Config from "conf";
|
||||||
import { isTestEnv } from "../common/vars";
|
import { isTestEnv } from "../common/vars";
|
||||||
|
|
||||||
@ -15,8 +14,7 @@ function infoLog(...args: any[]) {
|
|||||||
export function migration<S = any>({ version, run }: MigrationOpts) {
|
export function migration<S = any>({ version, run }: MigrationOpts) {
|
||||||
return {
|
return {
|
||||||
[version]: (storeConfig: Config<S>) => {
|
[version]: (storeConfig: Config<S>) => {
|
||||||
const storeName = path.dirname(storeConfig.path);
|
infoLog(`STORE MIGRATION (${storeConfig.path}): ${version}`,);
|
||||||
infoLog(`STORE MIGRATION (${storeName}): ${version}`,);
|
|
||||||
run(storeConfig, infoLog);
|
run(storeConfig, infoLog);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
import marked from 'marked'
|
import marked from 'marked'
|
||||||
import {readFileSync} from 'fs'
|
import {readFileSync} from 'fs'
|
||||||
import { getStaticPath } from "../../../common/register-static"
|
import { getStaticPath } from "../../../common/register-static"
|
||||||
|
import { userStore } from "../../../common/user-store"
|
||||||
|
import { tracker } from "../../../common/tracker"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'WhatsNewPage',
|
name: 'WhatsNewPage',
|
||||||
@ -46,7 +48,11 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toLanding: async function() {
|
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({
|
this.$router.push({
|
||||||
name: "landing-page",
|
name: "landing-page",
|
||||||
}).catch(err => {})
|
}).catch(err => {})
|
||||||
|
|||||||
@ -9,6 +9,8 @@ import BootstrapVue from 'bootstrap-vue'
|
|||||||
import App from './App'
|
import App from './App'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import store from './store'
|
import store from './store'
|
||||||
|
import { userStore } from "../../common/user-store"
|
||||||
|
import { when } from "mobx"
|
||||||
|
|
||||||
const promiseIpc = new PromiseIpc({maxTimeoutMs: 6000});
|
const promiseIpc = new PromiseIpc({maxTimeoutMs: 6000});
|
||||||
|
|
||||||
@ -27,17 +29,15 @@ Vue.mixin({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// any initialization we want to do for app state
|
// any initialization we want to do for app state
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
store.dispatch('init', ).catch((error) => {
|
await when(() => userStore.isReady);
|
||||||
console.error(error)
|
|
||||||
}).finally(() => {
|
await store.dispatch('init')
|
||||||
/* eslint-disable no-new */
|
console.log("start vue")
|
||||||
console.log("start vue")
|
new Vue({
|
||||||
new Vue({
|
components: { App },
|
||||||
components: { App },
|
store,
|
||||||
store,
|
router,
|
||||||
router,
|
template: '<App/>'
|
||||||
template: '<App/>'
|
}).$mount('#app')
|
||||||
}).$mount('#app')
|
})
|
||||||
})
|
|
||||||
}, 0)
|
|
||||||
|
|||||||
@ -1,23 +1,7 @@
|
|||||||
export function auth ( to, from, store ) {
|
import { userStore } from "../../../../common/user-store"
|
||||||
if(!store.getters.isLoggedIn){
|
|
||||||
console.log("router: guard: auth: activated");
|
|
||||||
return {
|
|
||||||
path: '/login'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function eula ( to, from, store ) {
|
export function whatsNew() {
|
||||||
if(!store.getters.isEulaAccepted){
|
if(userStore.hasNewAppVersion){
|
||||||
console.log("router: guard: eula: activated");
|
|
||||||
return {
|
|
||||||
path: '/accept-eula'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function whatsNew( to, from, store ) {
|
|
||||||
if(store.getters.showWhatsNew){
|
|
||||||
console.log("router: guard: whatsNew: activated");
|
console.log("router: guard: whatsNew: activated");
|
||||||
return {
|
return {
|
||||||
path: '/whats-new'
|
path: '/whats-new'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user