Skip to content

Commit 667d6e3

Browse files
committed
Combine community plugins sync config
1 parent 91a472f commit 667d6e3

5 files changed

Lines changed: 52 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ No. History here is based on Google Drive revisions, not Obsidian Sync snapshots
157157

158158
### Does it sync all `.obsidian` files?
159159

160-
No. Only configured categories are synced (for example editor settings, appearance, hotkeys, community plugin list).
160+
No. Only configured categories are synced (for example editor settings, appearance, hotkeys, community plugins).
161161
Unsafe and transient files (for example workspace and cache files) are intentionally excluded.
162162

163163
## Known limitations

src/main.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ interface LegacySelectiveSyncSettings {
2626
syncNonImageFiles?: boolean;
2727
}
2828

29+
interface LegacyVaultConfigSyncSettings {
30+
syncCommunityPluginList?: boolean;
31+
syncCommunityPluginFiles?: boolean;
32+
syncCommunityPlugins?: boolean;
33+
}
34+
2935
function resolveLegacyNonImageSyncSetting(
3036
settings: LegacySelectiveSyncSettings | null
3137
): boolean | null {
@@ -46,6 +52,22 @@ function resolveLegacyNonImageSyncSetting(
4652
return legacyValues.some(value => value);
4753
}
4854

55+
function resolveLegacyCommunityPluginSyncSetting(
56+
settings: LegacyVaultConfigSyncSettings | null
57+
): boolean | null {
58+
if (!settings || typeof settings.syncCommunityPlugins === 'boolean') {
59+
return null;
60+
}
61+
62+
const hasLegacyList = typeof settings.syncCommunityPluginList === 'boolean';
63+
const hasLegacyFiles = typeof settings.syncCommunityPluginFiles === 'boolean';
64+
if (!hasLegacyList && !hasLegacyFiles) {
65+
return null;
66+
}
67+
68+
return !!settings.syncCommunityPluginList || !!settings.syncCommunityPluginFiles;
69+
}
70+
4971
export default class GDriveSyncPlugin extends Plugin {
5072
settings: GDrivePluginSettings;
5173
authManager!: GoogleAuthManager;
@@ -256,12 +278,27 @@ export default class GDriveSyncPlugin extends Plugin {
256278
}
257279

258280
async loadSettings() {
259-
const loaded = await this.loadData() as (Partial<GDrivePluginSettings> & LegacySelectiveSyncSettings) | null;
281+
const loaded = await this.loadData() as (
282+
Partial<GDrivePluginSettings> &
283+
LegacySelectiveSyncSettings &
284+
LegacyVaultConfigSyncSettings
285+
) | null;
260286
this.settings = Object.assign({}, DEFAULT_SETTINGS, loaded ?? {});
287+
let shouldPersist = false;
261288

262289
const migratedNonImageSync = resolveLegacyNonImageSyncSetting(loaded);
263290
if (migratedNonImageSync !== null) {
264291
this.settings.syncNonImageFiles = migratedNonImageSync;
292+
shouldPersist = true;
293+
}
294+
295+
const migratedCommunityPluginSync = resolveLegacyCommunityPluginSyncSetting(loaded);
296+
if (migratedCommunityPluginSync !== null) {
297+
this.settings.syncCommunityPlugins = migratedCommunityPluginSync;
298+
shouldPersist = true;
299+
}
300+
301+
if (shouldPersist) {
265302
await this.saveData(this.settings);
266303
}
267304
}

src/settings.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ export interface GDrivePluginSettings {
6868
syncEditorSettings: boolean;
6969
syncAppearance: boolean;
7070
syncHotkeys: boolean;
71-
syncCommunityPluginList: boolean;
71+
syncCommunityPlugins: boolean;
7272
syncCorePluginSettings: boolean;
73-
syncCommunityPluginFiles: boolean;
7473

7574
// Internal state
7675
setupComplete: boolean; // false triggers the setup wizard on first load
@@ -115,9 +114,8 @@ export const DEFAULT_SETTINGS: GDrivePluginSettings = {
115114
syncEditorSettings: true,
116115
syncAppearance: true,
117116
syncHotkeys: false,
118-
syncCommunityPluginList: false,
117+
syncCommunityPlugins: false,
119118
syncCorePluginSettings: false,
120-
syncCommunityPluginFiles: false,
121119

122120
// Internal
123121
setupComplete: false,
@@ -468,12 +466,12 @@ export class GDriveSettingTab extends PluginSettingTab {
468466
);
469467

470468
new Setting(containerEl)
471-
.setName('Sync community plugin list')
472-
.setDesc('Sync community-plugins.json only, not plugin binaries.')
469+
.setName('Sync community plugins')
470+
.setDesc('Sync community-plugins.json plus each installed plugin\'s manifest.json, data.json, styles.css, and main.js.')
473471
.addToggle(t =>
474-
t.setValue(this.plugin.settings.syncCommunityPluginList).onChange(v => {
472+
t.setValue(this.plugin.settings.syncCommunityPlugins).onChange(v => {
475473
void this.updateSelectiveSyncSettings(() => {
476-
this.plugin.settings.syncCommunityPluginList = v;
474+
this.plugin.settings.syncCommunityPlugins = v;
477475
});
478476
})
479477
);
@@ -489,17 +487,6 @@ export class GDriveSettingTab extends PluginSettingTab {
489487
})
490488
);
491489

492-
new Setting(containerEl)
493-
.setName('Sync community plugin files')
494-
.setDesc('Sync manifest.json, data.json, styles.css, and main.js for each installed community plugin.')
495-
.addToggle(t =>
496-
t.setValue(this.plugin.settings.syncCommunityPluginFiles).onChange(v => {
497-
void this.updateSelectiveSyncSettings(() => {
498-
this.plugin.settings.syncCommunityPluginFiles = v;
499-
});
500-
})
501-
);
502-
503490
// ── Version history ───────────────────────────────────────────
504491
new Setting(containerEl).setName('Version history').setHeading();
505492

src/sync/SyncManager.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ export interface SelectiveSyncSnapshot {
9696
syncEditorSettings: boolean;
9797
syncAppearance: boolean;
9898
syncHotkeys: boolean;
99-
syncCommunityPluginList: boolean;
99+
syncCommunityPlugins: boolean;
100100
syncCorePluginSettings: boolean;
101-
syncCommunityPluginFiles: boolean;
102101
}
103102

104103
interface CleanupDuplicateArtifactsOptions {
@@ -1455,9 +1454,8 @@ export class SyncManager {
14551454
syncEditorSettings: this.plugin.settings.syncEditorSettings,
14561455
syncAppearance: this.plugin.settings.syncAppearance,
14571456
syncHotkeys: this.plugin.settings.syncHotkeys,
1458-
syncCommunityPluginList: this.plugin.settings.syncCommunityPluginList,
1457+
syncCommunityPlugins: this.plugin.settings.syncCommunityPlugins,
14591458
syncCorePluginSettings: this.plugin.settings.syncCorePluginSettings,
1460-
syncCommunityPluginFiles: this.plugin.settings.syncCommunityPluginFiles,
14611459
};
14621460
}
14631461

src/sync/exclusions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ type SelectiveSettings = Pick<
2424
| 'syncEditorSettings'
2525
| 'syncAppearance'
2626
| 'syncHotkeys'
27-
| 'syncCommunityPluginList'
27+
| 'syncCommunityPlugins'
2828
| 'syncCorePluginSettings'
29-
| 'syncCommunityPluginFiles'
3029
>;
3130

3231
export interface ExclusionDescriptionContext {
@@ -139,9 +138,9 @@ function isAllowedVaultConfigPath(relativePath: string, settings: SelectiveSetti
139138
if (relativePath === 'app.json') return settings.syncEditorSettings;
140139
if (relativePath === 'appearance.json') return settings.syncAppearance;
141140
if (relativePath === 'hotkeys.json') return settings.syncHotkeys;
142-
if (relativePath === 'community-plugins.json') return settings.syncCommunityPluginList;
141+
if (relativePath === 'community-plugins.json') return settings.syncCommunityPlugins;
143142
if (isCorePluginSettingsPath(relativePath)) return settings.syncCorePluginSettings;
144-
if (isCommunityPluginAssetPath(relativePath)) return settings.syncCommunityPluginFiles;
143+
if (isCommunityPluginAssetPath(relativePath)) return settings.syncCommunityPlugins;
145144
if (relativePath.startsWith('themes/') || relativePath.startsWith('snippets/')) return settings.syncAppearance;
146145
return false;
147146
}
@@ -341,13 +340,13 @@ export function describeUserAdjustableExclusionReason(
341340
return `Vault config file "${configPathLabel}" is disabled by Sync hotkeys.`;
342341
}
343342
if (relativePath === 'community-plugins.json') {
344-
return `Vault config file "${configPathLabel}" is disabled by Sync community plugin list.`;
343+
return `Vault config file "${configPathLabel}" is disabled by Sync community plugins.`;
345344
}
346345
if (relativePath && isCorePluginSettingsPath(relativePath)) {
347346
return `Vault config file "${configPathLabel}" is disabled by Sync core plugin settings.`;
348347
}
349348
if (relativePath && isCommunityPluginAssetPath(relativePath)) {
350-
return `Vault config file "${configPathLabel}" is disabled by Sync community plugin files.`;
349+
return `Vault config file "${configPathLabel}" is disabled by Sync community plugins.`;
351350
}
352351
if (relativePath?.startsWith('themes/') || relativePath?.startsWith('snippets/')) {
353352
return `Vault config path "${configPathLabel}" is disabled by Sync appearance.`;

0 commit comments

Comments
 (0)