Bug 577380 - Use the default application for the mime type to open the document
Using appExec for the last application that registered the document was failing in certain cases, such as for the Open Office for which the application execution string is being registered as "soffice %u" in ~/.recently-used.xbel. In general, using the default application for the mime type seems to be a more predictable way to open documents. We still fall back to using the appExect for the last application if the default application for a given mime type was not found.
This commit is contained in:
parent
88e68dec21
commit
d67c88e4dc
@ -65,6 +65,17 @@ DocDisplayItem.prototype = {
|
||||
|
||||
// Opens a document represented by this display item.
|
||||
launch : function() {
|
||||
// While using Gio.app_info_launch_default_for_uri() would be shorter
|
||||
// in terms of lines of code, we are not doing so because that would
|
||||
// duplicate the work of retrieving the mime type.
|
||||
let mimeType = this._docInfo.get_mime_type();
|
||||
let appInfo = Gio.app_info_get_default_for_type(mimeType, true);
|
||||
|
||||
if (appInfo != null) {
|
||||
appInfo.launch_uris([this._docInfo.get_uri()], Main.createAppLaunchContext());
|
||||
} else {
|
||||
log("Failed to get default application info for mime type " + mimeType +
|
||||
". Will try to use the last application that registered the document.");
|
||||
let appName = this._docInfo.last_application();
|
||||
let [success, appExec, count, time] = this._docInfo.get_application_info(appName);
|
||||
if (success) {
|
||||
@ -74,7 +85,7 @@ DocDisplayItem.prototype = {
|
||||
// already a part of appExec, so we don't supply any files to appInfo.launch().
|
||||
|
||||
// The 'command line' passed to create_from_command_line is allowed to contain
|
||||
// '%<something>' macros that are exapnded to file name / icon name, etc,
|
||||
// '%<something>' macros that are expanded to file name / icon name, etc,
|
||||
// so we need to escape % as %%
|
||||
appExec = appExec.replace(/%/g, "%%");
|
||||
|
||||
@ -82,14 +93,15 @@ DocDisplayItem.prototype = {
|
||||
|
||||
// The point of passing an app launch context to launch() is mostly to get
|
||||
// startup notification and associated benefits like the app appearing
|
||||
// on the right desktop; but it doesn't really work for now because we aren't
|
||||
// reading the application's desktop file, and thus don't find the
|
||||
// StartupNotify=true in it. So, despite passing the app launch context,
|
||||
// no startup notification occurs.
|
||||
// on the right desktop; but it doesn't really work for now because with
|
||||
// the way we create the appInfo we aren't reading the application's desktop
|
||||
// file, and thus don't find the StartupNotify=true in it. So, despite passing
|
||||
// the app launch context, no startup notification occurs.
|
||||
appInfo.launch([], Main.createAppLaunchContext());
|
||||
} else {
|
||||
log("Failed to get application info for " + this._docInfo.get_uri());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//// Protected method overrides ////
|
||||
|
Loading…
Reference in New Issue
Block a user