Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Mar 9, 2025
1 parent 7057acf commit 3513176
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
8 changes: 8 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5306,6 +5306,10 @@ export interface Locale extends ILocale {
* スキップ
*/
"skip": string;
/**
* 復元
*/
"restore": string;
"_preferencesProfile": {
/**
* プロファイル名
Expand Down Expand Up @@ -5349,6 +5353,10 @@ export interface Locale extends ILocale {
* このデバイスで設定の自動バックアップは有効になっていません。
*/
"autoPreferencesBackupIsNotEnabledForThisDevice": string;
/**
* 設定のバックアップが見つかりました
*/
"backupFound": string;
};
"_accountSettings": {
/**
Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,7 @@ overrideByAccount: "アカウントで上書き"
untitled: "無題"
noName: "名前はありません"
skip: "スキップ"
restore: "復元"

_preferencesProfile:
profileName: "プロファイル名"
Expand All @@ -1336,6 +1337,7 @@ _preferencesBackup:
selectBackupToRestore: "復元するバックアップを選択してください"
youNeedToNameYourProfileToEnableAutoBackup: "自動バックアップを有効にするにはプロファイル名の設定が必要です。"
autoPreferencesBackupIsNotEnabledForThisDevice: "このデバイスで設定の自動バックアップは有効になっていません。"
backupFound: "設定のバックアップが見つかりました"

_accountSettings:
requireSigninToViewContents: "コンテンツの表示にログインを必須にする"
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type Keys = (
'debug' |
'preferences' |
'latestPreferencesUpdate' |
'hidePreferencesRestoreSuggestion' |
`miux:${string}` |
`ui:folder:${string}` |
`themes:${string}` | // DEPRECATED
Expand Down
27 changes: 26 additions & 1 deletion packages/frontend/src/preferences/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function importProfile() {
const profile = JSON.parse(txt) as PreferencesProfile;

miLocalStorage.setItem('preferences', JSON.stringify(profile));
miLocalStorage.setItem('hidePreferencesRestoreSuggestion', 'true');
shouldSuggestRestoreBackup.value = false;
unisonReload();
};

Expand All @@ -139,7 +141,7 @@ export async function cloudBackup() {
});
}

async function restoreFromCloudBackup() {
export async function restoreFromCloudBackup() {
if ($i == null) return;

// TODO: 更新日時でソートして取得したい
Expand Down Expand Up @@ -176,7 +178,9 @@ async function restoreFromCloudBackup() {
console.log(profile);

miLocalStorage.setItem('preferences', JSON.stringify(profile));
miLocalStorage.setItem('hidePreferencesRestoreSuggestion', 'true');
store.set('enablePreferencesAutoCloudBackup', true);
shouldSuggestRestoreBackup.value = false;
unisonReload();
}

Expand All @@ -191,3 +195,24 @@ export async function enableAutoBackup() {

store.set('enablePreferencesAutoCloudBackup', true);
}

export const shouldSuggestRestoreBackup = ref(false);

if ($i != null) {
if (miLocalStorage.getItem('hidePreferencesRestoreSuggestion') !== 'true') {
misskeyApi('i/registry/keys', {
scope: ['client', 'preferences', 'backups'],
}).then(keys => {
if (keys.length === 0) {
miLocalStorage.setItem('hidePreferencesRestoreSuggestion', 'true');
} else {
shouldSuggestRestoreBackup.value = true;
}
});
}
}

export function hideRestoreBackupSuggestion() {
miLocalStorage.setItem('hidePreferencesRestoreSuggestion', 'true');
shouldSuggestRestoreBackup.value = false;
}
73 changes: 73 additions & 0 deletions packages/frontend/src/ui/_common_/PreferenceRestore.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root">
<span :class="$style.icon">
<i class="ti ti-info-circle"></i>
</span>
<span :class="$style.title">{{ i18n.ts._preferencesBackup.backupFound }}</span>
<span :class="$style.body"><button class="_textButton" @click="restore">{{ i18n.ts.restore }}</button> | <button class="_textButton" @click="skip">{{ i18n.ts.skip }}</button></span>
</div>
</template>

<script lang="ts" setup>
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
import { hideRestoreBackupSuggestion, restoreFromCloudBackup } from '@/preferences/utility.js';

function restore() {
restoreFromCloudBackup();
}

function skip() {
hideRestoreBackupSuggestion();
}
</script>

<style lang="scss" module>
.root {
--height: 24px;
font-size: 0.85em;
display: flex;
vertical-align: bottom;
width: 100%;
line-height: var(--height);
height: var(--height);
overflow: clip;
contain: strict;
background: var(--MI_THEME-panel);

@container (max-width: 1000px) {
display: block;
text-align: center;

> .body {
display: none;
}
}
}

.icon {
margin-left: 10px;
}

.title {
padding: 0 10px;
font-weight: bold;

&:empty {
display: none;
}
}

.body {
min-width: 0;
flex: 1;
overflow: clip;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/universal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkStickyContainer ref="contents" :class="$style.contents" style="container-type: inline-size;" @contextmenu.stop="onContextmenu">
<template #header>
<div>
<XPreferenceRestore v-if="shouldSuggestRestoreBackup"/>
<XAnnouncements v-if="$i"/>
<XStatusBars :class="$style.statusbars"/>
</div>
Expand Down Expand Up @@ -115,11 +116,13 @@ import { miLocalStorage } from '@/local-storage.js';
import { useScrollPositionManager } from '@/nirax.js';
import { mainRouter } from '@/router/main.js';
import { prefer } from '@/preferences.js';
import { shouldSuggestRestoreBackup } from '@/preferences/utility.js';

const XWidgets = defineAsyncComponent(() => import('./universal.widgets.vue'));
const XSidebar = defineAsyncComponent(() => import('@/ui/_common_/navbar.vue'));
const XStatusBars = defineAsyncComponent(() => import('@/ui/_common_/statusbars.vue'));
const XAnnouncements = defineAsyncComponent(() => import('@/ui/_common_/announcements.vue'));
const XPreferenceRestore = defineAsyncComponent(() => import('@/ui/_common_/PreferenceRestore.vue'));

const isRoot = computed(() => mainRouter.currentRoute.value.name === 'index');

Expand Down

0 comments on commit 3513176

Please sign in to comment.