summaryrefslogtreecommitdiff
path: root/src/client/app/init.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-05-24 05:28:46 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-05-24 05:28:46 +0900
commit89461c598f4746287d13dad6fa6d1215cb43c030 (patch)
tree4159971a9b58fa143382a0c91a9c9fede8647a31 /src/client/app/init.ts
parent:art: (diff)
downloadmisskey-89461c598f4746287d13dad6fa6d1215cb43c030.tar.gz
misskey-89461c598f4746287d13dad6fa6d1215cb43c030.tar.bz2
misskey-89461c598f4746287d13dad6fa6d1215cb43c030.zip
Refactor
Diffstat (limited to 'src/client/app/init.ts')
-rw-r--r--src/client/app/init.ts79
1 files changed, 37 insertions, 42 deletions
diff --git a/src/client/app/init.ts b/src/client/app/init.ts
index 34bc6a2785..d764beb3bd 100644
--- a/src/client/app/init.ts
+++ b/src/client/app/init.ts
@@ -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!
*/
@@ -141,6 +99,43 @@ export default (callback: (launch: (router: VueRouter, api?: (os: MiOS) => API)
const launch = (router: VueRouter, api?: (os: MiOS) => API) => {
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({
data() {
return {