Custom url protocol for OSX desktop app using electron by atom - macos

I am new to dekstop app by electron. However i built a desktop app using this source code and just changing the links to my site. Now I have a functional desktop app for mac.
But i want to open my app using a link say appName://and-some-link-follows
How can i implement custom url schema to open dekstop app whenever i click appName://....
For example:
I want to do something like Slack desktop app which opens up by clicking slack://and-some-link
Any help please. Stuck here for 2 days. Thanks in advance.

Today I faced a similar thing and upon doing some researching, I found this useful tutorial on how to do it. It explains everything thoroughly and I think it might be useful for others facing the same issue. This is the highlights:
const electron = require('electron')
const protocol = electron.protocol
// handles links `todo2://<something>`
const PROTOCOL_PREFIX = 'todo2'
function createWindow () {
mainWindow = new BrowserWindow({width: 1000, height: 800})
protocol.registerHttpProtocol(PROTOCOL_PREFIX, (req, cb) => {
const fullUrl = formFullTodoUrl(req.url)
devToolsLog('full url to open ' + fullUrl)
mainWindow.loadURL(fullUrl)
})
}
Also there's a guide on how to build for both OSX and Windows at the end of the post I linked.
For those who'd like to read a bit more, here's a link to the official docs.

I found it.
Do a build for your app
Right click -> show package content
In info.plist add the following
Open app once to register customURL into system.
In terminal enter /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump|egrep "(bindings.*:$)"|sort to check wheather yours is in the list.

Related

Is there a platform-independent method for opening links in an Outlook-addin?

I have an outlook-addin written in Angular framework, which communicates with the Outlook through the office-js.
My goal is to implement a service that opens any kind of URLs/links in any mainstream platforms where outlook is available, to be specific: in Google Chrome, Safari, Firefox, Opera, Internet Explorer, The MacOS desktop Outlook - old and new versions either, and most of the Windows desktop Outlook versions (2016, 2019, O365). But unfortunately I can not find a way that works in all of the platforms, and I want to avoid implementing it in a platform-dependent manner.
The first problem I encountered with, is that when I am trying to open links by a simple js function window.open(url) then the outlook versions that use Internet Explorer as an engine are failing to open URLs that contain the character #. That is because IE does not seem to be able to read this character and it cuts the URL in half by the # character and it completely removes the parts followed by the #.
https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg
window.open(
"https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg",
"_blank"
);
For example, if I try to open the URL above on Windows outlook 2019 which uses Internet Explorer as it's engine, then the url will look like this in the end:
https://en.wikipedia.org/wiki/County_Antrim
For a solution I've implemented a workaround that encodes the URL by a built-in function that comes with typescript which allows the IE to be able to open the link. By simply passing the encoded URL to the window.open() does not work because it concatenates the url with the host of my addin, which results in an invalid link.
window.open(
encodeURIComponent(
"https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg"
),
"_blank"
);
The host of my addin + the encoded URL:
https://localhost.eu.ngrok.io/https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCounty_Antrim%23%2Fmedia%2FFile%3ABallycastle_Harbour_-_geograph.org.uk_-_468327.jpg
So I had to redirect manually with a simple html code as shown below:
redirect.html:
<html>
<head>
<script type="text/javascript">
window.onload = function (event) {
var regex = /\?url=(.*)/ig;
var match = regex.exec(location.search);
if (match && match[1] && match[1] !== "") {
location.href = decodeURIComponent(match[1]);
}
else {
document.body.innerHTML = "Redirect failed!";
}
};
</script>
</head>
</html>
typescript code:
url = "https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg"
window.open("./redirect.html?url=" + encodeURIComponent(url), "_blank");
Unfortunately, this method also has some flaws in the desktop outlook of MacOS. Redirecting makes the links open in a simple webviewer of the outlook application, and not in Safari as it is expected since the default browser is set to Safari in both of the system preferences and in the outlook browser preference. Despite the fact that it can open the links in this webviewer, I can not use it, because some of the webpages I want to navigate to does not support to be opened by the webviewer.
I was suspecting that this behaviour is caused by the relativity of the url ("./redirect..."). So I have tried building the URL by adding dynamically or even hardcoding the host of my addin to the beginning of the URL this way:
`${window.location.origin + window.location.pathname}/redirect.html?url=` + encodeURIComponent(url);
But there was no difference in the results by doing it, so I am guessing that referencing the host of the addin itself does not change quality or state of the URL, meaning that it is still managed as a relative link.
Since I had the opportunity to host the redirect.html from another server, I have tried referencing the redirect.html file from another host, and that way even the MacOS Outlook worked perfectly, proving my suspicion of the wrong management of relative links.
I have also tried using the function called openBrowserWindow provided by office-js the following way:
Office.context.ui.openBrowserWindow(url);
But this was also a dead-end, since this could neither handle the # character in IE nor it was supported in all of the platforms I need to use.
The last workaround I have tried is by completely reworking the service and instead of opening the links by using js or ts functions, I have tried binding the urls to the href attribute of <a></a> elements, however the application requirements exclude this method, as there are some links that are expected to be opened by double clicking, which can not be done with using an <a> tag as far as I know, at least not in an "hacky" way.
Which I would really like to know, what makes the links open in the webviewer of the MacOS outlook application instead of the default browser of the system? Is it a setting I am missing, or is there a way to force using the safari?
Did you try simply doing:
if (Office.context.ui.openBrowserWindow) {
Office.context.ui.openBrowserWindow("https://google.com");
} else
{
window.open("https://google.com");
}
Since openBrowserWindow is selectively not supported in OWA, window.open will automatically take over.

