Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open links with this browser system-wide #7

Closed
benaryorg opened this issue Jan 10, 2015 · 25 comments
Closed

open links with this browser system-wide #7

benaryorg opened this issue Jan 10, 2015 · 25 comments
Assignees

Comments

@benaryorg
Copy link

As already commented on openrepos.net, it would be great to have support for opening links using webpirate.

It worked using WebCat, by creating a file in /usr/share/applications/.

Links:
llelectronics/webcat#13
https://together.jolla.com/question/1836/set-default-browser/

@Dax89
Copy link
Owner

Dax89 commented Jan 11, 2015

I will try to do it for the version 0.8.7 :)

@Dax89
Copy link
Owner

Dax89 commented Jan 25, 2015

Now it is possible to open links with WebPirate using the link that you have provided (https://together.jolla.com/question/1836/set-default-browser)

I have investigated in order to open a new tab when the browser is already opened: the default browser creates a D-Bus service with an "openUrl" method (the name can be seen in open-url.desktop)

I have managed to create a service for WebPirate too, and I have modified open-url.desktop so it points to the WebPirate's one, but it doesn't works (I don't know why), calling it manually, when the browser is opened, works correctly and opens a new tab with the requested url.

I will close this issue when the browser can load links even if it is already opened.

@MoritzJT
Copy link

Is there any progresss on this?

@Dax89
Copy link
Owner

Dax89 commented May 28, 2015

It's a Sailfish issue, I can't do anything atm.
The only workaround available is that one linked in this issue!

@Mikaela
Copy link
Contributor

Mikaela commented Jul 7, 2015

I have done the workaround, but it appears that there is another issue:

If Webpirate is already open and there is only one tab (more not tested) and you click a link in another application WebPirate is opened, but nothing more happens. I think it should open a new tab including whatever link was clicked.

I think this might be #7 (comment) in less technical words.

@Dax89
Copy link
Owner

Dax89 commented Jul 7, 2015

It's a known issue, and it is related to the default browser issue in Sailfish.

In order to open a new tab, WebPirate needs a DBus service, this one is present in the source code, but is disabled (and untested from about 10 releases) because it is not allowed in the harbour.

@Dax89
Copy link
Owner

Dax89 commented Aug 5, 2015

I have news about this issue!

The commit ce0bded restores DBus service and it's only running when WebPirate is active (it seems to be allowed in the harbour, because Tweetian does the same thing), but, now the problem is different:

Case 1 (edit harbour-webpirate.desktop)

MimeType=text/html;x-maemo-urischeme/http;x-maemo-urischeme/https;

works as always: executing WebPirate instead of Sailfish Browser BUT it does not open new tabs.

Case 2 (edit open-url.desktop)

# MimeType=text/html;x-maemo-urischeme/http;x-maemo-urischeme/https;

# X-Maemo-Service=org.sailfishos.browser
# X-Maemo-Method=org.sailfishos.browser.openUrl
X-Maemo-Service=org.harbour.webpirate
X-Maemo-Method=org.harbour.webpirate.openUrl

If WebPirate is running it creates a new tab BUT when an external link is clicked from another application and the browser is NOT running, nothing happens.

I have tried to do Case 1 + Case 2, but Saiflish fallbacks to Case 1.
I'll leave this service active in 1.5 (IF it passes the validation!) so anyone is free to make tests!

@Mikaela
Copy link
Contributor

Mikaela commented Sep 1, 2015

Is there something preventing the line in harbour-webpirate.desktop from being uncommented by default (something in harbour submission rules?)? Currently I must always remember to edit the file after updating Web Pirate.

(Also what is the proper spelling for Web Pirate? I think I change how I spell/write/type it a lot.)

@Dax89
Copy link
Owner

Dax89 commented Sep 1, 2015

Yes, it's about harbour restrictions!

(Also what is the proper spelling for Web Pirate? I think I change how I spell/write/type it a lot.)

It's ok "WebPirate" and "Web Pirate" too :D

@benaryorg
Copy link
Author

If this is fixed, feel free to close this issue.

@Mikaela
Copy link
Contributor

Mikaela commented Sep 4, 2015

It's not, because that one line must always be uncommented after update (even if I am unsure can anything be done to it) and new tabs cannot be opened from external applications if Web Pirate is already open (it only opens Web Pirate with whatever tab you have active).

@llelectronics
Copy link

I think the dbus solution works fine for WebPirate if it would have a "daemon" like dbus service running waiting in the background to start WebPirate even if the UI part is closed.
This is exactly how Sailfish-Browser does it. The booster-browser is basically listening all the time to the dbus requests.

@llelectronics
Copy link

I have to correct me there. Actually the booster-browser has nothing todo with the dbus calls. Its just a form of preloading the browser libraries for faster startup times.
What actually is needed is simply a dbus service file describing the dbus service and which file to execute if the service call is made but the application itself is not opened (so basically when WebPirate is closed)
I was able to make it run just like sailfish-browser with my latest commit in Webcat.
See: llelectronics/webcat@c09911b
This commit is a bit messy and big as I basically copied over your dbus receiver libraries Dax89 which is btw great work again :)
The actual interesting file is this one: https://github.com/llelectronics/webcat/blob/c09911b4d1abc4a3dd67116994bf315c29825861/org.harbour.webcat.service
This can be easily adapted for webpirate aswell and needs to go into /usr/share/dbus-1/services/ .
Sadly harbour does not allow to put any file into that directory or even /usr/local/share/dbus-1/services/ for that matter. So even if I managed to make a workable solution here we cannot upload it to the Jolla Store. :(

PS: So basically Method 1 and 2 can work together by adding that dbus service file and open-url.desktop then can look like this

[Desktop Entry]
Type=Application
Name=Browser
NotShowIn=X-MeeGo;
MimeType=text/html;x-maemo-urischeme/http;x-maemo-urischeme/https;
X-Maemo-Service=org.harbour.webpirate
X-Maemo-Method=org.harbour.webpirate.openUrl

P.P.S: I think I found another interesting thing. If I did nothing wrong you can also put the dbus service file in ~/.local/share/dbus-1/services . This would make it possible at least to add an option in the browser itself (under settings or somewhere) to make it the default.

@Dax89
Copy link
Owner

Dax89 commented Oct 6, 2015

@llelectronics Thanks for the extra info!!! :)

Writing the .service file in /.local/share/dbus-1/services overrides sailfish-browser settings too? And it is allowed, in the Harbour?

@llelectronics
Copy link

The .service file does not need to override sailfish-browser settings.
The only thing that needs to override the open-url.desktop file is the open-url.desktop file with the webpirate dbus calls in ~/.local/share/applications/open-url.desktop

As for harbour. I don't think it can be shipped in the rpm directly as it would need to ship a hardcoded path /home/nemo which isn't allowed.
But as you are able in c++ to determine the home directory you could of course just add a button in settings that copies or creates the dbus service file in ~/.local/share/dbus-1/services/ and copies or creates the open-url.desktop file with the dbus X-Maemo-Service and -Method adapted in ~/.local/share/applications
This open-url.desktop file will then override the global one :)

