Skip to content

Commit

Permalink
refactor: improve migration functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed Sep 10, 2023
1 parent 63ef3c1 commit da7a33d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin, MenuItem, TFile, WorkspaceLeaf, requireApiVersion } from 'obsidian';
import { Plugin, MenuItem, TFile, WorkspaceLeaf, requireApiVersion, Notice } from 'obsidian';
import { ExplorerLeaf, ExplorerView } from './@types/obsidian';
import { createDefaultDirectory, initIconPacks, loadUsedIcons, setPath } from './iconPackManager';
import IconsPickerModal, { Icon } from './iconsPickerModal';
Expand Down Expand Up @@ -31,10 +31,24 @@ export default class IconFolderPlugin extends Plugin {
if (!this.getSettings().migrated) {
console.log('migrating icons...');
this.data = migrateIcons(this);
this.getSettings().migrated = true;
this.getSettings().migrated++;
console.log('...icons migrated');
}

// @ts-ignore
if (this.getSettings().migrated === true) {
this.getSettings().migrated = 1;
}

// Migration for new syncing mechanism.
if (this.getSettings().migrated === 1) {
new Notice(
'Please delete your old icon packs and redownload your icon packs to use the new syncing mechanism.',
20000,
);
this.getSettings().migrated++;
}

const extraPadding = (this.getSettings() as any).extraPadding as ExtraMarginSettings;
if (extraPadding) {
if (extraPadding.top !== 2 || extraPadding.bottom !== 2 || extraPadding.left !== 2 || extraPadding.right !== 2) {
Expand Down
4 changes: 2 additions & 2 deletions src/settings/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface CustomRule {
}

export interface IconFolderSettings {
migrated: boolean;
migrated: number;
iconPacksPath: string;
fontSize: number;
emojiStyle: 'none' | 'native' | 'twemoji';
Expand All @@ -26,7 +26,7 @@ export interface IconFolderSettings {
}

export const DEFAULT_SETTINGS: IconFolderSettings = {
migrated: false,
migrated: 1,
iconPacksPath: '.obsidian/plugins/obsidian-icon-folder/icons',
fontSize: 16,
emojiStyle: 'none',
Expand Down

0 comments on commit da7a33d

Please sign in to comment.