你有正确的开始。您只需要处理 mime-type 并决定您希望如何打开 Libre Office。这是本地文件的示例(uri 是您要在本地打开的服务器上特定文档的路径):
this._web_view.connect('mime-type-policy-decision-requested',
(function (webview, frame, request, mimetype, decision) {
if (mimetype === 'application/msword' ||
mimetype === 'application/vnd.oasis.opendocument.spreadsheet') {
// Spawn a libreoffice process with this uri. Necessary because
// we want to open the files as templates - the `-n` option
// requires the user to save-as.
GLib.spawn_async(null, /* cwd */
['libreoffice', '-n', request.get_uri()],
null, /* inherit environment */
GLib.SpawnFlags.DO_NOT_REAP_CHILD | GLib.SpawnFlags.SEARCH_PATH,
null /* setup function */ );
decision.ignore();
return true;
} else if (mimetype === 'application/pdf') {
// if PDF, use the build in viewer (usually evince)
Gtk.show_uri(null, request.get_uri(), 0);
decision.ignore();
return true;
}
// default handler
return false;
}).bind(this));