Skip to content

Commit

Permalink
Fix modal dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Apr 9, 2022
1 parent eedd4f7 commit 3edcd31
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 40 deletions.
31 changes: 14 additions & 17 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ if (settings.security.require_password === null && settings.security.password ==
}, 500)
}

// Get current window
const currentWindow = BrowserWindow.getFocusedWindow()

/**
* Build number
*/
Expand Down Expand Up @@ -117,7 +114,7 @@ fs.readFile(path.join(cache_path, "rollback.authme"), "utf-8", (err, data) => {
*/
const loadRollback = () => {
dialog
.showMessageBox(currentWindow, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
Expand All @@ -138,7 +135,7 @@ const loadRollback = () => {
} else {
logger.log("rollback successful, codes.authme file created")

dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "info",
Expand Down Expand Up @@ -280,7 +277,7 @@ const editCode = (number) => {

edit_mode = false

dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "info",
Expand All @@ -304,7 +301,7 @@ const deleteCode = (number) => {
counter = 0

dialog
.showMessageBox(currentWindow, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
type: "warning",
Expand Down Expand Up @@ -340,7 +337,7 @@ let save_text = ""

const createSave = () => {
dialog
.showMessageBox(currentWindow, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
Expand Down Expand Up @@ -413,7 +410,7 @@ const saveModifications = async () => {
*/
const addCodes = () => {
dialog
.showOpenDialog(currentWindow, {
.showOpenDialog(BrowserWindow.getFocusedWindow(), {
title: lang.application_dialog.choose_import_file,
properties: ["openFile", "multiSelections"],
filters: [{ name: lang.application_dialog.authme_file, extensions: ["authme"] }],
Expand Down Expand Up @@ -452,7 +449,7 @@ const addCodes = () => {

generateEditElements()
} else {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
defaultId: 0,
Expand All @@ -466,7 +463,7 @@ const addCodes = () => {
})
}

dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
defaultId: 0,
Expand Down Expand Up @@ -511,7 +508,7 @@ const createRollback = () => {
const loadError = () => {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", (err, data) => {
if (err) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand All @@ -527,7 +524,7 @@ const loadError = () => {
*/
const loadCodes = async () => {
if (fs.existsSync(path.join(folder_path, "rollbacks", "rollback.authme"))) {
const result = await dialog.showMessageBox(currentWindow, {
const result = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
Expand All @@ -540,7 +537,7 @@ const loadCodes = async () => {
if (result.response === 0) {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", async (err, data) => {
if (err) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down Expand Up @@ -584,7 +581,7 @@ const loadCodes = async () => {
} else {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", async (err, data) => {
if (err) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down Expand Up @@ -655,7 +652,7 @@ const reloadExportWindow = () => {
*/
const revertChanges = () => {
dialog
.showMessageBox(currentWindow, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
Expand All @@ -676,7 +673,7 @@ const revertChanges = () => {
*/
const deleteAllCodes = () => {
dialog
.showMessageBox(currentWindow, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
Expand Down
8 changes: 4 additions & 4 deletions app/import/src/js/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
chooseImages: async () => {
let string = ""

const open_dialog = await dialog.showOpenDialog(currentWindow, {
const open_dialog = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
title: lang.import_dialog.choose_images,
properties: ["openFile", "multiSelections"],
filters: [{ name: lang.import_dialog.image_file, extensions: ["jpg", "jpeg", "png", "bmp"] }],
Expand All @@ -20,7 +20,7 @@ module.exports = {
const res = await reader.decodeFromImage(images[i])

if (res === false) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand All @@ -39,7 +39,7 @@ module.exports = {
if (images.length === i + 1) {
const save_exists = fs.existsSync(path.join(folder_path, "codes", "codes.authme"))

const result = await dialog.showMessageBox(currentWindow, {
const result = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.no],
type: "info",
Expand All @@ -66,7 +66,7 @@ module.exports = {
}
}
} else {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down
5 changes: 1 addition & 4 deletions app/import/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ if (app.isPackaged === false) {
dev = true
}

// Get current window
const currentWindow = BrowserWindow.getFocusedWindow()

/**
* Get Authme folder path
*/
Expand Down Expand Up @@ -95,7 +92,7 @@ buildNumber()
* @param {string} string
*/
const saveFile = async (string) => {
const result = await dialog.showSaveDialog(currentWindow, {
const result = await dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), {
title: lang.import_dialog.save_file,
filters: [{ name: lang.application_dialog.authme_file, extensions: ["authme"] }],
defaultPath: "~/import.authme",
Expand Down
8 changes: 4 additions & 4 deletions app/import/src/js/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {

qrHandleStream(stream)
} catch (error) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down Expand Up @@ -59,7 +59,7 @@ module.exports = {

const save_exists = fs.existsSync(path.join(folder_path, "codes", "codes.authme"))

const result = await dialog.showMessageBox(currentWindow, {
const result = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.no],
type: "info",
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = {
reader.stop()
track.stop()
} else {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand All @@ -103,7 +103,7 @@ module.exports = {

setTimeout(() => {
if (code_found === false) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down
8 changes: 4 additions & 4 deletions app/import/src/js/webcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
const hasWebcam = await webcamAvailable()

if (hasWebcam === false) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down Expand Up @@ -47,7 +47,7 @@ module.exports = {

const save_exists = fs.existsSync(path.join(folder_path, "codes", "codes.authme"))

const result = await dialog.showMessageBox(currentWindow, {
const result = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.no],
type: "info",
Expand All @@ -73,7 +73,7 @@ module.exports = {
}
}
} else {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand All @@ -94,7 +94,7 @@ module.exports = {

reader.stop()
} catch (error) {
dialog.showMessageBox(currentWindow, {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
Expand Down
6 changes: 2 additions & 4 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,8 @@ const toggleWindowCaptureSwitch = () => {
* Clear all data
*/
const clearData = () => {
const current_window = BrowserWindow.getFocusedWindow()

dialog
.showMessageBox(current_window, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.no],
defaultId: 1,
Expand All @@ -329,7 +327,7 @@ const clearData = () => {
.then((result) => {
if (result.response === 0) {
dialog
.showMessageBox(current_window, {
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.no],
defaultId: 1,
Expand Down
6 changes: 3 additions & 3 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ document.addEventListener("drop", (event) => event.preventDefault())
/**
* Title bar
*/
const currentWindow = getCurrentWindow()
const current_window = getCurrentWindow()
let titlebar
let loaded = false

if (process.platform === "win32") {
currentWindow.webContents.once("dom-ready", () => {
current_window.webContents.once("dom-ready", () => {
titlebar = new Titlebar({
menu: Menu.getApplicationMenu(),
browserWindow: currentWindow,
browserWindow: current_window,
backgroundColor: "#000000",
icon: "../../img/icon.png",
unfocusEffect: false,
Expand Down

0 comments on commit 3edcd31

Please sign in to comment.