Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ async function initialize (isAppStart = true) {
app
})

displayManager = new DisplayManager(settings, log)
displayManager = new DisplayManager(settings)

startI18next()
startProcessWin()
Expand Down
6 changes: 3 additions & 3 deletions app/utils/displayManager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { screen } from 'electron'
import log from 'electron-log/main.js'

class DisplayManager {
constructor (settings, log) {
constructor (settings) {
this.settings = settings
Comment on lines +5 to 6
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from dependency injection to direct import reduces testability and makes the DisplayManager class tightly coupled to the electron-log module. Consider keeping the log parameter optional to maintain flexibility for testing while providing a default import.

Suggested change
constructor (settings) {
this.settings = settings
constructor (settings, logInstance = log) {
this.settings = settings
this.log = logInstance

Copilot uses AI. Check for mistakes.
this.log = log
}

getDisplayCount () {
Expand Down Expand Up @@ -34,7 +34,7 @@ class DisplayManager {
if (displayID === -1) {
targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
} else if (displayID >= this.getDisplayCount() || displayID < 0) {
this.log.warn(`Stretchly: invalid displayID ${displayID}, falling back to cursor display`)
log.warn(`Stretchly: invalid displayID ${displayID}, falling back to cursor display`)
targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
} else {
const screens = screen.getAllDisplays()
Expand Down
15 changes: 5 additions & 10 deletions test/displayManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ vi.mock('electron', () => {
describe('DisplayManager', function () {
let displayManager
let mockSettings
let mockLog

beforeEach(function () {
vi.clearAllMocks()
mockSettings = {
get: vi.fn()
}
mockLog = {
warn: vi.fn()
}
})

describe('Mathematical Calculations', function () {
Expand All @@ -37,7 +33,7 @@ describe('DisplayManager', function () {
if (key === 'allScreens') return true
return null
})
displayManager = new DisplayManager(mockSettings, mockLog)
displayManager = new DisplayManager(mockSettings)
})

it('centers window horizontally correctly', function () {
Expand Down Expand Up @@ -94,7 +90,7 @@ describe('DisplayManager', function () {
if (key === 'allScreens') return true
return null
})
displayManager = new DisplayManager(mockSettings, mockLog)
displayManager = new DisplayManager(mockSettings)
})

it('getWindowPosition returns consistent windowed positioning', function () {
Expand Down Expand Up @@ -163,7 +159,7 @@ describe('DisplayManager', function () {

describe('Settings Integration', function () {
beforeEach(function () {
displayManager = new DisplayManager(mockSettings, mockLog)
displayManager = new DisplayManager(mockSettings)
})

it('uses cursor position when allScreens is true', function () {
Expand Down Expand Up @@ -213,12 +209,11 @@ describe('DisplayManager', function () {
if (key === 'allScreens') return true
return null
})
displayManager = new DisplayManager(mockSettings, mockLog)
displayManager = new DisplayManager(mockSettings)
})

it('handles invalid displayID by falling back and logging a warning', () => {
it('handles invalid displayID by falling back to cursor display', () => {
const target = displayManager.getTargetDisplay(5)
expect(mockLog.warn).toHaveBeenCalledWith('Stretchly: invalid displayID 5, falling back to cursor display')
expect(screen.getDisplayNearestPoint).toHaveBeenCalled()
target.id.should.equal(0)
})
Expand Down
Loading