Skip to content

Commit 0186556

Browse files
authored
Merge pull request #1627 from hovancik/dm-di
Refactor DisplayManager to remove logging dependency
2 parents 5c91147 + 14b9245 commit 0186556

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

app/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ async function initialize (isAppStart = true) {
274274
app
275275
})
276276

277-
displayManager = new DisplayManager(settings, log)
277+
displayManager = new DisplayManager(settings)
278278

279279
startI18next()
280280
startProcessWin()

app/utils/displayManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { screen } from 'electron'
2+
import log from 'electron-log/main.js'
23

34
class DisplayManager {
4-
constructor (settings, log) {
5+
constructor (settings) {
56
this.settings = settings
6-
this.log = log
77
}
88

99
getDisplayCount () {
@@ -34,7 +34,7 @@ class DisplayManager {
3434
if (displayID === -1) {
3535
targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
3636
} else if (displayID >= this.getDisplayCount() || displayID < 0) {
37-
this.log.warn(`Stretchly: invalid displayID ${displayID}, falling back to cursor display`)
37+
log.warn(`Stretchly: invalid displayID ${displayID}, falling back to cursor display`)
3838
targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
3939
} else {
4040
const screens = screen.getAllDisplays()

test/displayManager.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ vi.mock('electron', () => {
1919
describe('DisplayManager', function () {
2020
let displayManager
2121
let mockSettings
22-
let mockLog
2322

2423
beforeEach(function () {
2524
vi.clearAllMocks()
2625
mockSettings = {
2726
get: vi.fn()
2827
}
29-
mockLog = {
30-
warn: vi.fn()
31-
}
3228
})
3329

3430
describe('Mathematical Calculations', function () {
@@ -37,7 +33,7 @@ describe('DisplayManager', function () {
3733
if (key === 'allScreens') return true
3834
return null
3935
})
40-
displayManager = new DisplayManager(mockSettings, mockLog)
36+
displayManager = new DisplayManager(mockSettings)
4137
})
4238

4339
it('centers window horizontally correctly', function () {
@@ -94,7 +90,7 @@ describe('DisplayManager', function () {
9490
if (key === 'allScreens') return true
9591
return null
9692
})
97-
displayManager = new DisplayManager(mockSettings, mockLog)
93+
displayManager = new DisplayManager(mockSettings)
9894
})
9995

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

164160
describe('Settings Integration', function () {
165161
beforeEach(function () {
166-
displayManager = new DisplayManager(mockSettings, mockLog)
162+
displayManager = new DisplayManager(mockSettings)
167163
})
168164

169165
it('uses cursor position when allScreens is true', function () {
@@ -213,12 +209,11 @@ describe('DisplayManager', function () {
213209
if (key === 'allScreens') return true
214210
return null
215211
})
216-
displayManager = new DisplayManager(mockSettings, mockLog)
212+
displayManager = new DisplayManager(mockSettings)
217213
})
218214

219-
it('handles invalid displayID by falling back and logging a warning', () => {
215+
it('handles invalid displayID by falling back to cursor display', () => {
220216
const target = displayManager.getTargetDisplay(5)
221-
expect(mockLog.warn).toHaveBeenCalledWith('Stretchly: invalid displayID 5, falling back to cursor display')
222217
expect(screen.getDisplayNearestPoint).toHaveBeenCalled()
223218
target.id.should.equal(0)
224219
})

0 commit comments

Comments
 (0)