Skip to content

Commit f94d811

Browse files
committed
electron service restructure + card template not working on new games fix
1 parent 85391d3 commit f94d811

File tree

9 files changed

+59
-19
lines changed

9 files changed

+59
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules/
33
cider-app/electron/dist/main.js
44
cider-app/electron/dist/main.js.map
55
cider-app/release/
6+
cider-app/electron-app/dist/main.js
7+
cider-app/electron-app/dist/main.js.map
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ try {
105105
const result = await dialog.showOpenDialog(win, {
106106
properties: ['openDirectory']
107107
})
108-
console.log('directory selected', result.filePaths)
108+
console.log('directory selected', result.filePaths);
109+
});
110+
111+
// exit the application
112+
ipcMain.on('exit-application', async (event, arg) => {
113+
app.quit();
109114
});
110115

111116
} catch (e) {

cider-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"name": "Hristo Iankov"
66
},
77
"version": "0.3.0",
8-
"main": "electron/dist/main.js",
8+
"main": "electron-app/dist/main.js",
99
"scripts": {
1010
"ng": "ng",
1111
"start": "ng serve",
1212
"build": "ng build",
1313
"watch": "ng build --watch --configuration development",
1414
"test": "ng test",
15-
"electron": "ng build --base-href ./ && tsc --p electron && electron .",
16-
"electron:build": "ng build --base-href ./ && tsc --p electron && electron-builder build --publish=never"
15+
"electron": "ng build --base-href ./ && tsc --p electron-app && electron .",
16+
"electron:build": "ng build --base-href ./ && tsc --p electron-app && electron-builder build --publish=never"
1717
},
1818
"browser": {
1919
"fs": false,

cider-app/src/app/card-templates/card-templates.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</span>
2727
</div>
2828
<div class="preview-space" >
29-
<app-card-preview [card]="selectedCard" [template]="selectedTemplate"
29+
<app-card-preview [card]="selectedCard" [template]="selectedTemplate" *ngIf="selectedCard"
3030
[style]="{transform: 'translate(-50%, -50%) scale(' + zoom + ') translate(calc(399px/2/' + zoom + '), calc((100vh - 388px)/2/' + zoom + '))'}"
3131
></app-card-preview>
3232
</div>
@@ -38,7 +38,7 @@
3838
<ng-template pTemplate="icons">
3939
<button pButton pRipple icon="pi pi-info-circle" class="p-panel-header-icon p-link" (click)="openCssInfo()"></button>
4040
</ng-template>
41-
<ngx-monaco-editor style="height: 100%;"
41+
<ngx-monaco-editor style="height: 100%;" *ngIf="selectedTemplate"
4242
[options]="cssEditorOptions" [(ngModel)]="selectedTemplate.css"></ngx-monaco-editor>
4343
</p-panel>
4444
</div>
@@ -47,7 +47,7 @@
4747
<ng-template pTemplate="icons">
4848
<button pButton pRipple icon="pi pi-info-circle" class="p-panel-header-icon p-link" (click)="openHtmlInfo()"></button>
4949
</ng-template>
50-
<ngx-monaco-editor style="height: 100%;"
50+
<ngx-monaco-editor style="height: 100%;" *ngIf="selectedTemplate"
5151
[options]="htmlEditorOptions" [(ngModel)]="selectedTemplate.html"></ngx-monaco-editor>
5252
</p-panel>
5353
</div>
Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,49 @@
11
import { Injectable } from '@angular/core';
2+
import { IpcRenderer } from 'electron';
23

34
@Injectable({
45
providedIn: 'root'
56
})
67
export class ElectronService {
78

9+
projectHomeUrl: string | undefined;
10+
811
constructor() {
912
}
1013

1114
/**
12-
* async () => {
13-
* const result = await ipcRenderer.invoke('my-invokable-ipc', arg1, arg2)
14-
* // ...
15-
* }
15+
* Determine if application is running in electron
16+
*
17+
* @returns true/false
1618
*/
19+
public isElectron() : boolean {
20+
return typeof window !== 'undefined'
21+
&& typeof window.process === 'object'
22+
&& (<any>window.process).type === 'renderer';
23+
}
24+
25+
private getIpcRenderer(): IpcRenderer {
26+
return window.require('electron').ipcRenderer;
27+
}
1728

1829
public selectDirectory() {
19-
if (typeof window.require === 'function') {
20-
const ipcRenderer = window.require('electron').ipcRenderer;
21-
ipcRenderer.send("select-directory");
30+
if (!this.isElectron()) {
31+
return;
2232
}
33+
this.getIpcRenderer().send("select-directory");
2334
}
2435

2536
public titlebarDoubleClick() {
26-
if (typeof window.require === 'function') {
27-
const ipcRenderer = window.require('electron').ipcRenderer;
28-
ipcRenderer.send("titlebar-double-clicked");
37+
if (!this.isElectron()) {
38+
return;
39+
}
40+
this.getIpcRenderer().send("titlebar-double-clicked");
41+
}
42+
43+
public exitApplication() {
44+
if (!this.isElectron()) {
45+
return;
2946
}
47+
this.getIpcRenderer().send("exit-application");
3048
}
3149
}

cider-app/src/app/site-content-and-menu/site-content-and-menu.component.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@
4747
-webkit-app-region: none;
4848
}
4949

50+
.p-menubar-root-list > .p-menuitem > .p-menuitem-link {
51+
border-radius: 10px;
52+
}
53+
5054
.p-menuitem.selected-game {
5155
background-color: var(--surface-a);
5256
border-radius: 10px;
5357
}
5458

5559
.p-menuitem.p-menuitem-active > .p-menuitem-link {
56-
background: #2b323d;
60+
background: var(--surface-d);
5761
}
5862
}
5963

cider-app/src/app/site-content-and-menu/site-content-and-menu.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ export class SiteContentAndMenuComponent implements OnInit {
4343
{
4444
label: 'Open Project',
4545
icon: 'pi pi-pw pi-file',
46+
visible: this.electronService.isElectron(),
4647
command: () => this.selectDirectory()
4748
}, {
4849
label: 'Save',
49-
icon: 'pi pi-pw pi-save'
50+
icon: 'pi pi-pw pi-save',
51+
visible: this.electronService.isElectron()
5052
}, {
5153
separator:true
5254
}, {
@@ -74,6 +76,11 @@ export class SiteContentAndMenuComponent implements OnInit {
7476
icon: 'pi pi-pw pi-file-pdf',
7577
disabled: !selectedGame,
7678
routerLink: [`/games/${selectedGame?.id}/export-cards`]
79+
}, {
80+
label: 'Exit Cider',
81+
icon: 'pi pi-pw pi-file',
82+
visible: this.electronService.isElectron(),
83+
command: () => this.exitCider()
7784
}
7885
]
7986
}, {
@@ -179,4 +186,8 @@ export class SiteContentAndMenuComponent implements OnInit {
179186
this.electronService.titlebarDoubleClick();
180187
}
181188

189+
public exitCider() {
190+
this.electronService.exitApplication();
191+
}
192+
182193
}

0 commit comments

Comments
 (0)