2018-04-29 03:17:15 -05:00
|
|
|
import Vuex from 'vuex';
|
2018-05-20 12:13:39 -05:00
|
|
|
import createPersistedState from 'vuex-persistedstate';
|
|
|
|
|
2018-04-29 07:37:51 -05:00
|
|
|
import MiOS from './mios';
|
2018-05-26 23:49:09 -05:00
|
|
|
import { hostname } from './config';
|
2018-04-29 03:17:15 -05:00
|
|
|
|
|
|
|
const defaultSettings = {
|
2018-06-05 13:03:56 -05:00
|
|
|
home: null,
|
2018-05-17 02:24:01 -05:00
|
|
|
mobileHome: [],
|
2018-06-05 12:48:26 -05:00
|
|
|
deck: {
|
|
|
|
columns: [/*{
|
|
|
|
type: 'widgets',
|
|
|
|
widgets: []
|
|
|
|
}, */{
|
|
|
|
type: 'home'
|
|
|
|
}, {
|
|
|
|
type: 'notifications'
|
|
|
|
}, {
|
|
|
|
type: 'local'
|
|
|
|
}, {
|
|
|
|
type: 'global'
|
|
|
|
}]
|
|
|
|
},
|
2018-04-29 03:17:15 -05:00
|
|
|
fetchOnScroll: true,
|
|
|
|
showMaps: true,
|
|
|
|
showPostFormOnTopOfTl: false,
|
|
|
|
circleIcons: true,
|
|
|
|
gradientWindowHeader: false,
|
|
|
|
showReplyTarget: true,
|
|
|
|
showMyRenotes: true,
|
2018-05-25 06:19:14 -05:00
|
|
|
showRenotedMyNotes: true,
|
|
|
|
loadRemoteMedia: true,
|
2018-05-27 08:39:20 -05:00
|
|
|
disableViaMobile: false,
|
|
|
|
memo: null
|
2018-04-29 03:17:15 -05:00
|
|
|
};
|
|
|
|
|
2018-05-20 12:13:39 -05:00
|
|
|
const defaultDeviceSettings = {
|
|
|
|
apiViaStream: true,
|
|
|
|
autoPopout: false,
|
2018-05-23 15:28:46 -05:00
|
|
|
darkmode: false,
|
2018-05-20 12:13:39 -05:00
|
|
|
enableSounds: true,
|
|
|
|
soundVolume: 0.5,
|
|
|
|
lang: null,
|
|
|
|
preventUpdate: false,
|
|
|
|
debug: false,
|
|
|
|
lightmode: false,
|
2018-05-25 06:19:14 -05:00
|
|
|
loadRawImages: false,
|
2018-05-20 13:08:51 -05:00
|
|
|
postStyle: 'standard'
|
2018-05-20 12:13:39 -05:00
|
|
|
};
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
export default (os: MiOS) => new Vuex.Store({
|
2018-05-26 23:49:09 -05:00
|
|
|
plugins: [createPersistedState({
|
|
|
|
paths: ['i', 'device', 'settings']
|
2018-05-20 12:13:39 -05:00
|
|
|
})],
|
2018-04-29 03:17:15 -05:00
|
|
|
|
|
|
|
state: {
|
2018-05-26 23:49:09 -05:00
|
|
|
i: null,
|
2018-05-17 09:53:55 -05:00
|
|
|
indicate: false,
|
2018-04-29 03:17:15 -05:00
|
|
|
uiHeaderHeight: 0
|
|
|
|
},
|
|
|
|
|
2018-05-26 23:49:09 -05:00
|
|
|
getters: {
|
|
|
|
isSignedIn: state => state.i != null
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
mutations: {
|
2018-05-26 23:49:09 -05:00
|
|
|
updateI(state, x) {
|
|
|
|
state.i = x;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateIKeyValue(state, x) {
|
|
|
|
state.i[x.key] = x.value;
|
|
|
|
},
|
|
|
|
|
2018-05-17 09:53:55 -05:00
|
|
|
indicate(state, x) {
|
|
|
|
state.indicate = x;
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
setUiHeaderHeight(state, height) {
|
|
|
|
state.uiHeaderHeight = height;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-26 23:49:09 -05:00
|
|
|
actions: {
|
|
|
|
login(ctx, i) {
|
|
|
|
ctx.commit('updateI', i);
|
|
|
|
ctx.dispatch('settings/merge', i.clientSettings);
|
|
|
|
},
|
|
|
|
|
|
|
|
logout(ctx) {
|
|
|
|
ctx.commit('updateI', null);
|
|
|
|
document.cookie = `i=; domain=${hostname}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
|
|
|
|
},
|
|
|
|
|
|
|
|
mergeMe(ctx, me) {
|
|
|
|
Object.entries(me).forEach(([key, value]) => {
|
|
|
|
ctx.commit('updateIKeyValue', { key, value });
|
|
|
|
});
|
|
|
|
|
|
|
|
if (me.clientSettings) {
|
|
|
|
ctx.dispatch('settings/merge', me.clientSettings);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
modules: {
|
2018-05-20 12:13:39 -05:00
|
|
|
device: {
|
|
|
|
namespaced: true,
|
|
|
|
|
|
|
|
state: defaultDeviceSettings,
|
|
|
|
|
|
|
|
mutations: {
|
|
|
|
set(state, x: { key: string; value: any }) {
|
|
|
|
state[x.key] = x.value;
|
2018-05-26 10:18:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setTl(state, x) {
|
|
|
|
state.tl = {
|
|
|
|
src: x.src,
|
|
|
|
arg: x.arg
|
|
|
|
};
|
2018-05-20 12:13:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
settings: {
|
|
|
|
namespaced: true,
|
|
|
|
|
2018-05-20 12:13:39 -05:00
|
|
|
state: defaultSettings,
|
2018-04-29 03:17:15 -05:00
|
|
|
|
|
|
|
mutations: {
|
|
|
|
set(state, x: { key: string; value: any }) {
|
2018-05-20 12:13:39 -05:00
|
|
|
state[x.key] = x.value;
|
2018-04-29 03:17:15 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setHome(state, data) {
|
2018-05-20 12:13:39 -05:00
|
|
|
state.home = data;
|
2018-04-29 03:17:15 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setHomeWidget(state, x) {
|
2018-05-20 12:13:39 -05:00
|
|
|
const w = state.home.find(w => w.id == x.id);
|
2018-04-29 03:17:15 -05:00
|
|
|
if (w) {
|
|
|
|
w.data = x.data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addHomeWidget(state, widget) {
|
2018-05-20 12:13:39 -05:00
|
|
|
state.home.unshift(widget);
|
2018-05-17 02:24:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setMobileHome(state, data) {
|
2018-05-20 12:13:39 -05:00
|
|
|
state.mobileHome = data;
|
2018-05-17 02:24:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setMobileHomeWidget(state, x) {
|
2018-05-20 12:13:39 -05:00
|
|
|
const w = state.mobileHome.find(w => w.id == x.id);
|
2018-05-17 02:24:01 -05:00
|
|
|
if (w) {
|
|
|
|
w.data = x.data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addMobileHomeWidget(state, widget) {
|
2018-05-20 12:13:39 -05:00
|
|
|
state.mobileHome.unshift(widget);
|
2018-05-17 02:24:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
removeMobileHomeWidget(state, widget) {
|
2018-05-20 12:13:39 -05:00
|
|
|
state.mobileHome = state.mobileHome.filter(w => w.id != widget.id);
|
2018-04-29 03:17:15 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2018-04-29 03:54:50 -05:00
|
|
|
merge(ctx, settings) {
|
2018-06-05 12:48:26 -05:00
|
|
|
if (settings == null) return;
|
2018-04-29 03:54:50 -05:00
|
|
|
Object.entries(settings).forEach(([key, value]) => {
|
|
|
|
ctx.commit('set', { key, value });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
set(ctx, x) {
|
|
|
|
ctx.commit('set', x);
|
|
|
|
|
2018-05-26 23:49:09 -05:00
|
|
|
if (ctx.rootGetters.isSignedIn) {
|
2018-04-29 03:17:15 -05:00
|
|
|
os.api('i/update_client_setting', {
|
|
|
|
name: x.key,
|
|
|
|
value: x.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addHomeWidget(ctx, widget) {
|
|
|
|
ctx.commit('addHomeWidget', widget);
|
|
|
|
|
|
|
|
os.api('i/update_home', {
|
2018-05-20 12:13:39 -05:00
|
|
|
home: ctx.state.home
|
2018-04-29 03:17:15 -05:00
|
|
|
});
|
2018-05-17 02:24:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
addMobileHomeWidget(ctx, widget) {
|
|
|
|
ctx.commit('addMobileHomeWidget', widget);
|
|
|
|
|
|
|
|
os.api('i/update_mobile_home', {
|
2018-05-20 12:13:39 -05:00
|
|
|
home: ctx.state.mobileHome
|
2018-05-17 02:24:01 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMobileHomeWidget(ctx, widget) {
|
|
|
|
ctx.commit('removeMobileHomeWidget', widget);
|
|
|
|
|
|
|
|
os.api('i/update_mobile_home', {
|
2018-05-20 12:13:39 -05:00
|
|
|
home: ctx.state.mobileHome.filter(w => w.id != widget.id)
|
2018-05-17 02:24:01 -05:00
|
|
|
});
|
2018-04-29 03:17:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|