From ef1149be034d366776980d8309313364c4b8b56a Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 1 Nov 2015 11:10:28 +0000 Subject: [PATCH] show README on first install FossilOrigin-Name: 997c8e06966d761cf703a04d80d52e0eaf0dff4132b0ead56e94fcdd812e2b14 --- install.rdf | 2 +- main/main.js | 39 +++++++++++++++++++++++++++++++++++++++ main/modules/sbapi/opentab.js | 3 ++- main/prefs/prefs.js | 19 ++++++++++--------- main/startup.js | 2 +- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/install.rdf b/install.rdf index cfa2ebd..43f3074 100644 --- a/install.rdf +++ b/install.rdf @@ -2,7 +2,7 @@ guerilla@ketmar.no-ip.org - 0.0.3.6rc4 + 0.0.3.6rc5 2 Guerilla Scripting Userscript injecting engine for power users. diff --git a/main/main.js b/main/main.js index eeecb47..cb9bcd6 100644 --- a/main/main.js +++ b/main/main.js @@ -29,3 +29,42 @@ let pkgman = require("pkg/pkgman"); require("injector"); require("concmd"); + + +const {openTab} = require("sbapi/opentab"); +registerWindowLoadHook("readme hook", function (win) { + // open documentation on first run + if (!addonOptions.fsoReadmeViewed) { + //addonOptions.fsoReadmeViewed = true; + //conlog("win=", win, "; url=", gsdoxUrl+"README.txt"); + //openTab(win, gsdoxUrl+"README.txt", false); + let dwn = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); + if (!dwn) { conlog("000"); return; } + let chromeWindow = + dwn.QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIWebNavigation). + QueryInterface(Ci.nsIDocShellTreeItem). + rootTreeItem. + QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIDOMWindow); + if (!chromeWindow) { conlog("001"); return; } + let bro = chromeWindow.gBrowser; + if (!bro) { conlog("002"); return; } + //conlog("***"); + + let oss = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); + let observer = { + observe: function (aSubject, aTopic, aData) { + //conlog("OBS: ", aTopic); + if (aTopic === "sessionstore-windows-restored") { + if (!addonOptions.fsoReadmeViewed) { + bro.selectedTab = bro.addTab(gsdoxUrl+"README.txt"); + addonOptions.fsoReadmeViewed = true; + } + //oss.removeObserver(observer, "sessionstore-windows-restored"); + } + }, + }; + oss.addObserver(observer, "sessionstore-windows-restored", false); + } +}); diff --git a/main/modules/sbapi/opentab.js b/main/modules/sbapi/opentab.js index 52bac02..95e0f27 100644 --- a/main/modules/sbapi/opentab.js +++ b/main/modules/sbapi/opentab.js @@ -10,13 +10,14 @@ //////////////////////////////////////////////////////////////////////////////// exports.openTab = function (win, url, inbg) { let afterCurrent = null; - if (typeof(inbg) == "object") { + if (typeof(inbg) === "object") { afterCurrent = ("afterCurrent" in inbg ? !!inbg.afterCurrent : null); inbg = ("background" in inbg ? !!inbg.background : null); } else if (typeof(inbg) != "boolean") { inbg = null; } let dwn = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); + if (!dwn) return; let chromeWindow = dwn.QueryInterface(Ci.nsIInterfaceRequestor). getInterface(Ci.nsIWebNavigation). diff --git a/main/prefs/prefs.js b/main/prefs/prefs.js index 6302379..b3c50e8 100644 --- a/main/prefs/prefs.js +++ b/main/prefs/prefs.js @@ -11,6 +11,7 @@ const PREFS_BRANCH = "extensions.guerilla."; let PREFS = { + fsoReadmeViewed: false, // readme viewed? debugMode: false, debugCache: false, logEnabled: true, @@ -35,17 +36,17 @@ const PREFS_DIR_NAMES = { //////////////////////////////////////////////////////////////////////////////// -const PREFS_OLD_DIRS = { - jsdir: "guerillajs", - libdir: "guerillajs_libs", - dbdir: "guerillajs_data", - pkgdir: "guerillajs_packages", - pkgdbdir: "guerillajs_packages/_0data", - pkgtempdir: "guerillajs_packages/_0temp", -}; - // restore old values if user has some old dirs (function () { + const PREFS_OLD_DIRS = { + jsdir: "guerillajs", + libdir: "guerillajs_libs", + dbdir: "guerillajs_data", + pkgdir: "guerillajs_packages", + pkgdbdir: "guerillajs_packages/_0data", + pkgtempdir: "guerillajs_packages/_0temp", + }; + const dirSvcProps = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); let oldFound = false; for (let [n, v] of Iterator(PREFS_OLD_DIRS)) { diff --git a/main/startup.js b/main/startup.js index 3f21432..74835f4 100644 --- a/main/startup.js +++ b/main/startup.js @@ -344,7 +344,7 @@ function initAddonInternal (global, addonName, urlMain, urlJS) { let mainLoaded = false; function runHooks (hooktype, list, rev, firsttime) { - let rest = Array.prototype.splice.call(arguments, 2, arguments.length); + let rest = Array.prototype.splice.call(arguments, 4, arguments.length); let callmain = false; if (firsttime) { //Cu.reportError("runHooks ("+hooktype+"): first time"); -- 2.11.4.GIT