Skip to content

Commit

Permalink
feat(pack-manager): backup custom icons in a zipped file
Browse files Browse the repository at this point in the history
closes #10
  • Loading branch information
aidenlx committed Nov 17, 2021
1 parent ad8764f commit 8938309
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/icon-packs/pack-manager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -157,6 +159,14 @@ export default class PackManager extends Events {
this.refresh();
this.trigger("initialized", this);
}
async backupCustomIcons(): Promise<void> {
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);
Expand Down
6 changes: 6 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 8938309

Please sign in to comment.