Skip to content

Commit

Permalink
fix: about screen crash on loading icon (#162)
Browse files Browse the repository at this point in the history
* fix: about screen crash on loading icon
  • Loading branch information
danilolutz authored Mar 17, 2022
1 parent 7125b12 commit f211b33
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
11 changes: 2 additions & 9 deletions src/electron/data/protocols/Menu/MenuBuildTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { BrowserWindow, MenuItemConstructorOptions } from 'electron';
import Resources from '../../../infra/resources/DefaultResources';
import I18nAdapter from '../I18n/I18n';

import { MenuItemConstructorOptions } from 'electron';
export interface MenuBuildTemplate {
buildTemplate(
mainWindow: BrowserWindow,
i18nAdapter: I18nAdapter,
resources: Resources
): Promise<MenuItemConstructorOptions[]>;
buildTemplate(): Promise<MenuItemConstructorOptions[]>;
}
1 change: 1 addition & 0 deletions src/electron/infra/menu/DefaultMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class DefaultMenu implements MenuBuildTemplate {
accelerator: 'Ctrl+T',
click: this.actionHandler.newTitle,
},
{ type: 'separator' },
{
label: this.i18nAdapter.translate('menu.file.save'),
accelerator: 'Ctrl+S',
Expand Down
41 changes: 34 additions & 7 deletions src/electron/infra/menu/NativeMenuActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,89 +11,108 @@ const actionCreate = {
type ElectronWindow = BrowserWindow | undefined;

export default class NativeMenuActionHandlers implements MenuActionHandler {
constructor(private resources: Resource) {}
constructor(private resources: Resource) {
this.about = this.about.bind(this);
}

newBorrow(_menuItem: MenuItem, win: ElectronWindow): void {
public newBorrow(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.borrowTab, actionCreate);
}
}
newPerson(_menuItem: MenuItem, win: ElectronWindow): void {

public newPerson(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.personTab, actionCreate);
}
}
newTitle(_menuItem: MenuItem, win: ElectronWindow): void {

public newTitle(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.titleTab, actionCreate);
}
}
quickSearch(_menuItem: MenuItem, win: ElectronWindow): void {

public quickSearch(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.quickSearch);
}
}

closeTab(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.closeCurrentTab);
}
}

settings(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.settingsTab);
}
}

quit(): void {
app.quit();
}

save(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.save);
}
}

undo(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.undo();
}
}

redo(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.redo();
}
}

cut(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.cut();
}
}

copy(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.copy();
}
}

paste(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.paste();
}
}

selectAll(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.selectAll();
}
}

darkTheme(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.send(AppEvent.setTheme);
}
}

reload(_menuItem: MenuItem, win: ElectronWindow): void {
win.webContents.reload();
}

forceReload(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.reloadIgnoringCache();
}
}

toggleDevTools(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) {
win.webContents.toggleDevTools();
Expand All @@ -107,28 +126,36 @@ export default class NativeMenuActionHandlers implements MenuActionHandler {
zoomIn(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) win.webContents.zoomLevel = win.webContents.zoomLevel + 0.5;
}

zoomOut(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) win.webContents.zoomLevel = win.webContents.zoomLevel - 0.5;
}

fullScreen(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) win.setFullScreen(!win.isFullScreen());
}

minimize(_menuItem: MenuItem, win: ElectronWindow): void {
if (win) win.minimize();
}

close(): void {
app.quit();
}

documentation(): void {
shell.openExternal('https://librarian-org.gitbook.io/librarian/');
}

reportIssue(): void {
'https://github.com/librarian-org/librarian/issues/new';
shell.openExternal('https://github.com/librarian-org/librarian/issues/new');
}

website(): void {
shell.openExternal('https://librarian-org.github.io/');
}
about(): void {

public about(): void {
app.setAboutPanelOptions({
applicationName: 'Librarian',
applicationVersion: app.getVersion(),
Expand Down
9 changes: 3 additions & 6 deletions src/electron/infra/resources/DefaultResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import path from 'path';
import isDev from 'electron-is-dev';
import Resource from '../../data/protocols/Resource/Resource';


export default class DefaultResources
implements
Resource
{
export default class DefaultResources implements Resource {
public getLanguages(): string[] {
const folder = path.resolve(
__dirname,
Expand All @@ -33,7 +29,7 @@ export default class DefaultResources
}

public getIcon(): string {
return path.resolve(
const iconPath = path.resolve(
__dirname,
'..',
'renderer',
Expand All @@ -42,6 +38,7 @@ export default class DefaultResources
'images',
'librarian.png'
);
return iconPath;
}

public writeLanguageFile(language: string): void {
Expand Down

0 comments on commit f211b33

Please sign in to comment.