Skip to content

Commit

Permalink
feat: Bring store to windowsNlinux version
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershvueli committed Jul 20, 2021
1 parent ddf309c commit fff3c68
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 5 deletions.
18 changes: 16 additions & 2 deletions app/windowsNlinux/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { app, BrowserWindow, Tray, globalShortcut, Menu, ipcMain } = require("electron");
const { LRUMap } = require("lru_map");

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

// This is the npm package `open`, it is used here to open all links in an external browser
const open = require("open");

Expand All @@ -14,8 +18,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
Menu.setApplicationMenu(null)
Expand Down Expand Up @@ -125,6 +136,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
196 changes: 193 additions & 3 deletions app/windowsNlinux/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/windowsNlinux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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"
}
Expand Down

0 comments on commit fff3c68

Please sign in to comment.