|
1 | | -import { app, BrowserWindow, ipcMain, desktopCapturer, dialog, nativeImage, shell, systemPreferences, Tray } from 'electron' |
| 1 | +import { app, BrowserWindow, ipcMain, desktopCapturer, dialog, nativeImage, shell, systemPreferences, Tray, screen } from 'electron' |
2 | 2 | import os from 'os'; |
3 | 3 | import axios from 'axios'; |
4 | 4 | const { getWindows, activateWindow } = require('mac-windows'); |
@@ -512,7 +512,7 @@ ipcMain.handle('show-camera-window', async (_, show: boolean) => { |
512 | 512 | }); |
513 | 513 |
|
514 | 514 | const toggleCameraWindow = (show: boolean) => { |
515 | | - if (webcamWindow) { |
| 515 | + if (webcamWindow && !webcamWindow.isDestroyed()) { |
516 | 516 | showCameraWindow = show; |
517 | 517 | if (show) webcamWindow.show(); |
518 | 518 | else webcamWindow.hide(); |
@@ -847,7 +847,7 @@ const requestPermissions = async (permission: string): Promise<boolean> => { |
847 | 847 | function createFloatingWindow() { |
848 | 848 | const floatingWindow = new BrowserWindow({ |
849 | 849 | width: 60, |
850 | | - height: 150, |
| 850 | + height: 130, |
851 | 851 | x: 0, |
852 | 852 | y: 0, |
853 | 853 | resizable: false, |
@@ -881,15 +881,18 @@ function createFloatingWindow() { |
881 | 881 |
|
882 | 882 | const createWebcamWindow = () => { |
883 | 883 |
|
884 | | - const scalingFactor = 1; |
885 | | - const monitorHeight = 1080; |
| 884 | + const primaryDisplay = screen.getPrimaryDisplay(); |
| 885 | + |
| 886 | + const scalingFactor = primaryDisplay.scaleFactor; |
| 887 | + const monitorHeight = primaryDisplay.workAreaSize.height; |
| 888 | + // const monitorHeight = 1080; |
886 | 889 | const windowHeight = 232; |
887 | 890 | // const windowHeight = 1000; |
888 | 891 | const windowWidth = 200; |
889 | 892 | // const windowWidth = 1000; |
890 | 893 | const x = 100; |
891 | 894 | const y = |
892 | | - monitorHeight / scalingFactor - windowHeight - 100; |
| 895 | + monitorHeight / scalingFactor - windowHeight - 0; |
893 | 896 |
|
894 | 897 | const webcamWindow = new BrowserWindow({ |
895 | 898 | transparent: true, |
@@ -930,7 +933,7 @@ function createWindow() { |
930 | 933 | autoUpdater.forceDevUpdateConfig = true; |
931 | 934 | autoUpdater.checkForUpdates(); |
932 | 935 |
|
933 | | - if (mainWindow) { |
| 936 | + if (mainWindow && !mainWindow.isDestroyed()) { |
934 | 937 | mainWindow.focus(); |
935 | 938 | return; |
936 | 939 | } |
@@ -962,6 +965,17 @@ function createWindow() { |
962 | 965 | mainWindow?.webContents.send('main-process-message', (new Date).toLocaleString()) |
963 | 966 | }) |
964 | 967 |
|
| 968 | + // Close other windows when mainWindow is closed |
| 969 | + mainWindow.on('closed', () => { |
| 970 | + if (floatingWindow && !floatingWindow.isDestroyed()) { |
| 971 | + floatingWindow.close(); |
| 972 | + } |
| 973 | + if (webcamWindow && !webcamWindow.isDestroyed()) { |
| 974 | + webcamWindow.close(); |
| 975 | + } |
| 976 | + mainWindow = null; // Dereference the window object |
| 977 | + }); |
| 978 | + |
965 | 979 |
|
966 | 980 | // Create the floating window and hide it |
967 | 981 | floatingWindow = createFloatingWindow(); |
@@ -1081,7 +1095,6 @@ function createWindow() { |
1081 | 1095 | app.on('window-all-closed', () => { |
1082 | 1096 | if (process.platform !== 'darwin') { |
1083 | 1097 | app.quit() |
1084 | | - mainWindow = null |
1085 | 1098 | } |
1086 | 1099 | }) |
1087 | 1100 |
|
|
0 commit comments