Unable To Share Text On Xamarin Form

Hello Everyone I want to share the Text on Xamarin Form using Library plugin.share. I have successfully implemented the library and on android i can able to share the text but in iOS it returns me nothing. i have done the share code on button click event so when i click on button in iOS its doesn't returns me anything.i tried the Below code but doesn't got succeed
CrossShare.Current.Share("Hii alll", "Share");
please help me to get out of this,thanks in advance
You want to take a look at UIActivityViewController, you can find the documentation here https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIActivityViewController/
And Xamarin.Forms specific example http://devcenter.wintellect.com/jwood/implementing-sharing-in-xamarin-forms
This is a bit old, but I was having a similar issue and was able to resolve it.
First of all, you need to add the plugin Plugin.Share to ALL Xamarin.Forms projects (Portable, iOS, Android, UWP).
In the class that references the share code, add...
using Plugin.Share;
using Plugin.Share.Abstractions;
CrossShare.Share() doesn't work with strings, directly. You need to new up a ShareMessage.
var title = "Title For The Share";
var message = "Text to share.";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title });
I can't say specifically to iOS, as I don't have a Mac and can't test that project, but Android and Windows 10 is working.

Titanium appcelerator window add multiple url

In titanium appcelerator we can add single external js file to our window as follow
var win = Ti.UI.createWindow({
url:'myfile.js'
})
Can we add multiple js file to window?
The url property of Ti.UI.Window was deprecated long ago, maybe 2 years ago. It was a terrible implementation back in the day. You should not be using it.
If you won't want to use the Alloy framework, you should be creating windows as CommonJS modules where you export a window reference or a method to open the window. There are examples of this in the guides.

Launching app within another app

So I'm looking for the best way to open an app within another app on Xamarin forms when the app is install.. Currently I have an external link to the playstore (which loads up the app on play store) but, when the app is installed I'd like to link directly to this..
How would i go about doing this with Xamarin forms? Cheers
Here's how I went about fixing this issue :
Setting up app linking in Xamarin
This is possible but we need to change the code to the app we are linking to.
"App from" (in our case) changes :
To link to another app the change made to the main app is minimal:
1) Create a new URI. E.g. (URI AppLink = new Uri("http://appto/load");)
2) Set up the link with Device.OpenURI(AppLink);
"App to" (in our case) changes :
Android:
In main activity we need to add an intent filter, here is an example of what this looks like:
[IntentFilter(new [] {Android.Content.Intent.ActionView },
DataScheme="appto",
DataHost="load",
Categories=new [] { Android.Content.Intent.CategoryDefault })]
The DataScheme and DataHost correspond to the uri link above.
iOS:
Within the info.plist file in the advanced tab we need to create a new "url type"
I added an identifier of “com.appto.test” and URL scheme of “appto” (corresponds with uri link)
After these changes are done, the app should link. Atleast with the example it worked.

Firefox addon SDK, open an url automatically after Firefox startup?

With Firefox addon SDK, how to open specific url automatically after Firefox startup (for the purpose of testing page)
I've tried tabs.open(url) in this doc:
var tabs = require("sdk/tabs");
tabs.open("http://www.example.com");
And this one and a lot of Stackoverflow page ..., but none of them works at all...(It is still just a blank tab after $ cfx run)
I think you want to do this:
const tabs = require('sdk/tabs');
exports.main = function (options, callbacks) {
if (options.loadReason === 'startup') {
tabs.open('https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload');
}
};
The documentation for this is located here:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload
#canuckistani is actually right: if you're not seeing it, it's probably because your options.loadReason is something else. If you've got the plugin installed already, for example, you would get loadReason upgrade instead when you try to install the plugin again. See that url #canuckistani gave for more info.

Resources