[polari] utils: Linkify all supported URI schemes



commit 651c71fed5413dc5a06712277fba97e54cfc3552
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Nov 3 08:34:10 2015 +0800

    utils: Linkify all supported URI schemes
    
    Instead of maintaining and adding individual URI schemes
    to linkify we ask the system which are supported and match
    against those.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755563

 src/utils.js |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 9aa1d7e..3961b01 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -36,12 +36,13 @@ const GPASTE_BASEURL = 'https://paste.gnome.org/'
 const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)';
 const _leadingJunk = '[\\s`(\\[{\'\\"<\u00AB\u201C\u2018]';
 const _notTrailingJunk = '[^\\s`!()\\[\\]{};:\'\\".,<>?\u00AB\u00BB\u201C\u201D\u2018\u2019]';
+const _uriList = getURISchemes();
 
 const _urlRegexp = new RegExp(
     '(^|' + _leadingJunk + ')' +
     '(' +
         '(?:' +
-            '(?:http|https|ftp)://' +             // scheme://
+            '(?:' + _uriList.join('|') + '):' +   // scheme:
             '|' +
             'www\\d{0,3}[.]' +                    // www.
             '|' +
@@ -76,6 +77,24 @@ function debug(str) {
         log('DEBUG: ' + str);
 }
 
+function getURISchemes() {
+    let apps = Gio.AppInfo.get_all();
+    let prefix = 'x-scheme-handler/';
+    let schemes = [];
+
+    apps.forEach(function(app) {
+        let types = app.get_supported_types();
+        if (!types)
+            return;
+
+        types.forEach(function(type) {
+            if (type.startsWith(prefix))
+                schemes.push(type.replace(prefix, ''));
+        });
+    });
+    return schemes;
+}
+
 function addJSSignalMethods(proto) {
     proto.connectJS = Signals._connect;
     proto.disconnectJS = Signals._disconnect;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]