summaryrefslogtreecommitdiff
path: root/src/client/app/init.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-22 17:28:21 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-22 17:28:21 +0900
commit08b8d829f9514fc2cb7a7e5da88831e2a9e376f4 (patch)
treee71257e3888d965269c01c46420582f1473681e6 /src/client/app/init.ts
parentCW (diff)
downloadsharkey-08b8d829f9514fc2cb7a7e5da88831e2a9e376f4.tar.gz
sharkey-08b8d829f9514fc2cb7a7e5da88831e2a9e376f4.tar.bz2
sharkey-08b8d829f9514fc2cb7a7e5da88831e2a9e376f4.zip
ダークモード情報をアカウントではなくブラウザに保存するように
Diffstat (limited to 'src/client/app/init.ts')
-rw-r--r--src/client/app/init.ts45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/client/app/init.ts b/src/client/app/init.ts
index 461093488d..2f79e6cab1 100644
--- a/src/client/app/init.ts
+++ b/src/client/app/init.ts
@@ -61,39 +61,44 @@ Vue.mixin({
});
// Dark/Light
+const bus = new Vue();
Vue.mixin({
data() {
return {
- _darkmode_: false
+ _darkmode_: localStorage.getItem('darkmode') == 'true'
};
},
beforeCreate() {
- // なぜか警告が出るため
- this._darkmode_ = false;
+ // なぜか警告が出るので
+ this._darkmode_ = localStorage.getItem('darkmode') == 'true';
+ },
+ beforeDestroy() {
+ bus.$off('updated', this._onDarkmodeUpdated_);
},
mounted() {
- const set = () => {
- if (!this.$el || !this.$el.setAttribute || !this.os || !this.os.i) return;
- if (this.os.i.clientSettings.dark) {
+ this._onDarkmodeUpdated_(this._darkmode_);
+ bus.$on('updated', this._onDarkmodeUpdated_);
+ },
+ methods: {
+ _updateDarkmode_(v) {
+ localStorage.setItem('darkmode', v.toString());
+ bus.$emit('updated', v);
+ if (v) {
document.documentElement.setAttribute('data-darkmode', 'true');
- this.$el.setAttribute('data-darkmode', 'true');
- this._darkmode_ = true;
- this.$forceUpdate();
} else {
document.documentElement.removeAttribute('data-darkmode');
+ }
+ },
+ _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_ = false;
- this.$forceUpdate();
}
- };
-
- set();
-
- this.$watch('os.i.clientSettings', i => {
- set();
- }, {
- deep: true
- });
+ this._darkmode_ = v;
+ this.$forceUpdate();
+ }
}
});