@Dax89
Copy link
Owner

Dax89 commented Oct 6, 2015

Ok, now is crystal clear!
It's pretty easy to implement.

Thanks for your research @llelectronics :)

@Dax89
Copy link
Owner

Dax89 commented Oct 12, 2015

@llelectronics:
This is the implementation: 2ed95d9
Fell free to use it in Webcat :)

The problem is: Jolla allows those type of "local" services?

@llelectronics
Copy link

At least th harbour checker should not complain.
And about the implementation. I think I will use xdg-mime to register a default html handler and create a open-url-webcat.desktop file. That is in my opinion a more correct way of doing it.
You can take a look at https://github.com/llelectronics/mimer/blob/master/src/helper.hpp
To see how I use xdg-mime.
Currently it needs a linking from mimeapps.list to defaults.list due to an error in the SailfishOS/Mer version of xdg-mime tool.

In general maybe we could work out a standard somehow so that the mimer application will be able to set default apps (not only a webbrowser) with the dbus service file creation.

@Dax89
Copy link
Owner

Dax89 commented Oct 12, 2015

It's ok for me.

About the MIME, do you mean something like this? (thanks for the helper.cpp btw :) )

void DefaultBrowser::overwriteMime()
{
    this->setBusy(true);

    QString desktopfilename = QString("%1.desktop").arg(qApp->applicationName());

    this->setMime("text/html", desktopfilename);
    this->setMime("x-maemo-urischeme/http", desktopfilename);
    this->setMime("x-maemo-urischeme/https", desktopfilename);

    this->setBusy(false);
}

