implement the --new-user flag

ping #111
main
mirkobrombin 2 years ago
parent ae981727c0
commit d3c1ea6fb1

@ -29,6 +29,7 @@ from vanilla_first_setup.window import VanillaWindow
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("FirstSetup::Main")
class FirstSetupApplication(Adw.Application):
@ -38,6 +39,9 @@ class FirstSetupApplication(Adw.Application):
super().__init__(application_id='org.vanillaos.FirstSetup',
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
self.post_script = None
self.user = os.environ.get("USER")
self.new_user = False
self.create_action('quit', self.close, ['<primary>q'])
self.__register_arguments()
@ -51,12 +55,27 @@ class FirstSetupApplication(Adw.Application):
_("Run a post script"),
None
)
self.add_main_option(
"new-user",
ord("p"),
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
_("Run as a new user"),
None
)
def do_command_line(self, command_line):
"""Handle command line arguments."""
options = command_line.get_options_dict()
if options.contains("run-post-script"):
logger.info("Running post script")
self.post_script = options.lookup_value("run-post-script").get_string()
if options.contains("new-user"):
logger.info("Running as a new user")
self.user = None
self.new_user = True
self.activate()
@ -122,7 +141,7 @@ class FirstSetupApplication(Adw.Application):
win = self.props.active_window
if not win:
win = VanillaWindow(application=self, post_script=self.post_script)
win = VanillaWindow(application=self, post_script=self.post_script, user=self.user, new_user=self.new_user)
win.present()
def create_action(self, name, callback, shortcuts=None):

@ -45,8 +45,9 @@ templates = {
class Builder:
def __init__(self, window):
def __init__(self, window, new_user: bool = False):
self.__window = window
self.__new_user = new_user
self.__recipe = RecipeLoader()
self.__register_widgets = []
self.__register_finals = []
@ -89,6 +90,9 @@ class Builder:
if not _condition_met:
continue
if step.get("new-user-only") and not self.__new_user:
continue
_status = not step.get("is-advanced", False)

@ -131,11 +131,12 @@ class Processor:
return cmd
@staticmethod
def hide_first_setup():
desktop_file = os.path.expanduser(
"~/.local/share/applications/org.vanillaos.FirstSetup.desktop")
autostart_file = os.path.expanduser(
"~/.config/autostart/org.vanillaos.FirstSetup.desktop")
def hide_first_setup(user: str=None):
if user is None:
user = os.environ.get("USER")
desktop_file = "/home/%s/.local/share/applications/org.vanillaos.FirstSetup.desktop" % user
autostart_file = "/home/%s/.config/autostart/org.vanillaos.FirstSetup.desktop" % user
if os.path.exists(autostart_file):
os.remove(autostart_file)

@ -41,7 +41,7 @@ class VanillaWindow(Adw.ApplicationWindow):
btn_back = Gtk.Template.Child()
toasts = Gtk.Template.Child()
def __init__(self, post_script: str, **kwargs):
def __init__(self, post_script: str, user: str, new_user: bool=False, **kwargs):
super().__init__(**kwargs)
# prepare a variable for the initialization mode:
@ -77,7 +77,7 @@ class VanillaWindow(Adw.ApplicationWindow):
# this starts the builder and generates the widgets
# to put in the carousel
self.__builder = Builder(self)
self.__builder = Builder(self, new_user=new_user)
self.recipe = self.__builder.recipe
# system views
@ -172,7 +172,7 @@ class VanillaWindow(Adw.ApplicationWindow):
commands
)
self.__view_progress.start(res, Processor.hide_first_setup)
self.__view_progress.start(res, Processor.hide_first_setup, self.__user)
def set_installation_result(self, result, terminal):
self.__view_done.set_result(result, terminal)
@ -198,3 +198,6 @@ class VanillaWindow(Adw.ApplicationWindow):
toast = Adw.Toast.new(message)
toast.props.timeout = timeout
self.toasts.add_toast(toast)
def set_user(self, user):
self.__user = user

Loading…
Cancel
Save