Skip to content

Commit

Permalink
Generate URI schemes from build configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmccall committed Nov 23, 2023
1 parent 5687969 commit cbf311b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ DBusActivatable=true
# TRANSLATORS: This is an icon file name.
# Do not translate or transliterate this text!
Icon=@FRONTEND_APPLICATION_ID@
MimeType=x-scheme-handler/kolibri;x-scheme-handler/x-kolibri-app;
MimeType=x-scheme-handler/kolibri;x-scheme-handler/@APP_URI_SCHEME@;
X-Endless-LaunchMaximized=true
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Exec=@KOLIBRI_APP_LIBEXECDIR@/kolibri-gnome-launcher %U
NoDisplay=true
StartupNotify=false
DBusActivatable=true
MimeType=x-scheme-handler/x-kolibri-dispatch;
MimeType=x-scheme-handler/@DISPATCH_URI_SCHEME@;
9 changes: 9 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ build_profile = get_option('profile')
base_application_id = get_option('base_application_id')
base_object_path = get_option('base_object_path')
profile_env_prefix = get_option('env_prefix')
profile_uri_prefix = get_option('uri_prefix')

if build_profile == 'development'
base_application_id += '.Devel'
base_object_path += '/Devel'
profile_env_prefix += 'DEVEL_'
profile_uri_prefix += '-devel'
endif

frontend_application_id = base_application_id
Expand All @@ -51,6 +53,10 @@ daemon_private_object_path = daemon_object_path + '/Private'
search_provider_application_id = base_application_id + '.SearchProvider'
search_provider_object_path = base_object_path + '/SearchProvider'

kolibri_uri_scheme = 'kolibri'
app_uri_scheme = profile_uri_prefix + '-app'
dispatch_uri_scheme = profile_uri_prefix + '-dispatch'

po_dir = join_paths(meson.project_source_root(), 'po')

