Skip to content

Commit dc64a86

Browse files
committed
Refactor
1 parent ce8b1fb commit dc64a86

1 file changed

Lines changed: 40 additions & 34 deletions

File tree

app/main.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ function createWelcomeWindow (isAppStart = true) {
568568
y: displaysY(-1, 750),
569569
width: 1000,
570570
height: 750,
571+
show: false,
571572
autoHideMenuBar: true,
572573
icon: windowIconPath(),
573574
backgroundColor: 'EDEDED',
@@ -577,14 +578,13 @@ function createWelcomeWindow (isAppStart = true) {
577578
}
578579
})
579580
welcomeWin.webContents.loadURL(modalPath)
580-
if (welcomeWin) {
581-
welcomeWin.webContents.on('closed', () => {
582-
welcomeWin = null
583-
})
584-
}
585-
setTimeout(() => {
581+
welcomeWin.once('ready-to-show', () => {
586582
welcomeWin.center()
587-
}, 0)
583+
welcomeWin.show()
584+
})
585+
welcomeWin.once('closed', () => {
586+
welcomeWin = null
587+
})
588588
}
589589
}
590590

@@ -598,6 +598,7 @@ function createContributorSettingsWindow () {
598598
x: displaysX(-1, 735),
599599
y: displaysY(),
600600
width: 735,
601+
show: false,
601602
autoHideMenuBar: true,
602603
icon: windowIconPath(),
603604
backgroundColor: 'EDEDED',
@@ -607,14 +608,13 @@ function createContributorSettingsWindow () {
607608
}
608609
})
609610
contributorPreferencesWin.webContents.loadURL(modalPath)
610-
if (contributorPreferencesWin) {
611-
contributorPreferencesWin.webContents.on('closed', () => {
612-
contributorPreferencesWin = null
613-
})
614-
}
615-
setTimeout(() => {
611+
contributorPreferencesWin.once('ready-to-show', () => {
616612
contributorPreferencesWin.center()
617-
}, 0)
613+
contributorPreferencesWin.show()
614+
})
615+
contributorPreferencesWin.once('closed', () => {
616+
contributorPreferencesWin = null
617+
})
618618
}
619619

620620
function createSyncPreferencesWindow () {
@@ -625,6 +625,7 @@ function createSyncPreferencesWindow () {
625625

626626
const syncPreferencesUrl = 'https://my.stretchly.net/app/v1/sync'
627627
syncPreferencesWin = new BrowserWindow({
628+
show: false,
628629
autoHideMenuBar: true,
629630
width: 1000,
630631
height: 700,
@@ -639,15 +640,15 @@ function createSyncPreferencesWindow () {
639640
})
640641
syncPreferencesWin.webContents.openDevTools()
641642
syncPreferencesWin.webContents.loadURL(syncPreferencesUrl)
642-
if (syncPreferencesWin) {
643-
syncPreferencesWin.webContents.on('closed', () => {
644-
syncPreferencesWin = null
645-
})
646-
}
647643

648-
setTimeout(() => {
644+
syncPreferencesWin.once('closed', () => {
645+
syncPreferencesWin = null
646+
})
647+
648+
syncPreferencesWin.once('ready-to-show', () => {
649649
syncPreferencesWin.center()
650-
}, 0)
650+
syncPreferencesWin.show()
651+
})
651652
}
652653

653654
function planVersionCheck (seconds = 1) {
@@ -829,7 +830,7 @@ function startMicrobreak () {
829830
e.preventDefault()
830831
}
831832
})
832-
microbreakWinLocal.on('closed', () => {
833+
microbreakWinLocal.once('closed', () => {
833834
microbreakWinLocal = null
834835
})
835836
}
@@ -979,7 +980,7 @@ function startBreak () {
979980
e.preventDefault()
980981
}
981982
})
982-
breakWinLocal.on('closed', () => {
983+
breakWinLocal.once('closed', () => {
983984
breakWinLocal = null
984985
})
985986
}
@@ -1167,6 +1168,8 @@ function createPreferencesWindow () {
11671168
.workAreaSize.height * 0.9
11681169
preferencesWin = new BrowserWindow({
11691170
autoHideMenuBar: true,
1171+
show: false,
1172+
backgroundThrottling: false,
11701173
icon: windowIconPath(),
11711174
width: 600,
11721175
height: 530,
@@ -1180,12 +1183,13 @@ function createPreferencesWindow () {
11801183
}
11811184
})
11821185
preferencesWin.webContents.loadURL(modalPath)
1183-
preferencesWin.webContents.on('closed', () => {
1186+
preferencesWin.once('ready-to-show', () => {
1187+
preferencesWin.center()
1188+
preferencesWin.show()
1189+
})
1190+
preferencesWin.once('closed', () => {
11841191
preferencesWin = null
11851192
})
1186-
setTimeout(() => {
1187-
preferencesWin.center()
1188-
}, 0)
11891193
}
11901194

11911195
function updateTray () {
@@ -1554,6 +1558,7 @@ ipcMain.on('open-contributor-auth', function (event, provider) {
15541558
const myStretchlyUrl = `https://my.stretchly.net/app/v1?provider=${provider}`
15551559
myStretchlyWin = new BrowserWindow({
15561560
autoHideMenuBar: false,
1561+
show: false,
15571562
width: 1000,
15581563
height: 700,
15591564
icon: windowIconPath(),
@@ -1567,14 +1572,15 @@ ipcMain.on('open-contributor-auth', function (event, provider) {
15671572
})
15681573
myStretchlyWin.webContents.openDevTools()
15691574
myStretchlyWin.webContents.loadURL(myStretchlyUrl)
1570-
if (myStretchlyWin) {
1571-
myStretchlyWin.webContents.on('closed', () => {
1572-
myStretchlyWin = null
1573-
})
1574-
}
1575-
setTimeout(() => {
1575+
1576+
myStretchlyWin.once('closed', () => {
1577+
myStretchlyWin = null
1578+
})
1579+
1580+
myStretchlyWin.once('ready-to-show', () => {
15761581
myStretchlyWin.center()
1577-
}, 0)
1582+
myStretchlyWin.show()
1583+
})
15781584
})
15791585

15801586
ipcMain.on('open-sync-preferences', () => {

0 commit comments

Comments
 (0)