This commit is contained in:
syuilo 2018-05-24 05:28:46 +09:00
parent b320d08a5e
commit 89461c598f
12 changed files with 79 additions and 73 deletions

View file

@ -18,6 +18,14 @@
return; return;
} }
//#region Load settings
let settings = null;
const vuex = localStorage.getItem('vuex');
if (vuex) {
settings = JSON.parse(vuex);
}
//#endregion
// Get the current url information // Get the current url information
const url = new URL(location.href); const url = new URL(location.href);
@ -35,10 +43,8 @@
// The default language is English // The default language is English
if (!LANGS.includes(lang)) lang = 'en'; if (!LANGS.includes(lang)) lang = 'en';
const vuex = localStorage.getItem('vuex'); if (settings) {
if (vuex) { if (settings.device.lang) lang = settings.device.lang;
const data = JSON.parse(vuex);
if (data.device.lang) lang = data.device.lang;
} }
//#endregion //#endregion
@ -68,9 +74,11 @@
} }
// Dark/Light // Dark/Light
if (localStorage.getItem('darkmode') == 'true') { if (settings) {
if (settings.device.darkmode) {
document.documentElement.setAttribute('data-darkmode', 'true'); document.documentElement.setAttribute('data-darkmode', 'true');
} }
}
// Script version // Script version
const ver = localStorage.getItem('v') || VERSION; const ver = localStorage.getItem('v') || VERSION;

View file

@ -227,8 +227,7 @@ export default Vue.extend({
version, version,
langs, langs,
latestVersion: undefined, latestVersion: undefined,
checkingForUpdate: false, checkingForUpdate: false
darkmode: localStorage.getItem('darkmode') == 'true'
}; };
}, },
computed: { computed: {
@ -246,6 +245,11 @@ export default Vue.extend({
set(value) { this.$store.commit('device/set', { key: 'autoPopout', value }); } set(value) { this.$store.commit('device/set', { key: 'autoPopout', value }); }
}, },
darkmode: {
get() { return this.$store.state.device.darkmode; },
set(value) { this.$store.commit('device/set', { key: 'darkmode', value }); }
},
enableSounds: { enableSounds: {
get() { return this.$store.state.device.enableSounds; }, get() { return this.$store.state.device.enableSounds; },
set(value) { this.$store.commit('device/set', { key: 'enableSounds', value }); } set(value) { this.$store.commit('device/set', { key: 'enableSounds', value }); }
@ -276,11 +280,6 @@ export default Vue.extend({
set(value) { this.$store.commit('device/set', { key: 'enableExperimentalFeatures', value }); } set(value) { this.$store.commit('device/set', { key: 'enableExperimentalFeatures', value }); }
} }
}, },
watch: {
darkmode() {
(this as any)._updateDarkmode_(this.darkmode);
}
},
created() { created() {
(this as any).os.getMeta().then(meta => { (this as any).os.getMeta().then(meta => {
this.meta = meta; this.meta = meta;

View file

@ -35,7 +35,7 @@
</ul> </ul>
<ul> <ul>
<li @click="dark"> <li @click="dark">
<p><span>%i18n:@dark%</span><template v-if="_darkmode_">%fa:moon%</template><template v-else>%fa:R moon%</template></p> <p><span>%i18n:@dark%</span><template v-if="$store.state.device.darkmode">%fa:moon%</template><template v-else>%fa:R moon%</template></p>
</li> </li>
</ul> </ul>
</div> </div>
@ -99,7 +99,10 @@ export default Vue.extend({
(this as any).os.signout(); (this as any).os.signout();
}, },
dark() { dark() {
(this as any)._updateDarkmode_(!(this as any)._darkmode_); this.$store.commit('device/set', {
key: 'darkmode',
value: !this.$store.state.device.darkmode
});
} }
} }
}); });

View file

@ -2,7 +2,7 @@
<mk-window ref="window" is-modal width="450px" height="500px" @closed="$destroy"> <mk-window ref="window" is-modal width="450px" height="500px" @closed="$destroy">
<span slot="header">%fa:list% リスト</span> <span slot="header">%fa:list% リスト</span>
<div data-id="6e4caea3-d8f9-4ab7-96de-ab67fe8d5c82" :data-darkmode="_darkmode_"> <div data-id="6e4caea3-d8f9-4ab7-96de-ab67fe8d5c82" :data-darkmode="$store.state.device.darkmode">
<button class="ui" @click="add">%i18n:@create-list%</button> <button class="ui" @click="add">%i18n:@create-list%</button>
<a v-for="list in lists" :key="list.id" @click="choice(list)">{{ list.title }}</a> <a v-for="list in lists" :key="list.id" @click="choice(list)">{{ list.title }}</a>
</div> </div>

View file

@ -1,11 +1,11 @@
<template> <template>
<div class="mk-welcome"> <div class="mk-welcome">
<button @click="dark"> <button @click="dark">
<template v-if="_darkmode_">%fa:moon%</template> <template v-if="$store.state.device.darkmode">%fa:moon%</template>
<template v-else>%fa:R moon%</template> <template v-else>%fa:R moon%</template>
</button> </button>
<main> <main>
<img :src="_darkmode_ ? 'assets/title-dark.svg' : 'assets/title.svg'" alt="Misskey"> <img :src="$store.state.device.darkmode ? 'assets/title-dark.svg' : 'assets/title.svg'" alt="Misskey">
<p><button class="signup" @click="signup">%i18n:@signup-button%</button><button class="signin" @click="signin">%i18n:@signin-button%</button></p> <p><button class="signup" @click="signup">%i18n:@signup-button%</button><button class="signin" @click="signin">%i18n:@signin-button%</button></p>
<div class="tl"> <div class="tl">
@ -50,7 +50,6 @@ export default Vue.extend({
this.$modal.show('signin'); this.$modal.show('signin');
}, },
dark() { dark() {
(this as any)._updateDarkmode_(!(this as any)._darkmode_);
} }
} }
}); });

