mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-04 15:44:11 +01:00
add DownloadPost autocmd event
This commit is contained in:
@@ -37,10 +37,12 @@ function IO() //{{{
|
||||
const WINDOWS = navigator.platform == "Win32";
|
||||
const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator"
|
||||
|
||||
var environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
||||
.getService(Components.interfaces.nsIEnvironment);
|
||||
var directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
const environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
||||
.getService(Components.interfaces.nsIEnvironment);
|
||||
const directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
const downloadManager = Components.classes["@mozilla.org/download-manager;1"]
|
||||
.createInstance(Components.interfaces.nsIDownloadManager);
|
||||
|
||||
var processDir = directoryService.get("CurWorkD", Components.interfaces.nsIFile);
|
||||
var cwd = processDir.path;
|
||||
@@ -67,10 +69,7 @@ function IO() //{{{
|
||||
shellcmdflag = "-c";
|
||||
}
|
||||
|
||||
function expandPathList(list)
|
||||
{
|
||||
return list.split(",").map(io.expandPath).join(",");
|
||||
}
|
||||
function expandPathList(list) list.split(",").map(io.expandPath).join(",")
|
||||
|
||||
// TODO: why are we passing around so many strings? I know that the XPCOM
|
||||
// file API is limited but...
|
||||
@@ -85,6 +84,28 @@ function IO() //{{{
|
||||
return head + pathSeparator + tail;
|
||||
}
|
||||
|
||||
var downloadListener = {
|
||||
onDownloadStateChange: function (state, download)
|
||||
{
|
||||
if (download.state == downloadManager.DOWNLOAD_FINISHED)
|
||||
{
|
||||
autocommands.trigger("DownloadPost",
|
||||
{
|
||||
url: download.source.spec,
|
||||
file: download.targetFile.path,
|
||||
title: download.displayName,
|
||||
size: download.size
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
downloadManager.addListener(downloadListener);
|
||||
liberator.registerObserver("shutdown", function () {
|
||||
downloadManager.removeListener(downloadListener);
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// OPTIONS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
@@ -40,6 +40,7 @@ const config = { //{{{
|
||||
|
||||
autocommands: [["BookmarkAdd", "Triggered after a page is bookmarked"],
|
||||
["DOMLoad", "Triggered when a page's DOM content has fully loaded"],
|
||||
["DownloadPost", "Triggered when a download has completed"],
|
||||
["LocationChange", "Triggered when changing tabs or when naviagtion to a new location"],
|
||||
["PageLoadPre", "Triggered after a page load is initiated"],
|
||||
["PageLoad", "Triggered when a page gets (re)loaded/opened"],
|
||||
|
||||
Reference in New Issue
Block a user