Skip to content

Commit

Permalink
fix:[#339] network check without network interface
Browse files Browse the repository at this point in the history
- Split out network check from conn_check into static function
- Check for network by request success instead of network interfaces
  • Loading branch information
jardon committed Oct 1, 2024
1 parent 892c3b0 commit 550bdef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
17 changes: 2 additions & 15 deletions vanilla_first_setup/defaults/conn_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from requests import Session

from vanilla_first_setup.utils.run_async import RunAsync
from vanilla_first_setup.utils.network import Network

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("FirstSetup::Conn_Check")
Expand Down Expand Up @@ -72,21 +73,7 @@ def async_fn():
if "VANILLA_SKIP_CONN_CHECK" in os.environ:
return True

try:
s = Session()
headers = OrderedDict(
{
"Accept-Encoding": "gzip, deflate, br",
"Host": "vanillaos.org",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0",
}
)
s.headers = headers
s.get("https://vanillaos.org/", headers=headers, verify=True)
return True
except Exception as e:
logger.error(f"Connection check failed: {str(e)}")
return False
return Network.check_connection()

def callback(res, *args):
if self.__ignore_callback:
Expand Down
3 changes: 2 additions & 1 deletion vanilla_first_setup/defaults/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from gi.repository import NM, NMA4, Adw, GLib, Gtk

from vanilla_first_setup.utils.run_async import RunAsync
from vanilla_first_setup.utils.network import Network

logger = logging.getLogger("FirstSetup::Network")

Expand Down Expand Up @@ -286,7 +287,7 @@ def __init__(self, window, distro_info, key, step, **kwargs):

def __try_skip_page(self, data):
# Skip page if already connected to the internet
if self.has_eth_connection or self.has_wifi_connection:
if Network.check_connection():
self.__window.next()

@property
Expand Down
1 change: 1 addition & 0 deletions vanilla_first_setup/utils/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sources = [
'recipe.py',
'builder.py',
'parser.py',
'network.py',
]

install_data(sources, install_dir: utilsdir)
41 changes: 41 additions & 0 deletions vanilla_first_setup/utils/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# network.py
#
# Copyright 2023 mirkobrombin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundationat version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from collections import OrderedDict
from requests import Session

logger = logging.getLogger("FirstSetup::Connector")


class Network:
@staticmethod
def check_connection():
try:
s = Session()
headers = OrderedDict(
{
"Accept-Encoding": "gzip, deflate, br",
"Host": "vanillaos.org",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0",
}
)
s.headers = headers
s.get("https://vanillaos.org/", headers=headers, verify=True)
return True
except Exception as e:
logger.error(f"Connection check failed: {str(e)}")
return False

0 comments on commit 550bdef

Please sign in to comment.