Skip to content

Commit 0e18af4

Browse files
committed
Update shortcut handling and asset paths
Refactored Electron global shortcut registration for better maintainability and added common edit shortcuts. Updated asset paths in loading component and translation service to use relative paths. Fixed usage of getCurrentLang() in app.component.ts.
1 parent 371b72f commit 0e18af4

File tree

4 files changed

+65
-35
lines changed

4 files changed

+65
-35
lines changed

core/apps/ame/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ export class AppComponent implements OnInit {
143143
}
144144

145145
setMenuTranslation(): void {
146-
this.electronTunnelService.sendTranslationsToElectron(this.translate.translateService.currentLang);
146+
this.electronTunnelService.sendTranslationsToElectron(this.translate.translateService.getCurrentLang());
147147
}
148148
}

core/apps/ame/src/app/components/loading/loading.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
-->
1313

1414
<div class="loading-container">
15-
<img ngSrc="'assets/img/png/aspect-model-editor-targetsize-256.png'" alt="AME Logo" fill />
15+
<img ngSrc="'./assets/img/png/aspect-model-editor-targetsize-256.png'" alt="AME Logo" fill />
1616
<h2>Opening editor...</h2>
1717
</div>

core/electron-libs/shortcuts.js

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,77 @@
1414
const {app, globalShortcut, BrowserWindow, Menu, nativeTheme} = require('electron');
1515
const platformData = require('./os-checker');
1616

17-
function registerGlobalShortcuts() {
18-
const globalShortcuts = [
19-
{key: 'CommandOrControl+W', action: () => BrowserWindow.getFocusedWindow()?.close()},
20-
{key: 'CommandOrControl+M', action: () => BrowserWindow.getFocusedWindow()?.minimize()},
21-
{key: 'CommandOrControl+Shift+M', action: () => BrowserWindow.getFocusedWindow()?.maximize()},
22-
{key: 'CommandOrControl+Shift+F', action: () => BrowserWindow.getFocusedWindow()?.setFullScreen(true)},
23-
{key: 'CommandOrControl+Shift+G', action: () => BrowserWindow.getFocusedWindow()?.setFullScreen(false)},
24-
];
17+
const COMMON_SHORTCUTS = [
18+
{key: 'CommandOrControl+W', action: win => win.close()},
19+
{key: 'CommandOrControl+M', action: win => win.minimize()},
20+
{key: 'CommandOrControl+Shift+M', action: win => win.maximize()},
21+
{key: 'CommandOrControl+Shift+F', action: win => win.setFullScreen(true)},
22+
{key: 'CommandOrControl+Shift+G', action: win => win.setFullScreen(false)},
23+
// Edit operations
24+
{key: 'CommandOrControl+X', action: win => win.webContents.cut()},
25+
{key: 'CommandOrControl+C', action: win => win.webContents.copy()},
26+
{key: 'CommandOrControl+V', action: win => win.webContents.paste()},
27+
{key: 'CommandOrControl+Z', action: win => win.webContents.undo()},
28+
{key: 'CommandOrControl+A', action: win => win.webContents.selectAll()},
29+
{key: 'CommandOrControl+R', action: win => win.reload()},
30+
];
2531

26-
const macShortcuts = [
27-
{key: 'CommandOrControl+Q', action: () => (BrowserWindow.getFocusedWindow() ? app.quit() : null)},
28-
{key: 'Command+Option+I', action: () => BrowserWindow.getFocusedWindow().webContents.openDevTools()},
29-
{key: 'CommandOrControl+R', action: () => BrowserWindow.getFocusedWindow()?.reload()},
30-
{
31-
key: 'CommandOrControl+Shift+R',
32-
action: () => BrowserWindow.getFocusedWindow()?.webContents.reloadIgnoringCache(),
32+
const MAC_SHORTCUTS = [
33+
{
34+
key: 'CommandOrControl+Q',
35+
action: () => {
36+
const win = BrowserWindow.getFocusedWindow();
37+
if (win) {
38+
app.quit();
39+
}
40+
},
41+
},
42+
{
43+
key: 'Command+Option+I',
44+
action: () => {
45+
const win = BrowserWindow.getFocusedWindow();
46+
win?.webContents.openDevTools();
3347
},
34-
];
48+
},
49+
];
3550

36-
const openDevShortcut = [{key: 'Control+Shift+I', action: () => BrowserWindow.getFocusedWindow().webContents.openDevTools()}];
51+
const DEVTOOLS_SHORTCUTS = [
52+
{
53+
key: 'Control+Shift+I',
54+
action: () => {
55+
const win = BrowserWindow.getFocusedWindow();
56+
win?.webContents.openDevTools();
57+
},
58+
},
59+
];
3760

38-
globalShortcuts.forEach(({key, action}) => {
39-
globalShortcut.register(key, action);
61+
function registerShortcut({key, action}) {
62+
globalShortcut.register(key, () => {
63+
const focusedWindow = BrowserWindow.getFocusedWindow();
64+
if (!focusedWindow && action.length > 0) {
65+
// For actions that rely on a window, do nothing if there is none
66+
return;
67+
}
68+
69+
if (action.length > 0) {
70+
// action expects a window
71+
action(focusedWindow);
72+
} else {
73+
// action handles its own window lookup
74+
action();
75+
}
4076
});
77+
}
4178

42-
if (platformData.isMac) {
43-
macShortcuts.forEach(({key, action}) => {
44-
globalShortcut.register(key, action);
45-
});
46-
}
79+
function registerGlobalShortcuts() {
80+
COMMON_SHORTCUTS.forEach(registerShortcut);
4781

48-
if (platformData.isWin) {
49-
openDevShortcut.forEach(({key, action}) => {
50-
globalShortcut.register(key, action);
51-
});
82+
if (platformData.isMac) {
83+
MAC_SHORTCUTS.forEach(registerShortcut);
5284
}
5385

54-
if (platformData.isLinux) {
55-
openDevShortcut.forEach(({key, action}) => {
56-
globalShortcut.register(key, action);
57-
});
86+
if (platformData.isWin || platformData.isLinux) {
87+
DEVTOOLS_SHORTCUTS.forEach(registerShortcut);
5888
}
5989
}
6090

core/libs/translation/src/lib/services/language-translation.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class LanguageTranslationService {
5252
}
5353

5454
getTranslation(language: string): Observable<Translation> {
55-
return this.http.get<Translation>(`/assets/i18n/${language}.json`).pipe(
55+
return this.http.get<Translation>(`./assets/i18n/${language}.json`).pipe(
5656
takeUntilDestroyed(this.destroyRef),
5757
tap((translation: Translation) => (this.language = translation)),
5858
);

0 commit comments

Comments
 (0)