|
1 | | -import { BrowserWindow, Menu, MenuItemConstructorOptions, Notification, app, ipcMain, screen, shell } from 'electron'; |
| 1 | +import { BrowserWindow, Menu, MenuItemConstructorOptions, Notification, app, screen, shell } from 'electron'; |
2 | 2 | import { autoUpdater } from 'electron-updater'; |
3 | 3 | import activeWindows from 'mezon-active-windows'; |
4 | 4 | import { join } from 'path'; |
5 | 5 | import { format } from 'url'; |
6 | | -import { electronAppName, rendererAppName, rendererAppPort } from './constants'; |
| 6 | +import { rendererAppName, rendererAppPort } from './constants'; |
7 | 7 |
|
8 | 8 | import tray from '../Tray'; |
9 | 9 | import setupAutoUpdates from './autoUpdates'; |
10 | | -import { |
11 | | - ACTIVE_WINDOW, |
12 | | - CHANGE_ATTACHMENT_LIST, |
13 | | - GET_ATTACHMENT_DATA, |
14 | | - SEND_ATTACHMENT_DATA, |
15 | | - SET_ATTACHMENT_DATA, |
16 | | - SET_CURRENT_IMAGE, |
17 | | - TRIGGER_SHORTCUT |
18 | | -} from './events/constants'; |
| 10 | +import { ACTIVE_WINDOW, TRIGGER_SHORTCUT } from './events/constants'; |
19 | 11 | import setupRequestPermission from './requestPermission'; |
20 | 12 | import { initBadge } from './services/badge'; |
21 | 13 | import { forceQuit } from './utils'; |
@@ -259,96 +251,6 @@ export default class App { |
259 | 251 | return window !== null && !window.isDestroyed(); |
260 | 252 | } |
261 | 253 |
|
262 | | - static openImageWindow(props: any, options?: Electron.BrowserWindowConstructorOptions, params?: Record<string, string>) { |
263 | | - const defaultOptions: Electron.BrowserWindowConstructorOptions = { |
264 | | - width: 1000, |
265 | | - height: 800, |
266 | | - backgroundColor: '#1a1a1a', |
267 | | - show: false, |
268 | | - titleBarStyle: 'hidden', |
269 | | - frame: false, |
270 | | - trafficLightPosition: process.platform == 'darwin' ? { x: -20, y: -20 } : undefined, |
271 | | - webPreferences: { |
272 | | - nodeIntegration: false, |
273 | | - contextIsolation: true, |
274 | | - preload: join(__dirname, 'main.preload.js'), |
275 | | - backgroundThrottling: false |
276 | | - }, |
277 | | - autoHideMenuBar: true, |
278 | | - titleBarOverlay: false, |
279 | | - paintWhenInitiallyHidden: true, |
280 | | - visualEffectState: 'active' |
281 | | - }; |
282 | | - |
283 | | - const windowOptions = { ...defaultOptions, ...options }; |
284 | | - |
285 | | - if (!this.isWindowValid(this.imageViewerWindow) && !this.listWindowOpen?.[IMAGE_WINDOW_KEY]) { |
286 | | - this.imageViewerWindow = new BrowserWindow(windowOptions); |
287 | | - this.listWindowOpen = { |
288 | | - ...this.listWindowOpen, |
289 | | - [IMAGE_WINDOW_KEY]: this.imageViewerWindow |
290 | | - }; |
291 | | - |
292 | | - const emptyMenu = Menu.buildFromTemplate([]); |
293 | | - this.imageViewerWindow.setMenu(emptyMenu); |
294 | | - this.imageViewerWindow.setMenuBarVisibility(false); |
295 | | - // this.imageViewerWindow.setOpacity(0); |
296 | | - |
297 | | - const filePath = App.application.isPackaged |
298 | | - ? 'assets/image-window/image-window.html' |
299 | | - : 'apps/desktop/src/assets/image-window/image-window.html'; |
300 | | - const baseUrl = App.application.isPackaged |
301 | | - ? join(__dirname, '..', electronAppName, filePath) |
302 | | - : join(__dirname, '..', '..', '..', filePath); |
303 | | - const fullUrl = this.generateFullUrl(baseUrl, params); |
304 | | - |
305 | | - const loadContent = async () => { |
306 | | - try { |
307 | | - this.imageViewerWindow.loadURL( |
308 | | - format({ |
309 | | - pathname: fullUrl, |
310 | | - protocol: 'file:', |
311 | | - slashes: true, |
312 | | - query: params |
313 | | - }) |
314 | | - ); |
315 | | - } catch (error) { |
316 | | - console.error('Failed to load window:', error); |
317 | | - } |
318 | | - }; |
319 | | - |
320 | | - loadContent(); |
321 | | - this.imageViewerWindow?.show(); |
322 | | - } |
323 | | - |
324 | | - if (!App.application.isPackaged) { |
325 | | - this.imageViewerWindow.webContents.removeAllListeners('did-fail-load'); |
326 | | - this.imageViewerWindow.webContents.on('did-fail-load', (_, code, description) => { |
327 | | - console.error('Window load failed:', code, description); |
328 | | - }); |
329 | | - } |
330 | | - |
331 | | - this.imageViewerWindow?.setOpacity(1); |
332 | | - this.imageViewerWindow.removeAllListeners('closed'); |
333 | | - this.imageViewerWindow.on('closed', () => { |
334 | | - this.imageViewerWindow = null; |
335 | | - delete this.listWindowOpen[IMAGE_WINDOW_KEY]; |
336 | | - }); |
337 | | - ipcMain.removeAllListeners(SEND_ATTACHMENT_DATA); |
338 | | - ipcMain.on(SEND_ATTACHMENT_DATA, (event, data) => { |
339 | | - this.attachmentData = data; |
340 | | - this.imageViewerWindow.webContents.send(CHANGE_ATTACHMENT_LIST); |
341 | | - }); |
342 | | - ipcMain.removeAllListeners(GET_ATTACHMENT_DATA); |
343 | | - ipcMain.on(GET_ATTACHMENT_DATA, () => { |
344 | | - this.imageViewerWindow.webContents.send(SET_CURRENT_IMAGE, props); |
345 | | - this.imageViewerWindow.webContents.send(SET_ATTACHMENT_DATA, this.attachmentData); |
346 | | - }); |
347 | | - this.imageViewerWindow?.focus(); |
348 | | - |
349 | | - return this.imageViewerWindow; |
350 | | - } |
351 | | - |
352 | 254 | /** |
353 | 255 | * setup badge for the app |
354 | 256 | */ |
|
0 commit comments