View file

@ -4,7 +4,7 @@
<template slot="header">%fa:chart-pie%%i18n:@title%</template> <template slot="header">%fa:chart-pie%%i18n:@title%</template>
<button slot="func" title="%i18n:@refresh%" @click="fetch">%fa:sync%</button> <button slot="func" title="%i18n:@refresh%" @click="fetch">%fa:sync%</button>
<div class="mkw-polls--body" :data-darkmode="_darkmode_"> <div class="mkw-polls--body" :data-darkmode="$store.state.device.darkmode">
<div class="poll" v-if="!fetching && poll != null"> <div class="poll" v-if="!fetching && poll != null">
<p v-if="poll.text"><router-link to="poll | notePage">{{ poll.text }}</router-link></p> <p v-if="poll.text"><router-link to="poll | notePage">{{ poll.text }}</router-link></p>
<p v-if="!poll.text"><router-link to="poll | notePage">%fa:link%</router-link></p> <p v-if="!poll.text"><router-link to="poll | notePage">%fa:link%</router-link></p>

View file

@ -49,48 +49,6 @@ Vue.mixin({
} }
}); });
// Dark/Light
const bus = new Vue();
Vue.mixin({
data() {
return {
_darkmode_: localStorage.getItem('darkmode') == 'true'
};
},
beforeCreate() {
// なぜか警告が出るので
this._darkmode_ = localStorage.getItem('darkmode') == 'true';
},
beforeDestroy() {
bus.$off('updated', this._onDarkmodeUpdated_);
},
mounted() {
this._onDarkmodeUpdated_(this._darkmode_);
bus.$on('updated', this._onDarkmodeUpdated_);
},
methods: {
_updateDarkmode_(v) {
localStorage.setItem('darkmode', v.toString());
if (v) {
document.documentElement.setAttribute('data-darkmode', 'true');
} else {
document.documentElement.removeAttribute('data-darkmode');
}
bus.$emit('updated', v);
},
_onDarkmodeUpdated_(v) {
if (!this.$el || !this.$el.setAttribute) return;
if (v) {
this.$el.setAttribute('data-darkmode', 'true');
} else {
this.$el.removeAttribute('data-darkmode');
}
this._darkmode_ = v;
this.$forceUpdate();
}
}
});
/** /**
* APP ENTRY POINT! * APP ENTRY POINT!
*/ */
@ -141,6 +99,43 @@ export default (callback: (launch: (router: VueRouter, api?: (os: MiOS) => API)
const launch = (router: VueRouter, api?: (os: MiOS) => API) => { const launch = (router: VueRouter, api?: (os: MiOS) => API) => {
os.apis = api ? api(os) : null; os.apis = api ? api(os) : null;
//#region Dark/Light
Vue.mixin({
data() {
_unwatchDarkmode_: null
},
created() {
const apply = v => {
if (this.$el.setAttribute == null) return;
if (v) {
this.$el.setAttribute('data-darkmode', 'true');
} else {
this.$el.removeAttribute('data-darkmode');
}
};
this.$nextTick(() => apply(os.store.state.device.darkmode));
this._unwatchDarkmode_ = os.store.watch(s => {
return s.device.darkmode;
}, apply);
},
beforeDestroy() {
this._unwatchDarkmode_();
}
});
os.store.watch(s => {
return s.device.darkmode;
}, v => {
if (v) {
document.documentElement.setAttribute('data-darkmode', 'true');
} else {
document.documentElement.removeAttribute('data-darkmode');
}
});
//#endregion
Vue.mixin({ Vue.mixin({
data() { data() {
return { return {

View file

@ -29,7 +29,7 @@
</ul> </ul>
<ul> <ul>
<li><router-link to="/i/settings" :data-active="$route.name == 'settings'">%fa:cog%%i18n:@settings%%fa:angle-right%</router-link></li> <li><router-link to="/i/settings" :data-active="$route.name == 'settings'">%fa:cog%%i18n:@settings%%fa:angle-right%</router-link></li>
<li @click="dark"><p><template v-if="_darkmode_">%fa:moon%</template><template v-else>%fa:R moon%</template><span>ダークモード</span></p></li> <li @click="dark"><p><template v-if="$store.state.device.darkmode">%fa:moon%</template><template v-else>%fa:R moon%</template><span>ダークモード</span></p></li>
</ul> </ul>
</div> </div>
<a :href="aboutUrl"><p class="about">%i18n:@about%</p></a> <a :href="aboutUrl"><p class="about">%i18n:@about%</p></a>
@ -117,7 +117,10 @@ export default Vue.extend({
this.hasGameInvitations = false; this.hasGameInvitations = false;
}, },
dark() { dark() {
(this as any)._updateDarkmode_(!(this as any)._darkmode_); this.$store.commit('device/set', {
key: 'darkmode',
value: !this.$store.state.device.darkmode
});
} }
} }
}); });

View file

@ -17,7 +17,7 @@
<button @click="fn">%fa:pencil-alt%</button> <button @click="fn">%fa:pencil-alt%</button>
</template> </template>
<main :data-darkmode="_darkmode_"> <main :data-darkmode="$store.state.device.darkmode">
<div class="nav" v-if="showNav"> <div class="nav" v-if="showNav">
<div class="bg" @click="showNav = false"></div> <div class="bg" @click="showNav = false"></div>
<div class="body"> <div class="body">

View file

@ -141,7 +141,6 @@ export default Vue.extend({
version, version,
codename, codename,
langs, langs,
darkmode: localStorage.getItem('darkmode') == 'true',
latestVersion: undefined, latestVersion: undefined,
checkingForUpdate: false checkingForUpdate: false
}; };
@ -152,6 +151,11 @@ export default Vue.extend({
return Vue.filter('userName')((this as any).os.i); return Vue.filter('userName')((this as any).os.i);
}, },
darkmode: {
get() { return this.$store.state.device.darkmode; },
set(value) { this.$store.commit('device/set', { key: 'darkmode', value }); }
},
postStyle: { postStyle: {
get() { return this.$store.state.device.postStyle; }, get() { return this.$store.state.device.postStyle; },
set(value) { this.$store.commit('device/set', { key: 'postStyle', value }); } set(value) { this.$store.commit('device/set', { key: 'postStyle', value }); }
@ -168,12 +172,6 @@ export default Vue.extend({
}, },
}, },
watch: {
darkmode() {
(this as any)._updateDarkmode_(this.darkmode);
}
},
mounted() { mounted() {
document.title = 'Misskey | %i18n:@settings%'; document.title = 'Misskey | %i18n:@settings%';
}, },

View file

@ -1,7 +1,7 @@
<template> <template>
<mk-ui> <mk-ui>
<template slot="header" v-if="!fetching"><img :src="`${user.avatarUrl}?thumbnail&size=64`" alt="">{{ user | userName }}</template> <template slot="header" v-if="!fetching"><img :src="`${user.avatarUrl}?thumbnail&size=64`" alt="">{{ user | userName }}</template>
<main v-if="!fetching" :data-darkmode="_darkmode_"> <main v-if="!fetching" :data-darkmode="$store.state.device.darkmode">
<div class="is-suspended" v-if="user.isSuspended"><p>%fa:exclamation-triangle% %i18n:@is-suspended%</p></div> <div class="is-suspended" v-if="user.isSuspended"><p>%fa:exclamation-triangle% %i18n:@is-suspended%</p></div>
<div class="is-remote" v-if="user.host != null"><p>%fa:exclamation-triangle% %i18n:@is-remote%<a :href="user.url || user.uri" target="_blank">%i18n:@view-remote%</a></p></div> <div class="is-remote" v-if="user.host != null"><p>%fa:exclamation-triangle% %i18n:@is-remote%<a :href="user.url || user.uri" target="_blank">%i18n:@view-remote%</a></p></div>
<header> <header>

View file

@ -19,6 +19,7 @@ const defaultSettings = {
const defaultDeviceSettings = { const defaultDeviceSettings = {
apiViaStream: true, apiViaStream: true,
autoPopout: false, autoPopout: false,
darkmode: false,
enableSounds: true, enableSounds: true,
soundVolume: 0.5, soundVolume: 0.5,
lang: null, lang: null,