Skip to content

Commit

Permalink
Merge pull request #135 from endlessm/add-url-scheme-prefix
Browse files Browse the repository at this point in the history
Prefix app-specific URL schemes to avoid conflicts
  • Loading branch information
starnight authored Nov 24, 2023
2 parents 722b049 + 1232192 commit b201307
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 22 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@;
6 changes: 5 additions & 1 deletion data/metainfo/org.endlessos.Key.metainfo.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@
</screenshot>
</screenshots>
<releases>
<release version="0.8+next" date="2023-11-13" type="development">
<release version="0.8+next" date="2023-11-23" type="development">
<description>
<ul>
<li>
Kolibri's debug mode can now be enabled with the
<code>KOLIBRI_DEBUG</code> environment variable.
</li>
<li>
The Endless Key app now uses its own set of URI schemes, so Kolibri
channel launchers will not try to open in Endless Key.
</li>
</ul>
</description>
</release>
Expand Down
26 changes: 17 additions & 9 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ locale_dir = join_paths(get_option('prefix'), get_option('localedir'))
datadir = join_paths(get_option('prefix'), get_option('datadir'))

build_profile = get_option('profile')

if build_profile == 'default'
base_application_id = 'org.endlessos.Key'
base_object_path = '/org/endlessos/Key'
profile_env_prefix = 'ENDLESS_KEY_'
elif build_profile == 'development'
base_application_id = 'org.endlessos.Key.Devel'
base_object_path = '/org/endlessos/Key/Devel'
profile_env_prefix = 'ENDLESS_KEY_DEVEL_'
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 @@ -52,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 @@ -68,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
28 changes: 28 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,31 @@ option(
],
value: 'default'
)

option(
'base_application_id',
type: 'string',
value: 'org.endlessos.Key',
description: 'Base application ID. When profile is "development", ".Devel" is appended'
)

option(
'base_object_path',
type: 'string',
value: '/org/endlessos/Key',
description: 'Base D-Bus object path. When profile is "development", "/Devel" is appended'
)

option(
'env_prefix',
type: 'string',
value: 'ENDLESS_KEY_',
description: 'Prefix for environment variables. When profile is "development", "DEVEL_" is appended'
)

option(
'uri_prefix',
type: 'string',
value: 'x-endless-key',
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 b201307

Please sign in to comment.