Skip to content

Commit

Permalink
feat: add reload and reset menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRobz committed Nov 9, 2021
1 parent 6ae8661 commit 348a982
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 52 deletions.
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { DefaultIconsRedirect } from 'components/modules/IconsHome/DefaultIconsRedirect';
import { QueryParamProvider } from 'use-query-params';
import { UpdateChecker } from 'components/modules/UpdateChecker';
import { setupGlobalListeners } from 'data/globalListeners';
import IconsHome from './components/modules/IconsHome';
import { Layout } from './components/ui/layout/index';

Expand All @@ -19,6 +20,8 @@ const queryClient = new QueryClient({
},
});

setupGlobalListeners();

export default function App() {
return (
<Router>
Expand Down
10 changes: 10 additions & 0 deletions src/data/globalListeners/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { db } from 'data/db';
import { ipcRenderer } from 'electron';

export const setupGlobalListeners = () => {
ipcRenderer.on('reset-app-clear-data', async () => {
await Promise.all([db.icons.clear(), db.collections.clear()]);
localStorage.clear();
window.location.reload();
});
};
84 changes: 32 additions & 52 deletions src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ export default class MenuBuilder {

buildDarwinTemplate(): MenuItemConstructorOptions[] {
const subMenuAbout: DarwinMenuItemConstructorOptions = {
label: 'Electron',
label: 'Icon Shelf',
submenu: [
{
label: 'About IconShelf',
selector: 'orderFrontStandardAboutPanel:',
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{
label: 'Reset App and Clear Local Data',
click: () => {
this.mainWindow.webContents.send('reset-app-clear-data');
},
},
{ type: 'separator' },
{
label: 'Hide IconShelf',
Expand Down Expand Up @@ -115,18 +120,7 @@ export default class MenuBuilder {
},
],
};
const subMenuViewProd: MenuItemConstructorOptions = {
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
],
};

const subMenuWindow: DarwinMenuItemConstructorOptions = {
label: 'Window',
submenu: [
Expand Down Expand Up @@ -170,10 +164,7 @@ export default class MenuBuilder {
],
};

const subMenuView =
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'
? subMenuViewDev
: subMenuViewProd;
const subMenuView = subMenuViewDev;

return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
}
Expand All @@ -198,40 +189,29 @@ export default class MenuBuilder {
},
{
label: '&View',
submenu:
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'
? [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
},
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
]
: [
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
],
submenu: [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
},
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
],
},
{
label: 'Help',
Expand Down

0 comments on commit 348a982

Please sign in to comment.