summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/components/settings.vue
blob: 74ab45626d7182dd096babc4b38ce9f80f0bc664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<template>
<div class="mk-settings">
	<div class="nav">
		<p :class="{ active: page == 'profile' }" @mousedown="page = 'profile'">%fa:user .fw%%i18n:@profile%</p>
		<p :class="{ active: page == 'web' }" @mousedown="page = 'web'">%fa:desktop .fw%Web</p>
		<p :class="{ active: page == 'notification' }" @mousedown="page = 'notification'">%fa:R bell .fw%%i18n:@notification%</p>
		<p :class="{ active: page == 'drive' }" @mousedown="page = 'drive'">%fa:cloud .fw%%i18n:@drive%</p>
		<p :class="{ active: page == 'mute' }" @mousedown="page = 'mute'">%fa:ban .fw%%i18n:@mute%</p>
		<p :class="{ active: page == 'apps' }" @mousedown="page = 'apps'">%fa:puzzle-piece .fw%%i18n:@apps%</p>
		<p :class="{ active: page == 'twitter' }" @mousedown="page = 'twitter'">%fa:B twitter .fw%Twitter</p>
		<p :class="{ active: page == 'security' }" @mousedown="page = 'security'">%fa:unlock-alt .fw%%i18n:@security%</p>
		<p :class="{ active: page == 'api' }" @mousedown="page = 'api'">%fa:key .fw%API</p>
		<p :class="{ active: page == 'other' }" @mousedown="page = 'other'">%fa:cogs .fw%%i18n:@other%</p>
	</div>
	<div class="pages">
		<section class="profile" v-show="page == 'profile'">
			<h1>%i18n:@profile%</h1>
			<x-profile/>
		</section>

		<section class="web" v-show="page == 'web'">
			<h1>%i18n:@behaviour%</h1>
			<mk-switch v-model="$store.state.settings.fetchOnScroll" @change="onChangeFetchOnScroll" text="%i18n:@fetch-on-scroll%">
				<span>%i18n:@fetch-on-scroll-desc%</span>
			</mk-switch>
			<mk-switch v-model="autoPopout" text="%i18n:@auto-popout%">
				<span>%i18n:@auto-popout-desc%</span>
			</mk-switch>
			<details>
				<summary>%i18n:@advanced%</summary>
				<mk-switch v-model="apiViaStream" text="%i18n:@api-via-stream%">
					<span>%i18n:@api-via-stream-desc%</span>
				</mk-switch>
			</details>
		</section>

		<section class="web" v-show="page == 'web'">
			<h1>%i18n:@display%</h1>
			<div class="div">
				<button class="ui button" @click="customizeHome" style="margin-bottom: 16px">%i18n:@customize%</button>
			</div>
			<div class="div">
				<button class="ui" @click="updateWallpaper">%i18n:@choose-wallpaper%</button>
				<button class="ui" @click="deleteWallpaper">%i18n:@delete-wallpaper%</button>
				<mk-switch v-model="darkmode" text="%i18n:@dark-mode%"/>
				<mk-switch v-model="$store.state.settings.circleIcons" @change="onChangeCircleIcons" text="%i18n:@circle-icons%"/>
				<mk-switch v-model="$store.state.settings.gradientWindowHeader" @change="onChangeGradientWindowHeader" text="%i18n:@gradient-window-header%"/>
				<mk-switch v-model="$store.state.settings.iLikeSushi" @change="onChangeILikeSushi" text="%i18n:common.i-like-sushi%"/>
			</div>
			<mk-switch v-model="$store.state.settings.showPostFormOnTopOfTl" @change="onChangeShowPostFormOnTopOfTl" text="%i18n:@post-form-on-timeline%"/>
			<mk-switch v-model="$store.state.settings.showReplyTarget" @change="onChangeShowReplyTarget" text="%i18n:@show-reply-target%"/>
			<mk-switch v-model="$store.state.settings.showMyRenotes" @change="onChangeShowMyRenotes" text="%i18n:@show-my-renotes%"/>
			<mk-switch v-model="$store.state.settings.showRenotedMyNotes" @change="onChangeShowRenotedMyNotes" text="%i18n:@show-renoted-my-notes%"/>
			<mk-switch v-model="$store.state.settings.showMaps" @change="onChangeShowMaps" text="%i18n:@show-maps%">
				<span>%i18n:@show-maps-desc%</span>
			</mk-switch>
			<mk-switch v-model="$store.state.settings.reversiBoardLabels" @change="onChangeReversiBoardLabels" text="%i18n:common.show-reversi-board-labels%"/>
		</section>

		<section class="web" v-show="page == 'web'">
			<h1>%i18n:@sound%</h1>
			<mk-switch v-model="enableSounds" text="%i18n:@enable-sounds%">
				<span>%i18n:@enable-sounds-desc%</span>
			</mk-switch>
			<label>%i18n:@volume%</label>
			<el-slider
				v-model="soundVolume"
				:show-input="true"
				:format-tooltip="v => `${v * 100}%`"
				:disabled="!enableSounds"
				:max="1"
				:step="0.1"
			/>
			<button class="ui button" @click="soundTest">%fa:volume-up% %i18n:@test%</button>
		</section>

		<section class="web" v-show="page == 'web'">
			<h1>%i18n:@mobile%</h1>
			<mk-switch v-model="$store.state.settings.disableViaMobile" @change="onChangeDisableViaMobile" text="%i18n:@disable-via-mobile%"/>
		</section>

		<section class="web" v-show="page == 'web'">
			<h1>%i18n:@language%</h1>
			<el-select v-model="lang" placeholder="%i18n:@pick-language%">
				<el-option-group label="%i18n:@recommended%">
					<el-option label="%i18n:@auto%" :value="null"/>
				</el-option-group>
				<el-option-group label="%i18n:@specify-language%">
					<el-option v-for="x in langs" :label="x[1]" :value="x[0]" :key="x[0]"/>
				</el-option-group>
			</el-select>
			<div class="none ui info">
				<p>%fa:info-circle%%i18n:@language-desc%</p>
			</div>
		</section>

		<section class="web" v-show="page == 'web'">
			<h1>%i18n:@cache%</h1>
			<button class="ui button" @click="clean">%i18n:@clean-cache%</button>
			<div class="none ui info warn">
				<p>%fa:exclamation-triangle%%i18n:@cache-warn%</p>
			</div>
		</section>

		<section class="notification" v-show="page == 'notification'">
			<h1>%i18n:@notification%</h1>
			<mk-switch v-model="$store.state.i.settings.autoWatch" @change="onChangeAutoWatch" text="%i18n:@auto-watch%">
				<span>%i18n:@auto-watch-desc%</span>
			</mk-switch>
		</section>

		<section class="drive" v-show="page == 'drive'">
			<h1>%i18n:@drive%</h1>
			<x-drive/>
		</section>

		<section class="mute" v-show="page == 'mute'">
			<h1>%i18n:@mute%</h1>
			<x-mute/>
		</section>

		<section class="apps" v-show="page == 'apps'">
			<h1>%i18n:@apps%</h1>
			<x-apps/>
		</section>

		<section class="twitter" v-show="page == 'twitter'">
			<h1>Twitter</h1>
			<mk-twitter-setting/>
		</section>

		<section class="password" v-show="page == 'security'">
			<h1>%i18n:@password%</h1>
			<x-password/>
		</section>

		<section class="2fa" v-show="page == 'security'">
			<h1>%i18n:@2fa%</h1>
			<x-2fa/>
		</section>

		<section class="signin" v-show="page == 'security'">
			<h1>%i18n:@signin%</h1>
			<x-signins/>
		</section>

		<section class="api" v-show="page == 'api'">
			<h1>API</h1>
			<x-api/>
		</section>

		<section class="other" v-show="page == 'other'">
			<h1>%i18n:@about%</h1>
			<p v-if="meta">%i18n:@operator%: <i><a :href="meta.maintainer.url" target="_blank">{{ meta.maintainer.name }}</a></i></p>
		</section>

		<section class="other" v-show="page == 'other'">
			<h1>%i18n:@update%</h1>
			<p>
				<span>%i18n:@version% <i>{{ version }}</i></span>
				<template v-if="latestVersion !== undefined">
					<br>
					<span>%i18n:@latest-version% <i>{{ latestVersion ? latestVersion : version }}</i></span>
				</template>
			</p>
			<button class="ui button block" @click="checkForUpdate" :disabled="checkingForUpdate">
				<template v-if="checkingForUpdate">%i18n:@update-checking%<mk-ellipsis/></template>
				<template v-else>%i18n:@do-update%</template>
			</button>
			<details>
				<summary>%i18n:@update-settings%</summary>
				<mk-switch v-model="preventUpdate" text="%i18n:@prevent-update%">
					<span>%i18n:@prevent-update-desc%</span>
				</mk-switch>
			</details>
		</section>

		<section class="other" v-show="page == 'other'">
			<h1>%i18n:@advanced-settings%</h1>
			<mk-switch v-model="debug" text="%i18n:@debug-mode%">
				<span>%i18n:@debug-mode-desc%</span>
			</mk-switch>
			<mk-switch v-model="enableExperimentalFeatures" text="%i18n:@experimental%">
				<span>%i18n:@experimental-desc%</span>
			</mk-switch>
			<details v-if="debug">
				<summary>%i18n:@tools%</summary>
				<button class="ui button block" @click="taskmngr">%i18n:@task-manager%</button>
			</details>
		</section>

		<section class="other" v-show="page == 'other'">
			<h1>%i18n:@license%</h1>
			<div v-html="license"></div>
			<a :href="licenseUrl" target="_blank">%i18n:@third-parties%</a>
		</section>
	</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import XProfile from './settings.profile.vue';
