-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: bring window into nest app & restructure main functions and…
… remove unused modules - Migrate utility functions to `functions` directory for better organization. - Remove obsolete `store` related files to streamline codebase. - Update imports and mocks across the codebase to reflect new directory structure. - Replace `Store` usage with a more persistent and reliable settings storage mechanism using `WindowSetting` schema. - Enhance main window lifecycle management in `MainWindow` service. - Update application bootstrap process with `bootstrapNestApplication`.
- Loading branch information
🎲
committed
Dec 21, 2024
1 parent
a005078
commit ef6ea41
Showing
27 changed files
with
389 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { NestFactory } from '@nestjs/core' | ||
import { AppModule } from '../app.module' | ||
import { WinstonModule } from 'nest-winston' | ||
import { consoleTransport, fileTransport } from '../logging' | ||
import { Logger, ShutdownSignal } from '@nestjs/common' | ||
import { BrowserWindow } from 'electron' | ||
import { join } from 'node:path' | ||
|
||
export async function bootstrapNestApplication() { | ||
const logger = new Logger('bootstrap') | ||
logger.log('Bootstrapping application') | ||
const splashScreen = new BrowserWindow({ | ||
width: 1050, | ||
height: 600, | ||
show: true, | ||
frame: false, | ||
alwaysOnTop: false | ||
}) | ||
await splashScreen.loadFile(join(__dirname, '../../resources/splash.png')) | ||
splashScreen.setTitle('DCS Dropzone Mod Manager') | ||
|
||
try { | ||
logger.log('Creating application context') | ||
const applicationContext = await NestFactory.createApplicationContext(AppModule, { | ||
abortOnError: false, | ||
logger: WinstonModule.createLogger({ | ||
level: 'silly', | ||
transports: [consoleTransport, fileTransport] | ||
}) | ||
}) | ||
applicationContext.enableShutdownHooks([ShutdownSignal.SIGTERM, ShutdownSignal.SIGINT]) | ||
|
||
logger.log('Initializing application context') | ||
await applicationContext.init() | ||
|
||
logger.log('Application context initialized, closing splash screen') | ||
splashScreen.close() | ||
|
||
return applicationContext | ||
} catch (e) { | ||
splashScreen.close() | ||
logger.error('Failed to bootstrap application', e) | ||
throw e | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/main/utils/get-release-asset.ts → src/main/functions/get-release-asset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,60 @@ | ||
import { describe, it, expect, vi } from 'vitest' | ||
import { BrowserWindow } from 'electron' | ||
import { onBrowserWindowMovement } from './onMainWindowMovement' | ||
import { Store } from '../utils/store' | ||
|
||
describe('onBrowserWindowMovement', () => { | ||
it('stores window size and position when window is moved', async () => { | ||
it('saves window position and size correctly', async () => { | ||
const mockWindow = { | ||
getSize: vi.fn().mockReturnValue([800, 600]), | ||
getPosition: vi.fn().mockReturnValue([100, 100]), | ||
getSize: vi.fn().mockReturnValue([1024, 768]), | ||
getPosition: vi.fn().mockReturnValue([200, 150]), | ||
isMaximized: vi.fn().mockReturnValue(false) | ||
} as unknown as BrowserWindow | ||
|
||
const mockStore = { | ||
set: vi.fn(), | ||
write: vi.fn().mockResolvedValue(undefined) | ||
} as unknown as Store<number> | ||
const saveWindowPosition = vi.fn().mockResolvedValue(undefined) | ||
|
||
const handler = onBrowserWindowMovement(mockWindow, mockStore) | ||
const handler = onBrowserWindowMovement(mockWindow, saveWindowPosition) | ||
await handler() | ||
|
||
expect(mockStore.set).toHaveBeenCalledWith('width', 800) | ||
expect(mockStore.set).toHaveBeenCalledWith('height', 600) | ||
expect(mockStore.set).toHaveBeenCalledWith('x', 100) | ||
expect(mockStore.set).toHaveBeenCalledWith('y', 100) | ||
expect(mockStore.set).toHaveBeenCalledWith('maximized', 0) | ||
expect(mockStore.write).toHaveBeenCalled() | ||
expect(saveWindowPosition).toHaveBeenCalledWith({ | ||
width: 1024, | ||
height: 768, | ||
x: 200, | ||
y: 150, | ||
maximized: false | ||
}) | ||
}) | ||
|
||
it('stores maximized state when window is maximized', async () => { | ||
it('saves maximized state correctly', async () => { | ||
const mockWindow = { | ||
getSize: vi.fn().mockReturnValue([800, 600]), | ||
getPosition: vi.fn().mockReturnValue([100, 100]), | ||
getSize: vi.fn().mockReturnValue([1024, 768]), | ||
getPosition: vi.fn().mockReturnValue([200, 150]), | ||
isMaximized: vi.fn().mockReturnValue(true) | ||
} as unknown as BrowserWindow | ||
|
||
const mockStore = { | ||
set: vi.fn(), | ||
write: vi.fn().mockResolvedValue(undefined) | ||
} as unknown as Store<number> | ||
const saveWindowPosition = vi.fn().mockResolvedValue(undefined) | ||
|
||
const handler = onBrowserWindowMovement(mockWindow, mockStore) | ||
const handler = onBrowserWindowMovement(mockWindow, saveWindowPosition) | ||
await handler() | ||
|
||
expect(mockStore.set).toHaveBeenCalledWith('maximized', 1) | ||
expect(saveWindowPosition).toHaveBeenCalledWith({ | ||
width: 1024, | ||
height: 768, | ||
x: 200, | ||
y: 150, | ||
maximized: true | ||
}) | ||
}) | ||
|
||
it('handles errors during store write', async () => { | ||
it('handles errors during saveWindowPosition call', async () => { | ||
const mockWindow = { | ||
getSize: vi.fn().mockReturnValue([800, 600]), | ||
getPosition: vi.fn().mockReturnValue([100, 100]), | ||
getSize: vi.fn().mockReturnValue([1024, 768]), | ||
getPosition: vi.fn().mockReturnValue([200, 150]), | ||
isMaximized: vi.fn().mockReturnValue(false) | ||
} as unknown as BrowserWindow | ||
|
||
const mockStore = { | ||
set: vi.fn(), | ||
write: vi.fn().mockRejectedValue(new Error('Write failed')) | ||
} as unknown as Store<number> | ||
const saveWindowPosition = vi.fn().mockRejectedValue(new Error('Save failed')) | ||
|
||
const handler = onBrowserWindowMovement(mockWindow, mockStore) | ||
await expect(handler()).rejects.toThrow('Write failed') | ||
const handler = onBrowserWindowMovement(mockWindow, saveWindowPosition) | ||
await expect(handler()).rejects.toThrow('Save failed') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { BrowserWindow } from 'electron' | ||
import { Store } from '../utils/store' | ||
|
||
export function onBrowserWindowMovement(window: BrowserWindow, store: Store<number>) { | ||
export function onBrowserWindowMovement( | ||
window: BrowserWindow, | ||
saveWindowPosition: ({}: { | ||
width: number | ||
height: number | ||
x: number | ||
y: number | ||
maximized: boolean | ||
}) => Promise<any> | ||
) { | ||
return async function () { | ||
const [width, height] = window.getSize() | ||
const [x, y] = window.getPosition() | ||
const isMaximized = window.isMaximized() | ||
store.set('width', width) | ||
store.set('height', height) | ||
store.set('x', x) | ||
store.set('y', y) | ||
store.set('maximized', isMaximized ? 1 : 0) | ||
await store.write() | ||
const maximized = window.isMaximized() | ||
await saveWindowPosition({ width, height, x, y, maximized }) | ||
} | ||
} |
Oops, something went wrong.