Skip to content

Commit

Permalink
feat: Use store to save user's recents between app runs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershvueli committed Jul 20, 2021
1 parent 598a270 commit c76df72
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 10 deletions.
18 changes: 16 additions & 2 deletions app/macos/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const {
} = require("electron");
const { LRUMap } = require("lru_map");

// Create store to save user's recents
const Store = require('electron-store');
const store = new Store();

const robot = require("robotjs");

// This is the npm package `open`, it is used here to open all links in an external browser
Expand All @@ -23,8 +27,15 @@ const emojis = require("./src/emojis");
let tray = undefined;
let window = undefined;

// Let's preset our LRU Map that we'll use to keep track of recent uses
let lruMap = new LRUMap(10);
// Let's fetch our previous LRU Map, or set it
let lruMap;
if (store.has("lruMap")) {
lruMap = new LRUMap(10, store.get("lruMap").map(it => {
return [it.key, it.value];
}));
} else {
lruMap = new LRUMap(10);
}

// Hide the menu and dev tools (for production build)
Menu.setApplicationMenu(null);
Expand Down Expand Up @@ -140,6 +151,9 @@ ipcMain.handle("getEmojisForSearchString", (_event, arg) => {
// When we get a signal to select an emoji, update our LRU Map
ipcMain.on("selectEmoji", (_event, arg) => {
lruMap.set(arg, "");

// Save our current lruMap's JSON representation to the store
store.set("lruMap", lruMap.toJSON());
});

const toggleWindow = () => {
Expand Down
190 changes: 182 additions & 8 deletions app/macos/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/macos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"homepage": "https://github.com/virejdasani/Geniemoji#readme",
"dependencies": {
"electron": "^12.0.4",
"electron-store": "^8.0.0",
"lru_map": "^0.4.1",
"open": "^8.0.9",
"robotjs": "^0.6.0"
Expand Down

0 comments on commit c76df72

Please sign in to comment.