# Copyright (c) 2023, JINGROW and Contributors
# MIT License. See license.txt

import jingrow
from jingrow import _
from jingrow.apps import get_apps


def get_context():
	all_apps = get_apps()

	system_default_app = jingrow.get_system_settings("default_app")
	user_default_app = jingrow.db.get_value("User", jingrow.session.user, "default_app")
	default_app = user_default_app if user_default_app else system_default_app

	if len(all_apps) == 0:
		jingrow.local.flags.redirect_location = "/app"
		raise jingrow.Redirect

	for app in all_apps:
		app["is_default"] = True if app.get("name") == default_app else False

	return {"apps": all_apps}
