Skip to content

Commit

Permalink
Fix/about page desktop window (#8461)
Browse files Browse the repository at this point in the history
* fix: about page desktop window

* fix: about window not fit in windows platform

* fix: about window not fit in windows platform

* fix: prevent multiple about window

* fix: prevent timer window change size on drag the window

* fix: remove unnecessary code
  • Loading branch information
syns2191 authored Oct 25, 2024
1 parent 96c1715 commit 33f0b08
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 18 deletions.
4 changes: 4 additions & 0 deletions apps/desktop-timer/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ window.addEventListener('DOMContentLoaded', async () => {
titleBar.refreshMenu();
});

ipcRenderer.on('hide-menu', () => {
titleBar.dispose();
})

const overStyle = document.createElement('style');
overStyle.innerHTML = `
.cet-container {
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ window.addEventListener('DOMContentLoaded', async () => {
titleBar.refreshMenu();
});

ipcRenderer.on('hide-menu', () => {
titleBar.dispose();
})

ipcRenderer.on('adjust_view', () => {
clearInterval(contentInterval);
const headerIcon = '/html/body/div[2]/ga-app/ngx-pages/ngx-one-column-layout/nb-layout/div[1]/div/div/nb-sidebar[1]/div/div/div';
Expand Down
4 changes: 4 additions & 0 deletions apps/server-api/src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ window.addEventListener('DOMContentLoaded', async () => {
titleBar.refreshMenu();
});

ipcRenderer.on('hide-menu', () => {
titleBar.dispose();
})

const overStyle = document.createElement('style');
overStyle.innerHTML = `
.cet-menubar-menu-container {
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ window.addEventListener('DOMContentLoaded', async () => {
titleBar.refreshMenu();
});

ipcRenderer.on('hide-menu', () => {
titleBar.dispose();
})

const overStyle = document.createElement('style');
overStyle.innerHTML = `
.cet-menubar-menu-container {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-libs/src/lib/desktop-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AppMenu {
label: TranslateService.instant('MENU.ABOUT'),
enabled: true,
async click() {
const window: BrowserWindow = await createAboutWindow(windowPath.timeTrackerUi);
const window: BrowserWindow = await createAboutWindow(windowPath.timeTrackerUi, windowPath.preloadPath);
window.show();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
<span>
Copyright © 2020-{{'FOOTER.PRESENT' | translate}}
<span class="link" (click)="openLink('EVER')">{{ application?.companyName}}</span>
<br/>
<br />
{{'FOOTER.RIGHTS_RESERVED' | translate}}
<br/>
<span class="link" (click)="openLink('TOS')">{{'FOOTER.TERMS_OF_SERVICE' | translate}}</span> |
<span (click)="openLink('PRIVACY')" class="link">{{'FOOTER.PRIVACY_POLICY' | translate}}</span>
<br />
<span class="link" (click)="openLink('TOS')">{{'FOOTER.TERMS_OF_SERVICE' |
translate}}</span> |
<span (click)="openLink('PRIVACY')" class="link">{{'FOOTER.PRIVACY_POLICY' |
translate}}</span>
</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ div.logo {

::ng-deep nb-layout .layout .layout-container .content nb-layout-footer nav {
padding: 0px;
}
}
15 changes: 8 additions & 7 deletions packages/desktop-window/src/lib/desktop-window-about.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as remoteMain from '@electron/remote/main';
import { BrowserWindow, Menu } from 'electron';
import * as url from 'url';
import { attachTitlebarToWindow } from 'custom-electron-titlebar/main';

import log from 'electron-log';
import { WindowManager } from './concretes/window.manager';
Expand All @@ -16,6 +15,13 @@ export async function createAboutWindow(filePath, preloadPath?) {
const mainWindowSettings: Electron.BrowserWindowConstructorOptions = windowSetting(preloadPath);
const manager = WindowManager.getInstance();

const allwindows = BrowserWindow.getAllWindows();

Check warning on line 18 in packages/desktop-window/src/lib/desktop-window-about.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (allwindows)
const aboutWindows = allwindows.find((win) => win.getTitle() === 'About');

Check warning on line 19 in packages/desktop-window/src/lib/desktop-window-about.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (allwindows)
if (aboutWindows) {
aboutWindows.show();
return aboutWindows;
}

const window = new BrowserWindow(mainWindowSettings);
remoteMain.enable(window.webContents);
const launchPath = url.format({
Expand All @@ -42,7 +48,7 @@ export async function createAboutWindow(filePath, preloadPath?) {

manager.register(RegisteredWindow.ABOUT, window);
if (preloadPath) {
attachTitlebarToWindow(window);
window.webContents.send('hide-menu');
}
return window;
}
Expand All @@ -69,11 +75,6 @@ const windowSetting = (preloadPath) => {
};
if (preloadPath) {
mainWindowSettings.webPreferences.preload = preloadPath;
mainWindowSettings.titleBarOverlay = true;
mainWindowSettings.titleBarStyle = 'hidden';
if (process.platform === 'linux') {
mainWindowSettings.frame = false;
}
}
return mainWindowSettings;
};
19 changes: 14 additions & 5 deletions packages/desktop-window/src/lib/desktop-window-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Object.assign(console, log.functions);
const Store = require('electron-store');
const store = new Store();

function getScreenSize() {
const sizes = screen.getPrimaryDisplay().workAreaSize;
const width = sizes.height < 768 ? 310 : 360;
const height = sizes.height < 768 ? sizes.height - 20 : 768;
return { width, height }
}

export async function createTimeTrackerWindow(timeTrackerWindow, filePath, preloadPath?) {
const mainWindowSettings: Electron.BrowserWindowConstructorOptions = windowSetting(preloadPath);
const manager = WindowManager.getInstance();
Expand All @@ -29,24 +36,26 @@ export async function createTimeTrackerWindow(timeTrackerWindow, filePath, prelo

timeTrackerWindow.hide();
await timeTrackerWindow.loadURL(launchPath);
if (preloadPath) {
attachTitlebarToWindow(timeTrackerWindow);
}
const { width, height } = getScreenSize();
timeTrackerWindow.setMinimumSize(width, height);
timeTrackerWindow.setMenu(null);
timeTrackerWindow.on('close', (event) => {
event.preventDefault();
timeTrackerWindow.hide();
});

manager.register(RegisteredWindow.TIMER, timeTrackerWindow);
if (preloadPath) {
attachTitlebarToWindow(timeTrackerWindow);
}

return timeTrackerWindow;
}

const windowSetting = (preloadPath?) => {
const sizes = screen.getPrimaryDisplay().workAreaSize;
const height = sizes.height < 768 ? sizes.height - 20 : 768;
const { width, height } = getScreenSize();
const zoomF = sizes.height < 768 ? 0.8 : 1.0;
const width = sizes.height < 768 ? 310 : 360;
const filesPath = store.get('filePath');
console.log('file path == ', filesPath);
const mainWindowSettings: Electron.BrowserWindowConstructorOptions = {
Expand Down

0 comments on commit 33f0b08

Please sign in to comment.