kolibri_app_libexecdir = join_paths(libexecdir, 'kolibri-app')
Expand All @@ -67,6 +73,9 @@ kolibri_app_config.set('GETTEXT_PACKAGE', meson.project_name())
kolibri_app_config.set('LOCALE_DIR', locale_dir)
kolibri_app_config.set('BUILD_PROFILE', build_profile)
kolibri_app_config.set('PROFILE_ENV_PREFIX', profile_env_prefix)
kolibri_app_config.set('KOLIBRI_URI_SCHEME', kolibri_uri_scheme)
kolibri_app_config.set('APP_URI_SCHEME', app_uri_scheme)
kolibri_app_config.set('DISPATCH_URI_SCHEME', dispatch_uri_scheme)
kolibri_app_config.set('KOLIBRI_APP_LIBEXECDIR', kolibri_app_libexecdir)
kolibri_app_config.set('KOLIBRI_APP_DATA_DIR', kolibri_app_data_dir)
kolibri_app_config.set('ENDLESS_KEY_DATA_DIR', endless_key_data_dir)
Expand Down
6 changes: 3 additions & 3 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ option(
option(
'env_prefix',
type: 'string',
value: 'KOLIBRI_',
value: 'KOLIBRI',
description: 'Prefix for environment variables. When profile is "development", "DEVEL_" is appended'
)

option(
'uri_prefix',
type: 'string',
value: 'x-kolibri-',
description: 'Prefix for custom URI schemes. When profile is "development", "devel-" is appended'
value: 'x-kolibri',
description: 'Prefix for custom URI schemes. When profile is "development", "-devel" is appended'
)
3 changes: 3 additions & 0 deletions src/kolibri_app/config.py.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
BUILD_PROFILE = "@BUILD_PROFILE@"
PROFILE_ENV_PREFIX = "@PROFILE_ENV_PREFIX@"
KOLIBRI_URI_SCHEME = "@KOLIBRI_URI_SCHEME@"
APP_URI_SCHEME = "@APP_URI_SCHEME@"
DISPATCH_URI_SCHEME = "@DISPATCH_URI_SCHEME@"
PROJECT_VERSION = "@PROJECT_VERSION@"
BASE_OBJECT_PATH = "@BASE_OBJECT_PATH@"
BASE_APPLICATION_ID = "@BASE_APPLICATION_ID@"
Expand Down
4 changes: 3 additions & 1 deletion src/kolibri_gnome/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import WebKit
from kolibri_app.config import APP_URI_SCHEME
from kolibri_app.config import BASE_APPLICATION_ID
from kolibri_app.config import BASE_OBJECT_PATH
from kolibri_app.config import KOLIBRI_APP_DATA_DIR
from kolibri_app.config import KOLIBRI_URI_SCHEME
from kolibri_app.globals import get_release_notes_version
from kolibri_app.globals import get_version
from kolibri_app.globals import XDG_CURRENT_DESKTOP
Expand Down Expand Up @@ -246,7 +248,7 @@ def __window_on_open_new_window(
return new_window.get_main_webview() if new_window else None

def __handle_open_file_url(self, url: str):
valid_url_schemes = ("kolibri", "x-kolibri-app")
valid_url_schemes = (KOLIBRI_URI_SCHEME, APP_URI_SCHEME)

url_tuple = urlsplit(url)

Expand Down
15 changes: 9 additions & 6 deletions src/kolibri_gnome/kolibri_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import WebKit
from kolibri_app.config import APP_URI_SCHEME
from kolibri_app.config import BUILD_PROFILE
from kolibri_app.config import ENDLESS_KEY_DATA_DIR
from kolibri_app.config import FRONTEND_APPLICATION_ID
from kolibri_app.config import KOLIBRI_URI_SCHEME
from kolibri_app.config import PROJECT_VERSION
from kolibri_app.config import VCS_TAG
from kolibri_app.utils import get_app_modules_debug_info
Expand Down Expand Up @@ -100,7 +102,7 @@ def kolibri_version(self) -> str:

@property
def default_url(self) -> str:
return "x-kolibri-app:/explore"
return f"{APP_URI_SCHEME}:/explore"

@property
def webkit_web_context(self) -> WebKit.WebContext:
Expand All @@ -114,10 +116,10 @@ def shutdown(self):

def get_absolute_url(self, url: str) -> typing.Optional[str]:
url_tuple = urlsplit(url)
if url_tuple.scheme == "kolibri":
if url_tuple.scheme == KOLIBRI_URI_SCHEME:
target_url = self.parse_kolibri_url_tuple(url_tuple)
return self.__kolibri_daemon.get_absolute_url(target_url)
elif url_tuple.scheme == "x-kolibri-app":
elif url_tuple.scheme == APP_URI_SCHEME:
target_url = self.parse_x_kolibri_app_url_tuple(url_tuple)
return self.__kolibri_daemon.get_absolute_url(target_url)
return url
Expand All @@ -131,7 +133,8 @@ def kolibri_api_get_async(self, *args, **kwargs):
def should_open_url(self, url: str) -> bool:
return (
url == self.default_url
or urlsplit(url).scheme in ("kolibri", "x-kolibri-app", "about", "blob")
or urlsplit(url).scheme
in (KOLIBRI_URI_SCHEME, APP_URI_SCHEME, "about", "blob")
or self.is_url_in_scope(url)
)

Expand Down Expand Up @@ -230,7 +233,7 @@ def _get_kolibri_library_path(self, search: typing.Optional[str] = None) -> str:
return f"{LEARN_PATH_PREFIX}home"

def url_to_x_kolibri_app(self, url: str) -> str:
return urlsplit(url)._replace(scheme="x-kolibri-app", netloc="").geturl()
return urlsplit(url)._replace(scheme=APP_URI_SCHEME, netloc="").geturl()

def parse_x_kolibri_app_url_tuple(self, url_tuple: SplitResult) -> str:
"""
Expand Down Expand Up @@ -399,7 +402,7 @@ def __init__(self, channel_id: str):

@property
def default_url(self) -> str:
return f"x-kolibri-app:{self.__default_path}"
return f"{APP_URI_SCHEME}:{self.__default_path}"

@property
def __default_path(self) -> str:
Expand Down
6 changes: 4 additions & 2 deletions src/kolibri_gnome_launcher/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from urllib.parse import urlunparse

from gi.repository import Gio
from kolibri_app.config import DISPATCH_URI_SCHEME
from kolibri_app.config import KOLIBRI_URI_SCHEME
from kolibri_app.config import LAUNCHER_APPLICATION_ID

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -41,7 +43,7 @@ def do_open(self, files: list, n_files: int, hint: str):
def handle_uri(self, uri: str):
url_tuple = urlsplit(uri)

if url_tuple.scheme == "x-kolibri-dispatch":
if url_tuple.scheme == DISPATCH_URI_SCHEME:
channel_id = url_tuple.netloc
node_path = url_tuple.path
node_query = url_tuple.query
Expand All @@ -59,7 +61,7 @@ def handle_uri(self, uri: str):

if node_path or node_query:
kolibri_node_url = urlunparse(
("kolibri", node_path, "", None, node_query, None)
(KOLIBRI_URI_SCHEME, node_path, "", None, node_query, None)
)
kolibri_gnome_args.append(kolibri_node_url)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ build_kolibri_dispatch_uri(const gchar *channel_id,
uri_path = g_strconcat("/", node_path, NULL);

kolibri_uri = g_uri_build(G_URI_FLAGS_NONE,
"x-kolibri-dispatch",
DISPATCH_URI_SCHEME,
NULL,
channel_id,
-1,
Expand Down
1 change: 1 addition & 0 deletions src/kolibri_gnome_search_provider/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gobject_dep = dependency('gobject-2.0')

_c_config = configuration_data()
_c_config.set_quoted('PACKAGE_STRING', package_string)
_c_config.set_quoted('DISPATCH_URI_SCHEME', dispatch_uri_scheme)
_c_config.set_quoted('FRONTEND_APPLICATION_ID', frontend_application_id)
_c_config.set_quoted('FRONTEND_OBJECT_PATH', frontend_object_path)
_c_config.set_quoted('FRONTEND_CHANNEL_APPLICATION_ID_PREFIX', frontend_channel_application_id_prefix)
Expand Down

0 comments on commit cbf311b

Please sign in to comment.