void DefaultBrowser::restoreMime()
{
    this->setBusy(true);

    this->setMime("text/html", "open-url.desktop");
    this->setMime("x-maemo-urischeme/http", "open-url.desktop");
    this->setMime("x-maemo-urischeme/https", "open-url.desktop");

    this->setBusy(false);
}

void DefaultBrowser::setMime(const QString &mimetype, const QString &desktopfile) const
{
    QDir localappsdir = this->localApplicationsDirectory();

    if(!localappsdir.exists("defaults.list"))
    {
        QProcess symlink;
        symlink.start(QString("ln -sf %1 %2").arg(localappsdir.absoluteFilePath("mimeapps.list"), localappsdir.absoluteFilePath("defaults.list")));
        symlink.waitForFinished();
    }

    QProcess xdgmime;
    xdgmime.start(QString("xdg-mime default %1 %2").arg(desktopfile, mimetype));
    xdgmime.waitForFinished();
}

@llelectronics
Copy link

Yeah exactly :)

@Dax89
Copy link
Owner

Dax89 commented Oct 12, 2015

Ok, the commit 3590e31 uses xdg-mime.

At the current state openUrl() DBus method is called correctly, but if I press a link when the browser is not started nothing happens.

text/html, x-maemo-urischeme/http and x-maemo-urischeme/https MIME types are set to "open-url-webpirate.desktop"

And openurl-webpirate.desktop contains:

[Desktop Entry]
Type=Application
Name=Browser
NotShownIn=X-MeeGo;
MimeType=text/html;x-maemo-urischeme/http;x-maemo-urischeme/https;
X-Maemo-Service=org.harbour.webpirate
X-Maemo-Method=org.harbour.webpirate.openUrl

The .service is in .local/share/dbus-1/service, and in .local/share/applications I have open-url-webpirate.desktop

Am I missing something?

@llelectronics
Copy link

The folder should be ~/.local/share/dbus-1/services though in your source I think it is correct.
Hmm... maybe it cached that stuff on my device somehow. Does it work when you put the .service file in /usr/share/dbus-1/services ?
If it is then its really a caching thing. I would wonder if then it will still work if you remove that file from there.

PS: OK small update. Its not a caching issue. I tested it on my device by removing the .local/share/dbus-1/services/ directory and it stopped working. So it has to be something else.

PPS: Try perhaps editing the exec line in your service file to see if you can call harbour-webpirate directly without using the invoker.

@Dax89
Copy link
Owner

Dax89 commented Oct 12, 2015

Ok fixed in 01b70a4

.service files are case sensitive :D

@carmenfdezb
Copy link

Great!!! I'm testing v1.7-5 and it seems it's working fine ;)

@Dax89
Copy link
Owner

Dax89 commented Oct 14, 2015

Perfect! 👍
So I can close this issue.

(Implemented in: 2ed95d9 3590e31 01b70a4)

@Dax89 Dax89 closed this as completed Oct 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants