Skip to content

Commit

Permalink
Splash screen opens on selected display #164
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 14, 2021
1 parent 2bc667a commit 790ff16
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let update_seen = false
let manual_update = false
let tray = null
let menu = null
let display = null

// ? development
let dev = false
Expand Down Expand Up @@ -347,25 +348,6 @@ const createWindow = () => {
wco = true
}

/**
* Open Authme on selected display
*/
const displays = screen.getAllDisplays()
const primary_display = screen.getPrimaryDisplay()

// Remove primary display
for (let i = 0; i < displays.length; i++) {
if (displays.id === primary_display.id) {
displays[i].pop()
}
}

// Add primary display
displays.splice(0, 0, primary_display)

// Get selected display
const display = displays[settings.settings.default_display - 1]

/**
* Create windows
*/
Expand Down Expand Up @@ -1473,7 +1455,7 @@ app.whenReady()
}

process.on("uncaughtException", (error) => {
logger.error("Unknown error occurred", error.stack)
logger.error("Error occurred while starting", error.stack)

dialog
.showMessageBox({
Expand All @@ -1483,7 +1465,7 @@ app.whenReady()
cancelId: 1,
noLink: true,
type: "error",
message: `Unknown error occurred! \n\n${error.stack}`,
message: `Error occurred while starting Authme! \n\n${error.stack}`,
})
.then((result) => {
if (result.response === 0) {
Expand All @@ -1494,7 +1476,31 @@ app.whenReady()
})
})

/**
* Open Authme on selected display
*/
const displays = screen.getAllDisplays()
const primary_display = screen.getPrimaryDisplay()

// Remove primary display
for (let i = 0; i < displays.length; i++) {
if (displays[i].id === primary_display.id) {
displays.splice(i, 1)
}
}

// Add primary display
displays.splice(0, 0, primary_display)

// Get selected display
display = displays[settings.settings.default_display - 1]

/**
* Splash window
*/
window_splash = new BrowserWindow({
x: display.bounds.x,
y: display.bounds.y,
width: 500,
height: 550,
transparent: true,
Expand All @@ -1507,9 +1513,14 @@ app.whenReady()
},
})

window_splash.center()

window_splash.loadFile("./app/splash/index.html")
window_splash.setProgressBar(10)

/**
* Close splash window and create the app window
*/
window_splash.once("ready-to-show", () => {
window_splash.show()

Expand All @@ -1534,7 +1545,9 @@ app.whenReady()
}
})

// ? create tray
/**
* Create tray icon
*/
const icon_path = path.join(__dirname, "img/tray.png")
tray = new Tray(icon_path)

Expand All @@ -1548,7 +1561,7 @@ app.whenReady()
createMenu()
})
.catch((error) => {
logger.error("Unknown error occurred", error.stack)
logger.error("Error occurred while starting", error.stack)

dialog
.showMessageBox({
Expand All @@ -1558,7 +1571,7 @@ app.whenReady()
cancelId: 1,
noLink: true,
type: "error",
message: `Unknown error occurred! \n\n${error.stack}`,
message: `Error occurred while starting Authme! \n\n${error.stack}`,
})
.then((result) => {
if (result.response === 0) {
Expand Down

0 comments on commit 790ff16

Please sign in to comment.