diff --git a/package.json b/package.json index 1d5fe97..ed55a9f 100755 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "@fortawesome/fontawesome-free": "^5.15.4", "@release-it/bumper": "^3.0.1", "@release-it/conventional-changelog": "^3.3.0", + "@types/file-saver": "^2.0.3", "@types/json-schema": "^7.0.9", + "@types/jszip": "^3.4.1", "@types/mime-types": "^2.1.1", "@types/node": "^16.11.7", "@types/node-emoji": "^1.8.1", @@ -49,10 +51,12 @@ "eslint-plugin-react-hooks": "^4.3.0", "eslint-plugin-simple-import-sort": "^7.0.0", "fast-glob": "^3.2.7", + "file-saver": "^2.0.5", "file-select-dialog": "^1.5.4", "fs-extra": "^10.0.0", "fuse.js": "^6.4.6", "json": "^11.0.0", + "jszip": "^3.7.1", "mime-types": "^2.1.34", "node-emoji": "github:rhysd/node-emoji#fix-gh-short-codes", "obsidian": "^0.12.17", diff --git a/src/icon-packs/pack-manager.ts b/src/icon-packs/pack-manager.ts index d5311ef..7149455 100644 --- a/src/icon-packs/pack-manager.ts +++ b/src/icon-packs/pack-manager.ts @@ -1,7 +1,9 @@ import "./icon.less"; import cls from "classnames"; +import { saveAs } from "file-saver"; import Fuse from "fuse.js"; +import JSZip from "jszip"; import svg2uri from "mini-svg-data-uri"; import emoji from "node-emoji"; import { EventRef, Events, normalizePath, Notice } from "obsidian"; @@ -157,6 +159,14 @@ export default class PackManager extends Events { this.refresh(); this.trigger("initialized", this); } + async backupCustomIcons(): Promise { + let zip = new JSZip(); + const iconlist = await this.vault.adapter.list(this.customIconsDir); + for (const filepath of iconlist.files) { + zip.file(basename(filepath), this.vault.adapter.readBinary(filepath)); + } + saveAs(await zip.generateAsync({ type: "blob" }), "custom-icons.zip"); + } async addFromFiles(pack: string, files: FileList) { const icons = await getIconsFromFileList(files); diff --git a/src/settings.ts b/src/settings.ts index 74579f4..dc1d6ce 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -146,6 +146,12 @@ export class IconSCSettingTab extends PluginSettingTab { new Setting(this.containerEl) .setHeading() .setName("Custom Icons") + .addExtraButton((btn) => + btn + .setIcon("sheets-in-box") + .setTooltip("Backup icons") + .onClick(() => this.plugin.packManager.backupCustomIcons()), + ) .then( (s) => Platform.isDesktopApp &&