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

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

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

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

Loading…
Cancel
Save