From 4430f9e887fc50ca0722819f159111aa4c340786 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Thu, 12 Jul 2018 23:33:55 +0200 Subject: [PATCH 1/4] Add VSCode-related files to the .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1c9a6b8c5..65d3c2649 100644 --- a/.gitignore +++ b/.gitignore @@ -54,7 +54,6 @@ tmp/ .byebug_history .sass-cache/ .DS_Store -.idea .redcar .stgit* *.swap @@ -73,6 +72,8 @@ capybara-*.html *.rbc # IDE +.idea +.vscode diaspora.iml # Dolphin's directory's preferences files From 8709c45d30dc6ada3f065a8892f0aaf173cd997d Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Thu, 12 Jul 2018 23:50:32 +0200 Subject: [PATCH 2/4] Move the protocol handler into a proper helper module Previous file history in 80dfdcd6afb600b400c7bccd427918658feebdf3, couldn't keep it. --- .../javascripts/helpers/protocol_handler.js | 22 +++++++++++++++++++ app/assets/javascripts/main.js | 2 +- app/assets/javascripts/protocol-handler.js | 17 -------------- 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 app/assets/javascripts/helpers/protocol_handler.js delete mode 100644 app/assets/javascripts/protocol-handler.js diff --git a/app/assets/javascripts/helpers/protocol_handler.js b/app/assets/javascripts/helpers/protocol_handler.js new file mode 100644 index 000000000..6d9368979 --- /dev/null +++ b/app/assets/javascripts/helpers/protocol_handler.js @@ -0,0 +1,22 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +Diaspora.ProtocolHandler = { + register: function() { + if (typeof (window.navigator.registerProtocolHandler) !== "function") { + return false; + } + + var protocol = location.protocol; + var slashes = protocol.concat("//"); + var host = slashes.concat(window.location.hostname); + + if (location.port) { + host = host.concat(":" + location.port); + } + + window.navigator.registerProtocolHandler("web+diaspora", host.concat("/link?q=%s"), document.title); + return true; + } +}; + +Diaspora.ProtocolHandler.register(); diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 563bbc315..e359ad7c2 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -45,5 +45,5 @@ //= require api/authorization_page //= require bootstrap-markdown/bootstrap-markdown //= require helpers/markdown_editor +//= require helpers/protocol_handler //= require jquery.are-you-sure -//= require protocol-handler diff --git a/app/assets/javascripts/protocol-handler.js b/app/assets/javascripts/protocol-handler.js deleted file mode 100644 index 6afedf409..000000000 --- a/app/assets/javascripts/protocol-handler.js +++ /dev/null @@ -1,17 +0,0 @@ -// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later - -function registerDiasporaLinksProtocol() { - var protocol = location.protocol; - var slashes = protocol.concat("//"); - var host = slashes.concat(window.location.hostname); - - if (location.port) { - host = host.concat(":" + location.port); - } - - window.navigator.registerProtocolHandler("web+diaspora", host.concat("/link?q=%s"), document.title); -} - -if (typeof (window.navigator.registerProtocolHandler) === "function") { - registerDiasporaLinksProtocol(); -} From f8a4a2c510a08c246ac957ac71d86ff5e86ffdb0 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Fri, 13 Jul 2018 00:04:41 +0200 Subject: [PATCH 3/4] Gracefully ignore exceptions when trying to register the ProtocolHandler --- .../javascripts/helpers/protocol_handler.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/helpers/protocol_handler.js b/app/assets/javascripts/helpers/protocol_handler.js index 6d9368979..c857c1b51 100644 --- a/app/assets/javascripts/helpers/protocol_handler.js +++ b/app/assets/javascripts/helpers/protocol_handler.js @@ -2,19 +2,20 @@ Diaspora.ProtocolHandler = { register: function() { - if (typeof (window.navigator.registerProtocolHandler) !== "function") { + if (!window.navigator.registerProtocolHandler) { return false; } - var protocol = location.protocol; - var slashes = protocol.concat("//"); - var host = slashes.concat(window.location.hostname); - - if (location.port) { - host = host.concat(":" + location.port); + try { + window.navigator.registerProtocolHandler( + "web+diaspora", + [window.location.protocol, "//", window.location.host, "/link?q=%s"].join(""), + document.title + ); + } catch (_) { + return false; } - window.navigator.registerProtocolHandler("web+diaspora", host.concat("/link?q=%s"), document.title); return true; } }; From af500dabbccc0fca4344286901c9dc72ddf5114d Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Fri, 13 Jul 2018 00:23:49 +0200 Subject: [PATCH 4/4] Add section in the User's settings to register the protocol handler closes #7833 --- app/assets/javascripts/app/pages/settings.js | 4 ++++ app/assets/javascripts/helpers/protocol_handler.js | 2 -- app/views/users/_edit.haml | 10 ++++++++++ config/locales/diaspora/en.yml | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/pages/settings.js b/app/assets/javascripts/app/pages/settings.js index be522514f..6592c1b8c 100644 --- a/app/assets/javascripts/app/pages/settings.js +++ b/app/assets/javascripts/app/pages/settings.js @@ -15,6 +15,10 @@ app.pages.Settings = Backbone.View.extend({ form: $("#post-default-aspects") }); $("#update_profile_form").areYouSure(); + + $("#register-protocol-handler").click(function() { + Diaspora.ProtocolHandler.register(); + }); } }); // @license-end diff --git a/app/assets/javascripts/helpers/protocol_handler.js b/app/assets/javascripts/helpers/protocol_handler.js index c857c1b51..090362f27 100644 --- a/app/assets/javascripts/helpers/protocol_handler.js +++ b/app/assets/javascripts/helpers/protocol_handler.js @@ -19,5 +19,3 @@ Diaspora.ProtocolHandler = { return true; } }; - -Diaspora.ProtocolHandler.register(); diff --git a/app/views/users/_edit.haml b/app/views/users/_edit.haml index 0ec3102b7..65bf97f0e 100644 --- a/app/views/users/_edit.haml +++ b/app/views/users/_edit.haml @@ -180,6 +180,16 @@ .clearfix= f.submit t(".change"), class: "btn btn-primary pull-right", id: "change_email_preferences" %hr + .row + .col-md-12 + %h3#protocol-handler + = t(".protocol_handler.title") + %p= t(".protocol_handler.description") + .form-group + %button.btn.btn-default#register-protocol-handler + = t(".protocol_handler.register") + %hr + .row .col-md-6.account-data %h3= t(".export_data") diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index f28b8f551..e6d80d0b1 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -1242,6 +1242,11 @@ en: lock_username: "Your username will be locked. You will not be able to create a new account on this pod with the same ID." no_turning_back: "There is no turning back! If you’re really sure, enter your password below." + protocol_handler: + title: "web+diaspora:// protocol handler" + description: "Clicking this button will ask your browser to install a handler that allows us to open web+diaspora:// URLs on your home pod. This is currently experimental and interactions will depend on your browser." + register: "Register" + privacy_settings: title: "Privacy settings" strip_exif: "Strip metadata such as location, author, and camera model from uploaded images (recommended)"