Skip to content

Commit

Permalink
Remove network check
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 15, 2021
1 parent 82dc3ab commit b8bd9b6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 183 deletions.
38 changes: 1 addition & 37 deletions app/application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,7 @@ <h5 class="mx-3 flex flex-row m-0 font-bold build-content text-center">You are r
</div>
</div>

<!-- offline mode -->
<div class="w-full text-white bg-popup-red font-bold offline hidden">
<div class="container flex flex-row items-center justify-between px-6 py-4 mx-auto">
<div class="flex">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>

<p class="mx-3 relative top-1">Authme runs in offline mode. The app will work fine, but you can't look for new updates!</p>
</div>
<a onclick="this.parentElement.style.display='none'" class="p-1 transition-colors duration-200 transform rounded-md hover:text-gray-800 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
</div>

<!-- online mode -->
<div class="w-full text-white bg-popup-green font-bold online hidden">
<div class="container flex flex-row items-center justify-between px-6 py-4 mx-auto">
<div class="flex">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>

<p class="mx-3 relative top-1">Authme runs in online mode. The app reconnected to the internet, you can look for new updates!</p>
</div>
<a onclick="this.parentElement.style.display='none'" class="p-1 transition-colors duration-200 transform rounded-md hover:text-gray-800 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
</div>

<!-- update -->
<!-- manual update -->
<div class="w-full text-white bg-popup-blue font-bold update hidden">
<div class="container flex flex-row items-center justify-between px-6 py-4 mx-auto">
<div class="flex">
Expand Down
43 changes: 0 additions & 43 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,49 +631,6 @@ const showInfo = () => {
document.querySelector(".info").style.display = "block"
}

// ? offline mode
let offline_mode = false
let offline_closed = false
let online_closed = false

const check_for_internet = () => {
dns.lookup("google.com", (err) => {
if (err && err.code == "ENOTFOUND" && offline_closed === false) {
document.querySelector(".online").style.display = "none"
document.querySelector(".offline").style.display = "block"

offline_mode = true
offline_closed = true

ipc.send("offline")

logger.warn("Can't connect to the internet")
} else if (err === null && offline_mode === true && online_closed === false) {
document.querySelector(".online").style.display = "block"
document.querySelector(".offline").style.display = "none"

offline_mode = false
online_closed = true

ipc.send("offline")

logger.warn("Connected to the internet")
} else if ((online_closed === true || offline_closed === true) && err === null) {
offline_mode = false
offline_closed = false
online_closed = false

logger.warn("Connection restored")
}
})
}

check_for_internet()

setInterval(() => {
check_for_internet()
}, 5000)

/**
* Save imported codes to disk
*/
Expand Down
44 changes: 4 additions & 40 deletions app/settings/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src https://api.levminer.com" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' />
<meta charset="UTF-8" />
<!-- js -->
<script defer src="./src/js/index.js"></script>
Expand Down Expand Up @@ -81,43 +81,7 @@ <h5 class="mx-3 flex flex-row m-0 font-bold build-content text-center">You are r
</div>
</div>

<!-- offline mode -->
<div class="w-full text-white bg-popup-red font-bold offline hidden">
<div class="container flex flex-row items-center justify-between px-6 py-4 mx-auto">
<div class="flex">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>

<p class="mx-3 relative top-1">Authme runs in offline mode. The app will work fine, but you can't look for new updates!</p>
</div>
<a onclick="this.parentElement.style.display='none'" class="p-1 transition-colors duration-200 transform rounded-md hover:text-gray-800 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
</div>

<!-- online mode -->
<div class="w-full text-white bg-popup-green font-bold online hidden">
<div class="container flex flex-row items-center justify-between px-6 py-4 mx-auto">
<div class="flex">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>

<p class="mx-3 relative top-1">Authme runs in online mode. The app reconnected to the internet, you can look for new updates!</p>
</div>
<a onclick="this.parentElement.style.display='none'" class="p-1 transition-colors duration-200 transform rounded-md hover:text-gray-800 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
</div>

<!-- update -->
<!-- manual update -->
<div class="w-full text-white bg-popup-blue font-bold update hidden">
<div class="container flex flex-row items-center justify-between px-6 py-4 mx-auto">
<div class="flex">
Expand Down Expand Up @@ -837,7 +801,7 @@ <h4>
<br />
<div class="flex flex-col md:w-4/5 lg:w-2/3 mx-auto rounded-2xl bg-gray-800 mb-20">
<div class="flex justify-center items-center">
<h3>Show/Hide app</h3>
<h3>Show/Hide App</h3>
</div>
<div class="flex justify-center items-center">
<input class="input" disabled type="text" id="hk100_input" />
Expand Down Expand Up @@ -891,7 +855,7 @@ <h3>Settings</h3>
</div>
<div class="flex flex-col md:w-4/5 lg:w-2/3 mx-auto rounded-2xl bg-gray-800 mb-20">
<div class="flex justify-center items-center">
<h3>Exit app</h3>
<h3>Exit App</h3>
</div>
<div class="flex justify-center items-center">
<input class="input" disabled type="text" id="hk102_input" />
Expand Down
39 changes: 0 additions & 39 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,50 +770,11 @@ const edit = () => {
ipc.send("toggleEdit")
}

// ? offline mode
let offline_mode = false
let offline_closed = false
let online_closed = false

// ? send reload
const reload = () => {
ipc.send("reloadApplicationWindow")
}

const check_for_internet = () => {
dns.lookup("google.com", (err) => {
if (err && err.code == "ENOTFOUND" && offline_closed === false) {
document.querySelector(".online").style.display = "none"
document.querySelector(".offline").style.display = "block"

offline_mode = true
offline_closed = true

logger.warn("Can't connect to the internet")
} else if (err === null && offline_mode === true && online_closed === false) {
document.querySelector(".online").style.display = "block"
document.querySelector(".offline").style.display = "none"

offline_mode = false
online_closed = true

logger.log("Connected to the internet")
} else if ((online_closed === true || offline_closed === true) && err === null) {
offline_mode = false
offline_closed = false
online_closed = false

logger.log("Connection restored")
}
})
}

check_for_internet()

setInterval(() => {
check_for_internet()
}, 10000)

// ? dismiss dialog on click outside
window.addEventListener("click", (event) => {
const dropdown_content = document.querySelector("#dropdownContent0")
Expand Down
32 changes: 8 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,14 @@ const createWindow = () => {
autoUpdater.on("error", (error) => {
logger.error("Error during auto update", error.stack)

dialog.showErrorBox("Authme", "Error during auto update. \n\nTry to restart Authme!")
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
defaultId: 0,
cancelId: 1,
type: "error",
message: `Error during auto update. \n\nTry to restart Authme and check your network connection! \n\n${error.stack}`,
})
})

autoUpdater.on("download-progress", (progress) => {
Expand Down Expand Up @@ -1176,29 +1183,6 @@ ipc.on("abort", () => {
})
})

/**
* Offline mode
*/
ipc.on("offline", () => {
if (offline === false) {
setTimeout(() => {
window_application.setTitle("Authme (Offline)")
window_settings.setTitle("Authme (Offline)")
}, 1000)
offline = true

logger.warn("Running in offline mode")
} else {
setTimeout(() => {
window_application.setTitle("Authme")
window_settings.setTitle("Authme ")
}, 1000)
offline = false

logger.log("Running in online mode")
}
})

/**
* Display release notes
*/
Expand Down

0 comments on commit b8bd9b6

Please sign in to comment.