import XMute from './settings.mute.vue';
import XPassword from './settings.password.vue';
import X2fa from './settings.2fa.vue';
import XApi from './settings.api.vue';
import XApps from './settings.apps.vue';
import XSignins from './settings.signins.vue';
import XDrive from './settings.drive.vue';
import { url, docsUrl, license, lang, langs, version } from '../../../config';
import checkForUpdate from '../../../common/scripts/check-for-update';
import MkTaskManager from './taskmanager.vue';

export default Vue.extend({
	components: {
		XProfile,
		XMute,
		XPassword,
		X2fa,
		XApi,
		XApps,
		XSignins,
		XDrive
	},
	data() {
		return {
			page: 'profile',
			meta: null,
			license,
			version,
			langs,
			latestVersion: undefined,
			checkingForUpdate: false
		};
	},
	computed: {
		licenseUrl(): string {
			return `${docsUrl}/${lang}/license`;
		},

		apiViaStream: {
			get() { return this.$store.state.device.apiViaStream; },
			set(value) { this.$store.commit('device/set', { key: 'apiViaStream', value }); }
		},

		autoPopout: {
			get() { return this.$store.state.device.autoPopout; },
			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: {
			get() { return this.$store.state.device.enableSounds; },
			set(value) { this.$store.commit('device/set', { key: 'enableSounds', value }); }
		},

		soundVolume: {
			get() { return this.$store.state.device.soundVolume; },
			set(value) { this.$store.commit('device/set', { key: 'soundVolume', value }); }
		},

		lang: {
			get() { return this.$store.state.device.lang; },
			set(value) { this.$store.commit('device/set', { key: 'lang', value }); }
		},

		preventUpdate: {
			get() { return this.$store.state.device.preventUpdate; },
			set(value) { this.$store.commit('device/set', { key: 'preventUpdate', value }); }
		},

		debug: {
			get() { return this.$store.state.device.debug; },
			set(value) { this.$store.commit('device/set', { key: 'debug', value }); }
		},

		enableExperimentalFeatures: {
			get() { return this.$store.state.device.enableExperimentalFeatures; },
			set(value) { this.$store.commit('device/set', { key: 'enableExperimentalFeatures', value }); }
		}
	},
	created() {
		(this as any).os.getMeta().then(meta => {
			this.meta = meta;
		});
	},
	methods: {
		taskmngr() {
			(this as any).os.new(MkTaskManager);
		},
		customizeHome() {
			this.$router.push('/i/customize-home');
			this.$emit('done');
		},
		updateWallpaper() {
			(this as any).apis.chooseDriveFile({
				multiple: false
			}).then(file => {
				(this as any).api('i/update', {
					wallpaperId: file.id
				});
			});
		},
		deleteWallpaper() {
			(this as any).api('i/update', {
				wallpaperId: null
			});
		},
		onChangeFetchOnScroll(v) {
			this.$store.dispatch('settings/set', {
				key: 'fetchOnScroll',
				value: v
			});
		},
		onChangeAutoWatch(v) {
			(this as any).api('i/update', {
				autoWatch: v
			});
		},
		onChangeDark(v) {
			this.$store.dispatch('settings/set', {
				key: 'dark',
				value: v
			});
		},
		onChangeShowPostFormOnTopOfTl(v) {
			this.$store.dispatch('settings/set', {
				key: 'showPostFormOnTopOfTl',
				value: v
			});
		},
		onChangeShowReplyTarget(v) {
			this.$store.dispatch('settings/set', {
				key: 'showReplyTarget',
				value: v
			});
		},
		onChangeShowMyRenotes(v) {
			this.$store.dispatch('settings/set', {
				key: 'showMyRenotes',
				value: v
			});
		},
		onChangeShowRenotedMyNotes(v) {
			this.$store.dispatch('settings/set', {
				key: 'showRenotedMyNotes',
				value: v
			});
		},
		onChangeShowMaps(v) {
			this.$store.dispatch('settings/set', {
				key: 'showMaps',
				value: v
			});
		},
		onChangeCircleIcons(v) {
			this.$store.dispatch('settings/set', {
				key: 'circleIcons',
				value: v
			});
		},
		onChangeILikeSushi(v) {
			this.$store.dispatch('settings/set', {
				key: 'iLikeSushi',
				value: v
			});
		},
		onChangeReversiBoardLabels(v) {
			this.$store.dispatch('settings/set', {
				key: 'reversiBoardLabels',
				value: v
			});
		},
		onChangeGradientWindowHeader(v) {
			this.$store.dispatch('settings/set', {
				key: 'gradientWindowHeader',
				value: v
			});
		},
		onChangeDisableViaMobile(v) {
			this.$store.dispatch('settings/set', {
				key: 'disableViaMobile',
				value: v
			});
		},
		checkForUpdate() {
			this.checkingForUpdate = true;
			checkForUpdate((this as any).os, true, true).then(newer => {
				this.checkingForUpdate = false;
				this.latestVersion = newer;
				if (newer == null) {
					(this as any).apis.dialog({
						title: '%i18n:@no-updates%',
						text: '%i18n:@no-updates-desc%'
					});
				} else {
					(this as any).apis.dialog({
						title: '%i18n:@update-available%',
						text: '%i18n:@update-available-desc%'
					});
				}
			});
		},
		clean() {
			localStorage.clear();
			(this as any).apis.dialog({
				title: '%i18n:@cache-cleared%',
				text: '%i18n:@caache-cleared-desc%'
			});
		},
		soundTest() {
			const sound = new Audio(`${url}/assets/message.mp3`);
			sound.volume = this.$store.state.device.soundVolume;
			sound.play();
		}
	}
});
</script>

<style lang="stylus" scoped>
@import '~const.styl'

root(isDark)
	display flex
	width 100%
	height 100%

	> .nav
		flex 0 0 200px
		width 100%
		height 100%
		padding 16px 0 0 0
		overflow auto
		border-right solid 1px isDark ? #1c2023 : #ddd

		> p
			display block
			padding 10px 16px
			margin 0
			color isDark ? #9aa2a7 : #666
			cursor pointer
			user-select none
			transition margin-left 0.2s ease

			> [data-fa]
				margin-right 4px

			&:hover
				color isDark ? #fff : #555

			&.active
				margin-left 8px
				color $theme-color !important

	> .pages
		width 100%
		height 100%
		flex auto
		overflow auto

		> section
			margin 32px
			color isDark ? #c4ccd2 : #4a535a

			> h1
				margin 0 0 1em 0
				padding 0 0 8px 0
				font-size 1em
				color isDark ? #e3e7ea : #555
				border-bottom solid 1px isDark ? #1c2023 : #eee

			&, >>> *
				.ui.button.block
					margin 16px 0

				> section
					margin 32px 0

					> h2
						margin 0 0 1em 0
						padding 0 0 8px 0
						font-size 1em
						color isDark ? #e3e7ea : #555
						border-bottom solid 1px isDark ? #1c2023 : #eee

		> .web
			> .div
				border-bottom solid 1px isDark ? #1c2023 : #eee
				margin 16px 0

.mk-settings[data-darkmode]
	root(true)

.mk-settings:not([data-darkmode])
	root(false)

</style>