Skip to content

Commit

Permalink
Mobile localstorage alternative (#25)
Browse files Browse the repository at this point in the history
* backup if localStorage doesn't work
* 0.3.5
  • Loading branch information
shabegom authored May 2, 2021
1 parent b69c035 commit 6e59743
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "buttons",
"name": "Buttons",
"description": "Create Buttons in your Obsidian notes to run commands, open links, and insert templates",
"version": "0.3.4",
"version": "0.3.5",
"author": "shabegom",
"authorUrl": "https://shbgm.ca",
"isDesktopOnly": false,
Expand Down
7 changes: 6 additions & 1 deletion src/buttonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { App, TFile, CachedMetadata } from "obsidian";
import { ExtendedBlockCache, Arguments } from "./types";
import { createArgumentObject } from "./utils";

let buttonStore: ExtendedBlockCache[];

export const initializeButtonStore = (app: App): void => {
const files = app.vault.getMarkdownFiles();
const blocksArr = files
Expand All @@ -12,6 +14,7 @@ export const initializeButtonStore = (app: App): void => {
.filter((arr) => arr !== undefined)
.flat();
localStorage.setItem("buttons", JSON.stringify(blocksArr));
buttonStore = blocksArr;
};

export const addButtonToStore = (app: App, file: TFile): void => {
Expand All @@ -22,13 +25,15 @@ export const addButtonToStore = (app: App, file: TFile): void => {
? removeDuplicates([...buttons, ...store])
: removeDuplicates(store);
localStorage.setItem("buttons", JSON.stringify(newStore));
buttonStore = newStore;
};

export const getButtonFromStore = async (
app: App,
args: Arguments
): Promise<Arguments> | undefined => {
const store = JSON.parse(localStorage.getItem("buttons"));
let store = JSON.parse(localStorage.getItem("buttons"));
store = store ? store : buttonStore;
if (args.id) {
const storedButton = store.filter(
(item: ExtendedBlockCache) => `button-${args.id}` === item.id
Expand Down

0 comments on commit 6e59743

Please sign in to comment.