Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [close #190] Add network settings step #210

Merged
merged 10 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- libadwaita-1-dev
- gettext
- desktop-file-utils
- libnm-dev
- libnma-dev
- libnma-gtk4-dev

### Build
```bash
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions data/icons/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ install_data(
install_dir: join_paths(get_option('datadir'), 'icons', scalable_dir)
)

install_data(
join_paths(actions_dir, 'background-app-ghost-symbolic.svg'),
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'actions')
)
install_data(
join_paths(actions_dir, 'vanilla-container-terminal-symbolic.svg'),
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'actions')
Expand Down
24 changes: 24 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
vanilla-first-setup (2.1.0) unstable; urgency=critical

* Add network step

-- Mateus Melchiades <[email protected]> Mon, 26 Jul 2023 10:52:00 -0300

vanilla-first-setup (2.0.7) unstable; urgency=critical

* Correctly use log_file variable from recipe

-- Mateus Melchiades <[email protected]> Mon, 30 Jul 2023 19:18:00 -0300

vanilla-first-setup (2.0.6) unstable; urgency=critical

* Post script fixes

-- Mateus Melchiades <[email protected]> Mon, 27 Jul 2023 10:35:00 -0300

vanilla-first-setup (2.0.5) unstable; urgency=critical

* Default user cleanup fixes

-- Mateus Melchiades <[email protected]> Mon, 27 Jul 2023 09:04:00 -0300

vanilla-first-setup (2.0.3) unstable; urgency=critical

* Change log font
Expand Down
14 changes: 10 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: vanilla-first-setup
Section: utils
Priority: optional
Maintainer: Mirko Brombin <[email protected]>
Build-Depends:
Build-Depends:
build-essential,
debhelper,
python3,
Expand All @@ -11,7 +11,10 @@ Build-Depends:
gettext,
desktop-file-utils,
make,
libjpeg-dev
libjpeg-dev,
libnm-dev,
libnma-dev,
libnma-gtk4-dev
Homepage: https://github.com/mirkobrombin/vanilla-first-setup/
Vcs-Browser: hhttps://github.com/mirkobrombin/vanilla-first-setup
Vcs-Git: https://github.com/mirkobrombin/vanilla-first-setup.git
Expand All @@ -24,5 +27,8 @@ Depends: python3,
libadwaita-1-0,
gir1.2-gtk-4.0,
gir1.2-adw-1,
gir1.2-vte-3.91
Description: This utility is meant to be used in Ubuntu Vanilla GNOME as a first-setup wizard.
gir1.2-vte-3.91,
libnm0,
libnma0,
libnma-gtk4-0
Description: This utility is meant to be used in Vanilla GNOME as a first-setup wizard.
4 changes: 4 additions & 0 deletions recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
}
},
"steps": {
"network": {
"template": "network",
"protected": true
},
"conn-check": {
"template": "conn-check",
"protected": true
Expand Down
37 changes: 23 additions & 14 deletions vanilla_first_setup/defaults/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from vanilla_first_setup.dialog import VanillaDialog


@Gtk.Template(resource_path='/org/vanillaos/FirstSetup/gtk/layout-applications.ui')
@Gtk.Template(resource_path="/org/vanillaos/FirstSetup/gtk/layout-applications.ui")
class VanillaLayoutApplications(Adw.Bin):
__gtype_name__ = 'VanillaLayoutApplications'
__gtype_name__ = "VanillaLayoutApplications"

status_page = Gtk.Template.Child()
bundles_list = Gtk.Template.Child()
Expand Down Expand Up @@ -57,9 +57,9 @@ def present_customize(widget, dialog, apps_list, item):
apps_list.remove(app["apps_action_row"])
except KeyError:
pass
if self.__window.builder.get_temp_finals("packages")["vars"]["flatpak"] == True:
if self.__window.builder.get_temp_finals("packages")["vars"]["flatpak"]:
package_manager = "flatpak"
elif self.__window.builder.get_temp_finals("packages")["vars"]["snap"] == True:
elif self.__window.builder.get_temp_finals("packages")["vars"]["snap"]:
try:
package_manager = "snap"
except KeyError:
Expand All @@ -71,7 +71,11 @@ def present_customize(widget, dialog, apps_list, item):
_apps_action_row = Adw.ActionRow(
title=app["name"],
)
_app_icon = Gtk.Image.new_from_resource("/org/vanillaos/FirstSetup/assets/bundle-app-icons/" + app["icon"] + ".png")
_app_icon = Gtk.Image.new_from_resource(
"/org/vanillaos/FirstSetup/assets/bundle-app-icons/"
+ app["icon"]
+ ".png"
)
_app_icon.set_icon_size(Gtk.IconSize.LARGE)
_app_icon.add_css_class("lowres-icon")
_apps_action_row.add_prefix(_app_icon)
Expand Down Expand Up @@ -100,10 +104,10 @@ def apply_preferences(widget, dialog, apps_list, item):

for item in self.__step["bundles"]:
_selection_dialog = VanillaDialog(
self.__window,
"Select Applications",
"Description",
)
self.__window,
"Select Applications",
"Description",
)

_cancel_button = Gtk.Button()
_apply_button = Gtk.Button()
Expand All @@ -118,7 +122,9 @@ def apply_preferences(widget, dialog, apps_list, item):
_header_bar.set_show_start_title_buttons(False)

_apps_list = Adw.PreferencesGroup()
_apps_list.set_description("The following list includes only applications available in your preferred package manager.")
_apps_list.set_description(
"The following list includes only applications available in your preferred package manager."
)
_apps_page = Adw.PreferencesPage()
_apps_page.add(_apps_list)

Expand All @@ -131,8 +137,7 @@ def apply_preferences(widget, dialog, apps_list, item):
selection_dialogs.append(_selection_dialog)

_action_row = Adw.ActionRow(
title=item["title"],
subtitle=item.get("subtitle", "")
title=item["title"], subtitle=item.get("subtitle", "")
)
_switcher = Gtk.Switch()
_switcher.set_active(item.get("default", False))
Expand All @@ -145,9 +150,13 @@ def apply_preferences(widget, dialog, apps_list, item):
_customize.add_css_class("flat")
_action_row.add_suffix(_customize)

_customize.connect("clicked", present_customize, selection_dialogs[-1], _apps_list, item)
_customize.connect(
"clicked", present_customize, selection_dialogs[-1], _apps_list, item
)
_cancel_button.connect("clicked", close_customize, selection_dialogs[-1])
_apply_button.connect("clicked", apply_preferences, selection_dialogs[-1], _apps_list, item)
_apply_button.connect(
"clicked", apply_preferences, selection_dialogs[-1], _apps_list, item
)

self.bundles_list.add(_action_row)

Expand Down
63 changes: 46 additions & 17 deletions vanilla_first_setup/defaults/conn_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@

from requests import Session
from collections import OrderedDict
import requests

import logging
import os

from gi.repository import Gtk, GLib, Adw
from gi.repository import Gtk, Adw

from vanilla_first_setup.utils.run_async import RunAsync
from gettext import gettext as _


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("FirstSetup::Conn_Check")

@Gtk.Template(resource_path='/org/vanillaos/FirstSetup/gtk/default-conn-check.ui')

@Gtk.Template(resource_path="/org/vanillaos/FirstSetup/gtk/default-conn-check.ui")
class VanillaDefaultConnCheck(Adw.Bin):
__gtype_name__ = 'VanillaDefaultConnCheck'
__gtype_name__ = "VanillaDefaultConnCheck"

btn_recheck = Gtk.Template.Child()
status_page = Gtk.Template.Child()
Expand All @@ -37,12 +43,16 @@ def __init__(self, window, distro_info, key, step, **kwargs):
self.__distro_info = distro_info
self.__key = key
self.__step = step
self.__step_num = step["num"]

# connection check start
self.__start_conn_check()
self.__ignore_callback = False

# signals
self.btn_recheck.connect("clicked", self.__on_btn_recheck_clicked)
self.__window.carousel.connect("page-changed", self.__conn_check)
self.__window.btn_back.connect(
"clicked", self.__on_btn_back_clicked, self.__window.carousel.get_position()
)

@property
def step_id(self):
Expand All @@ -51,32 +61,49 @@ def step_id(self):
def get_finals(self):
return {}

def __start_conn_check(self):
def __on_btn_back_clicked(self, data, idx):
if idx + 1 != self.__step_num:
return
self.__ignore_callback = True

def __conn_check(self, carousel=None, idx=None):
if idx is not None and idx != self.__step_num:
return

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'
})
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(f"https://vanillaos.org/", headers=headers, verify=True)
s.get("https://vanillaos.org/", headers=headers, verify=True)
return True
except:
except Exception as e:
logger.error(f"Connection check failed: {str(e)}")
return False

def callback(res, *args):
if self.__ignore_callback:
self.__ignore_callback = False
return

if res:
self.__window.next()
return

self.status_page.set_icon_name("network-wired-disconnected-symbolic")
self.status_page.set_title(_("No Internet Connection!"))
self.status_page.set_description(_("First Setup requires an active internet connection"))
self.status_page.set_description(
_("First Setup requires an active internet connection")
)
self.btn_recheck.set_visible(True)

RunAsync(async_fn, callback)
Expand All @@ -85,5 +112,7 @@ def __on_btn_recheck_clicked(self, widget, *args):
widget.set_visible(False)
self.status_page.set_icon_name("content-loading-symbolic")
self.status_page.set_title(_("Checking Connection…"))
self.status_page.set_description(_("Please wait until the connection check is done."))
self.__start_conn_check()
self.status_page.set_description(
_("Please wait until the connection check is done.")
)
self.__conn_check()
32 changes: 14 additions & 18 deletions vanilla_first_setup/defaults/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
# 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 sys
import time
import re, subprocess, shutil
from gi.repository import Gtk, Gio, GLib, Adw
import re
from gi.repository import Gtk, Adw


@Gtk.Template(resource_path='/org/vanillaos/FirstSetup/gtk/default-hostname.ui')
@Gtk.Template(resource_path="/org/vanillaos/FirstSetup/gtk/default-hostname.ui")
class VanillaDefaultHostname(Adw.Bin):
__gtype_name__ = 'VanillaDefaultHostname'
__gtype_name__ = "VanillaDefaultHostname"

btn_next = Gtk.Template.Child()
hostname_entry = Gtk.Template.Child()
Expand All @@ -40,7 +38,7 @@ def __init__(self, window, distro_info, key, step, **kwargs):

# signals
self.btn_next.connect("clicked", self.__on_btn_next_clicked)
self.hostname_entry.connect('changed', self.__on_hostname_entry_changed)
self.hostname_entry.connect("changed", self.__on_hostname_entry_changed)

@property
def step_id(self):
Expand All @@ -51,39 +49,37 @@ def __on_btn_next_clicked(self, widget):

def get_finals(self):
return {
"vars": {
"setHostname": True
},
"vars": {"setHostname": True},
"funcs": [
{
"if": "setHostname",
"type": "command",
"commands": [
"hostnamectl set-hostname " + self.hostname
]
"commands": ["hostnamectl set-hostname " + self.hostname],
}
]
],
}

def __on_hostname_entry_changed(self, *args):
_hostname = self.hostname_entry.get_text()

if self.__validate_hostname(_hostname):
self.hostname = _hostname
self.hostname_entry.remove_css_class('error')
self.hostname_entry.remove_css_class("error")
self.__verify_continue()
return

self.__window.toast("Hostname cannot contain special characters. Please choose another hostname.")
self.hostname_entry.add_css_class('error')
self.__window.toast(
"Hostname cannot contain special characters. Please choose another hostname."
)
self.hostname_entry.add_css_class("error")
self.hostname = ""
self.__verify_continue()

def __validate_hostname(self, hostname):
if len(hostname) > 50:
return False

allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in hostname.split("."))

def __verify_continue(self):
Expand Down
3 changes: 2 additions & 1 deletion vanilla_first_setup/defaults/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ sources = [
'user.py',
'hostname.py',
'applications.py',
'conn_check.py'
'conn_check.py',
'network.py',
]

install_data(sources, install_dir: defaultsdir)
Loading