Skip to content

Commit ac6951c

Browse files
committed
Refactor display handling to use displayManager methods directly
1 parent 128c52f commit ac6951c

1 file changed

Lines changed: 32 additions & 52 deletions

File tree

app/main.js

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,6 @@ function startPowerMonitoring () {
382382
powerMonitor.on('unlock-screen', onResumeOrUnlock)
383383
}
384384

385-
function numberOfDisplays () {
386-
return displayManager.getDisplayCount()
387-
}
388-
389385
function closeWindows (windowArray) {
390386
for (const window of windowArray) {
391387
window.hide()
@@ -398,22 +394,6 @@ function closeWindows (windowArray) {
398394
return null
399395
}
400396

401-
function displaysX (displayID = -1, width = 800, fullscreen = false) {
402-
return displayManager.getDisplayX(displayID, width, fullscreen)
403-
}
404-
405-
function displaysY (displayID = -1, height = 600, fullscreen = false) {
406-
return displayManager.getDisplayY(displayID, height, fullscreen)
407-
}
408-
409-
function displaysWidth (displayID = -1) {
410-
return displayManager.getDisplayWidth(displayID)
411-
}
412-
413-
function displaysHeight (displayID = -1) {
414-
return displayManager.getDisplayHeight(displayID)
415-
}
416-
417397
function trayIconPath () {
418398
const params = {
419399
paused:
@@ -475,8 +455,8 @@ function createWelcomeWindow (isAppStart = true) {
475455
if (settings.get('isFirstRun') && isAppStart) {
476456
const modalPath = 'file://' + join(__dirname, '/welcome.html')
477457
welcomeWin = new BrowserWindow({
478-
x: displaysX(-1, 1000),
479-
y: displaysY(-1, 750),
458+
x: displayManager.getDisplayX(-1, 1000),
459+
y: displayManager.getDisplayY(-1, 750),
480460
width: 1000,
481461
height: 750,
482462
show: false,
@@ -506,8 +486,8 @@ function createContributorSettingsWindow () {
506486
}
507487
const modalPath = 'file://' + join(__dirname, '/contributor-preferences.html')
508488
contributorPreferencesWin = new BrowserWindow({
509-
x: displaysX(-1, 735),
510-
y: displaysY(),
489+
x: displayManager.getDisplayX(-1, 735),
490+
y: displayManager.getDisplayY(),
511491
width: 735,
512492
show: false,
513493
autoHideMenuBar: true,
@@ -541,8 +521,8 @@ function createSyncPreferencesWindow () {
541521
width: 1000,
542522
height: 700,
543523
icon: windowIconPath(),
544-
x: displaysX(),
545-
y: displaysY(),
524+
x: displayManager.getDisplayX(),
525+
y: displayManager.getDisplayY(),
546526
backgroundColor: 'whitesmoke',
547527
webPreferences: {
548528
preload: join(__dirname, './electron-bridge.mjs'),
@@ -654,10 +634,10 @@ function startMicrobreak () {
654634
calculateBackgroundColor(settings.get('miniBreakColor'))]
655635
})
656636

657-
for (let localDisplayId = 0; localDisplayId < numberOfDisplays(); localDisplayId++) {
637+
for (let localDisplayId = 0; localDisplayId < displayManager.getDisplayCount(); localDisplayId++) {
658638
const windowOptions = {
659-
width: Math.floor(displaysWidth(localDisplayId) * settings.get('breakWindowWidth')),
660-
height: Math.floor(displaysHeight(localDisplayId) * settings.get('breakWindowHeight')),
639+
width: Math.floor(displayManager.getDisplayWidth(localDisplayId) * settings.get('breakWindowWidth')),
640+
height: Math.floor(displayManager.getDisplayHeight(localDisplayId) * settings.get('breakWindowHeight')),
661641
autoHideMenuBar: true,
662642
icon: windowIconPath(),
663643
resizable: false,
@@ -681,13 +661,13 @@ function startMicrobreak () {
681661
}
682662

683663
if (settings.get('fullscreen') && process.platform !== 'darwin') {
684-
windowOptions.width = displaysWidth(localDisplayId)
685-
windowOptions.height = displaysHeight(localDisplayId)
686-
windowOptions.x = displaysX(localDisplayId, 0, true)
687-
windowOptions.y = displaysY(localDisplayId, 0, true)
664+
windowOptions.width = displayManager.getDisplayWidth(localDisplayId)
665+
windowOptions.height = displayManager.getDisplayHeight(localDisplayId)
666+
windowOptions.x = displayManager.getDisplayX(localDisplayId, 0, true)
667+
windowOptions.y = displayManager.getDisplayY(localDisplayId, 0, true)
688668
} else if (!(settings.get('fullscreen') && process.platform === 'win32')) {
689-
windowOptions.x = displaysX(localDisplayId, windowOptions.width, false)
690-
windowOptions.y = displaysY(localDisplayId, windowOptions.height, false)
669+
windowOptions.x = displayManager.getDisplayX(localDisplayId, windowOptions.width, false)
670+
windowOptions.y = displayManager.getDisplayY(localDisplayId, windowOptions.height, false)
691671
}
692672

693673
let microbreakWinLocal = new BrowserWindow(windowOptions)
@@ -706,7 +686,7 @@ function startMicrobreak () {
706686
microbreakWinLocal.showInactive()
707687
}
708688

709-
log.info(`Stretchly: showing window ${localDisplayId + 1} of ${numberOfDisplays()}`)
689+
log.info(`Stretchly: showing window ${localDisplayId + 1} of ${displayManager.getDisplayCount()}`)
710690
if (process.platform === 'darwin') {
711691
if (showBreaksAsRegularWindows) {
712692
microbreakWinLocal.setFullScreen(settings.get('fullscreen'))
@@ -746,7 +726,7 @@ function startMicrobreak () {
746726
microbreakWins.push(microbreakWinLocal)
747727

748728
if (!settings.get('allScreens')) {
749-
if (numberOfDisplays() > 1) {
729+
if (displayManager.getDisplayCount() > 1) {
750730
log.info('Stretchly: not showing on more Monitors as it is disabled.')
751731
}
752732
break
@@ -803,10 +783,10 @@ function startBreak () {
803783
calculateBackgroundColor(settings.get('mainColor'))]
804784
})
805785

806-
for (let localDisplayId = 0; localDisplayId < numberOfDisplays(); localDisplayId++) {
786+
for (let localDisplayId = 0; localDisplayId < displayManager.getDisplayCount(); localDisplayId++) {
807787
const windowOptions = {
808-
width: Math.floor(displaysWidth(localDisplayId) * settings.get('breakWindowWidth')),
809-
height: Math.floor(displaysHeight(localDisplayId) * settings.get('breakWindowHeight')),
788+
width: Math.floor(displayManager.getDisplayWidth(localDisplayId) * settings.get('breakWindowWidth')),
789+
height: Math.floor(displayManager.getDisplayHeight(localDisplayId) * settings.get('breakWindowHeight')),
810790
autoHideMenuBar: true,
811791
icon: windowIconPath(),
812792
resizable: false,
@@ -830,13 +810,13 @@ function startBreak () {
830810
}
831811

832812
if (settings.get('fullscreen') && process.platform !== 'darwin') {
833-
windowOptions.width = displaysWidth(localDisplayId)
834-
windowOptions.height = displaysHeight(localDisplayId)
835-
windowOptions.x = displaysX(localDisplayId, 0, true)
836-
windowOptions.y = displaysY(localDisplayId, 0, true)
813+
windowOptions.width = displayManager.getDisplayWidth(localDisplayId)
814+
windowOptions.height = displayManager.getDisplayHeight(localDisplayId)
815+
windowOptions.x = displayManager.getDisplayX(localDisplayId, 0, true)
816+
windowOptions.y = displayManager.getDisplayY(localDisplayId, 0, true)
837817
} else if (!(settings.get('fullscreen') && process.platform === 'win32')) {
838-
windowOptions.x = displaysX(localDisplayId, windowOptions.width, false)
839-
windowOptions.y = displaysY(localDisplayId, windowOptions.height, false)
818+
windowOptions.x = displayManager.getDisplayX(localDisplayId, windowOptions.width, false)
819+
windowOptions.y = displayManager.getDisplayY(localDisplayId, windowOptions.height, false)
840820
}
841821

842822
let breakWinLocal = new BrowserWindow(windowOptions)
@@ -855,7 +835,7 @@ function startBreak () {
855835
breakWinLocal.showInactive()
856836
}
857837

858-
log.info(`Stretchly: showing window ${localDisplayId + 1} of ${numberOfDisplays()}`)
838+
log.info(`Stretchly: showing window ${localDisplayId + 1} of ${displayManager.getDisplayCount()}`)
859839
if (process.platform === 'darwin') {
860840
if (showBreaksAsRegularWindows) {
861841
breakWinLocal.setFullScreen(settings.get('fullscreen'))
@@ -896,7 +876,7 @@ function startBreak () {
896876
breakWins.push(breakWinLocal)
897877

898878
if (!settings.get('allScreens')) {
899-
if (numberOfDisplays() > 1) {
879+
if (displayManager.getDisplayCount() > 1) {
900880
log.info('Stretchly: not showing on more Monitors as it is disabled.')
901881
}
902882
break
@@ -1083,8 +1063,8 @@ function createPreferencesWindow () {
10831063
width: 600,
10841064
height: 530,
10851065
maxHeight: Math.round(maxHeight),
1086-
x: displaysX(-1, 600),
1087-
y: displaysY(-1, 530),
1066+
x: displayManager.getDisplayX(-1, 600),
1067+
y: displayManager.getDisplayY(-1, 530),
10881068
backgroundColor: '#EDEDED',
10891069
webPreferences: {
10901070
preload: join(__dirname, './preferences-preload.mjs'),
@@ -1471,8 +1451,8 @@ ipcMain.on('open-contributor-auth', function (event, provider) {
14711451
width: 1000,
14721452
height: 700,
14731453
icon: windowIconPath(),
1474-
x: displaysX(),
1475-
y: displaysY(),
1454+
x: displayManager.getDisplayX(),
1455+
y: displayManager.getDisplayY(),
14761456
backgroundColor: 'whitesmoke',
14771457
webPreferences: {
14781458
preload: join(__dirname, './electron-bridge.mjs'),

0 commit comments

Comments
 (0)