From 18184441f1eabb34696ea4771051eb3aa8334ce4 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Fri, 21 Jun 2019 01:50:01 +0900
Subject: [PATCH] =?UTF-8?q?=E3=83=9B=E3=83=BC=E3=83=A0=E3=81=AE=E3=82=AB?=
 =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=83=9E=E3=82=A4=E3=82=BA=E6=83=85=E5=A0=B1?=
 =?UTF-8?q?=E3=82=92=E8=A4=87=E6=95=B0=E3=81=AE=E3=83=87=E3=83=90=E3=82=A4?=
 =?UTF-8?q?=E3=82=B9=E9=96=93=E3=81=A7=E5=90=8C=E6=9C=9F=E3=81=A7=E3=81=8D?=
 =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 locales/ja-JP.yml                             |  2 ++
 .../views/components/settings/settings.vue    | 16 ++++++++++
 src/client/app/desktop/views/home/home.vue    | 16 ++++++++--
 src/client/app/mobile/views/pages/widgets.vue | 14 ++++++++-
 src/client/app/store.ts                       | 30 +++++++++++++++++++
 5 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml
index d9223b1c4b..bdf8c24ce4 100644
--- a/locales/ja-JP.yml
+++ b/locales/ja-JP.yml
@@ -282,6 +282,8 @@ common:
     disable-via-mobile: "「モバイルからの投稿」フラグを付けない"
     load-raw-images: "添付された画像を高画質で表示する"
     load-remote-media: "リモートサーバーのメディアを表示する"
+    sync: "同期"
+    home-profile: "ホームのプロファイル"
 
   search: "検索"
   delete: "削除"
diff --git a/src/client/app/common/views/components/settings/settings.vue b/src/client/app/common/views/components/settings/settings.vue
index 0cbc40da57..1c02bdee8c 100644
--- a/src/client/app/common/views/components/settings/settings.vue
+++ b/src/client/app/common/views/components/settings/settings.vue
@@ -131,6 +131,12 @@
 				</section>
 			</section>
 
+			<section>
+				<header>{{ $t('@._settings.sync') }}</header>
+				<ui-input v-if="$root.isMobile" v-model="homeProfile">{{ $t('@._settings.home-profile') }}</ui-input>
+				<ui-input v-else v-model="mobileHomeProfile">{{ $t('@._settings.home-profile') }}</ui-input>
+			</section>
+
 			<section>
 				<header>{{ $t('@._settings.web-search-engine') }}</header>
 				<ui-input v-model="webSearchEngine">{{ $t('@._settings.web-search-engine') }}<template #desc>{{ $t('@._settings.web-search-engine-desc') }}</template></ui-input>
@@ -500,6 +506,16 @@ export default Vue.extend({
 			get() { return this.$store.state.device.mobileNotificationPosition; },
 			set(value) { this.$store.commit('device/set', { key: 'mobileNotificationPosition', value }); }
 		},
+
+		homeProfile: {
+			get() { return this.$store.state.device.homeProfile; },
+			set(value) { this.$store.commit('device/set', { key: 'homeProfile', value }); }
+		},
+
+		mobileHomeProfile: {
+			get() { return this.$store.state.device.mobileHomeProfile; },
+			set(value) { this.$store.commit('device/set', { key: 'mobileHomeProfile', value }); }
+		},
 	},
 	created() {
 		this.$root.getMeta().then(meta => {
diff --git a/src/client/app/desktop/views/home/home.vue b/src/client/app/desktop/views/home/home.vue
index d4677df842..49ac4c2407 100644
--- a/src/client/app/desktop/views/home/home.vue
+++ b/src/client/app/desktop/views/home/home.vue
@@ -102,7 +102,11 @@ export default Vue.extend({
 	computed: {
 		home(): any[] {
 			if (this.$store.getters.isSignedIn) {
-				return this.$store.state.device.home || [];
+				if (this.$store.state.device.homeProfile) {
+					return this.$store.state.settings.homeProfiles[this.$store.state.device.homeProfile] || this.$store.state.device.home || [];
+				} else {
+					return this.$store.state.device.home || [];
+				}
 			} else {
 				return [{
 					name: 'instance',
@@ -186,6 +190,14 @@ export default Vue.extend({
 			if (this.$store.state.device.home == null) {
 				this.$store.commit('device/setHome', _defaultDesktopHomeWidgets);
 			}
+
+			if (this.$store.state.device.homeProfile) {
+				this.$watch('$store.state.device.home', () => {
+					this.$store.dispatch('settings/updateHomeProfile');
+				}, {
+					deep: true
+				});
+			}
 		}
 	},
 
@@ -245,7 +257,7 @@ export default Vue.extend({
 
 		focus() {
 			(this.$refs.content as any).focus();
-		}
+		},
 	}
 });
 </script>
diff --git a/src/client/app/mobile/views/pages/widgets.vue b/src/client/app/mobile/views/pages/widgets.vue
index 7130fddb34..7f0ef678de 100644
--- a/src/client/app/mobile/views/pages/widgets.vue
+++ b/src/client/app/mobile/views/pages/widgets.vue
@@ -72,7 +72,11 @@ export default Vue.extend({
 
 	computed: {
 		widgets(): any[] {
-			return this.$store.state.device.mobileHome;
+			if (this.$store.state.device.mobileHomeProfile) {
+				return this.$store.state.settings.mobileHomeProfiles[this.$store.state.device.mobileHomeProfile] || this.$store.state.device.mobileHome;
+			} else {
+				return this.$store.state.device.mobileHome;
+			}
 		}
 	},
 
@@ -98,6 +102,14 @@ export default Vue.extend({
 				id: 'g', data: {}
 			}]);
 		}
+
+		if (this.$store.state.device.mobileHomeProfile) {
+			this.$watch('$store.state.device.mobileHome', () => {
+				this.$store.dispatch('settings/updateMobileHomeProfile');
+			}, {
+				deep: true
+			});
+		}
 	},
 
 	mounted() {
diff --git a/src/client/app/store.ts b/src/client/app/store.ts
index 6f545eb09b..7b56628b31 100644
--- a/src/client/app/store.ts
+++ b/src/client/app/store.ts
@@ -34,10 +34,14 @@ const defaultSettings = {
 	gamesReversiShowBoardLabels: false,
 	gamesReversiUseAvatarStones: true,
 	disableAnimatedMfm: false,
+	homeProfiles: {},
+	mobileHomeProfiles: {},
 };
 
 const defaultDeviceSettings = {
 	home: null,
+	homeProfile: null,
+	mobileHomeProfile: null,
 	mobileHome: [],
 	deck: null,
 	deckMode: false,
@@ -361,6 +365,32 @@ export default (os: MiOS) => new Vuex.Store({
 						});
 					}
 				},
+
+				updateHomeProfile(ctx) {
+					const profiles = ctx.state.homeProfiles;
+					profiles[ctx.rootState.device.homeProfile] = ctx.rootState.device.home;
+					ctx.commit('set', {
+						key: 'homeProfiles',
+						value: profiles
+					});
+					os.api('i/update-client-setting', {
+						name: 'homeProfiles',
+						value: profiles
+					});
+				},
+
+				updateMobileHomeProfile(ctx) {
+					const profiles = ctx.state.mobileHomeProfiles;
+					profiles[ctx.rootState.device.mobileHomeProfile] = ctx.rootState.device.mobileHome;
+					ctx.commit('set', {
+						key: 'mobileHomeProfiles',
+						value: profiles
+					});
+					os.api('i/update-client-setting', {
+						name: 'mobileHomeProfiles',
+						value: profiles
+					});
+				}
 			}
 		}
 	}