mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-07-25 21:24:50 +02:00
wip
This commit is contained in:
@@ -123,10 +123,12 @@ createVisibilityAwareInterval(() => {
|
||||
}, 1000 * 60 * 3);
|
||||
//#endregion
|
||||
|
||||
if (store.s.enablePreferencesAutoCloudSync) {
|
||||
// TODO: 前回同期してから10分以上経過している場合のみ
|
||||
cloudSync();
|
||||
}
|
||||
store.loaded.then(() => {
|
||||
if (store.s.enablePreferencesAutoCloudSync) {
|
||||
// TODO: 前回同期してから10分以上経過している場合のみ
|
||||
cloudSync();
|
||||
}
|
||||
});
|
||||
|
||||
if (_DEV_) {
|
||||
(window as any).prefer = prefer;
|
||||
|
||||
@@ -351,6 +351,8 @@ export class PreferencesManager extends EventEmitter<PreferencesManagerEvents> {
|
||||
|
||||
const cloudValues = await this.io.cloudGetBulk({ needs });
|
||||
|
||||
let modified = false;
|
||||
|
||||
for (const _key in PREF_DEF) {
|
||||
const key = _key as keyof PREF;
|
||||
const record = this.getMatchedRecordOf(key);
|
||||
@@ -359,12 +361,14 @@ export class PreferencesManager extends EventEmitter<PreferencesManagerEvents> {
|
||||
if (!deepEqual(cloudValue, record[1])) {
|
||||
this.rewriteRawState(key, cloudValue);
|
||||
record[1] = cloudValue;
|
||||
modified = true;
|
||||
if (_DEV_) console.log('cloud fetched', key, cloudValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.save();
|
||||
if (modified) this.save();
|
||||
|
||||
if (_DEV_) console.log('cloud fetch completed');
|
||||
}
|
||||
|
||||
|
||||
@@ -162,11 +162,13 @@ export async function cloudSync() {
|
||||
key: prefer.profile.name,
|
||||
}) as PreferencesProfile | null;
|
||||
|
||||
if (cloudProfile == null || cloudProfile.modifiedAt < prefer.profile.modifiedAt) {
|
||||
await cloudBackup();
|
||||
if (cloudProfile == null || cloudProfile.modifiedAt <= prefer.profile.modifiedAt) {
|
||||
if (_DEV_) console.log('no new cloud profile found, skipping sync');
|
||||
return;
|
||||
}
|
||||
|
||||
if (_DEV_) console.log('new cloud profile found, restoring from cloud', cloudProfile);
|
||||
|
||||
miLocalStorage.setItem('preferences', JSON.stringify(cloudProfile));
|
||||
|
||||
prefer.reloadProfile();
|
||||
@@ -178,6 +180,10 @@ export async function cloudBackup() {
|
||||
throw new Error('cannot auto backup for this profile');
|
||||
}
|
||||
|
||||
// TODO: 同期有効時、既に新しいバージョンがバックアップされている場合は上書きしないようにする
|
||||
|
||||
if (_DEV_) console.log('cloud backup', prefer.profile);
|
||||
|
||||
await misskeyApi('i/registry/set', {
|
||||
scope: ['client', 'preferences', 'backups'],
|
||||
key: prefer.profile.name,
|
||||
|
||||
Reference in New Issue
Block a user