diff --git a/src/chrome/content/progress.js b/src/chrome/content/progress.js
index def3ed3..14de71e 100644
--- a/src/chrome/content/progress.js
+++ b/src/chrome/content/progress.js
@@ -8,16 +8,22 @@ const kI2PBootstrapErrorTopic = "I2PBootstrapError"
const kI2PLogHasWarnOrErrTopic = "I2PLogHasWarnOrErr"
+Cu.import("resource://gre/modules/Services.jsm")
Cu.import("resource://gre/modules/XPCOMUtils.jsm")
XPCOMUtils.defineLazyModuleGetter(this, "LauncherUtil", "resource://i2pbutton/modules/launcher-util.jsm")
const I2PLauncherLogger = Cc["@geti2p.net/i2pbutton-logger;1"].getService(Ci.nsISupports).wrappedJSObject
-const gI2PProcessService = Cc["@geti2p.net/i2pbutton-process-service;1"].getService(Ci.nsISupports).wrappedJSObject
var gObsSvc
var gOpenerCallbackFunc // Set when opened from network settings.
+var gIsInitialBootstrap
+var gInitialPanelID
+function closeThisWindow(reason) {
+ dump('closeThisWindow\n')
+ window.close()
+}
function initDialog()
{
@@ -33,7 +39,7 @@ function initDialog()
return
}
}
- catch (e) { dump(e + "\n") }
+ catch (e) { dump(`${e}\n`) }
try
{
@@ -42,39 +48,64 @@ function initDialog()
gObsSvc.addObserver(gObserver, kBootstrapStatusTopic, false)
gObsSvc.addObserver(gObserver, kI2PBootstrapErrorTopic, false)
gObsSvc.addObserver(gObserver, kI2PLogHasWarnOrErrTopic, false)
- }
- catch (e) {}
- var isBrowserStartup = false
- if (window.arguments)
- {
- isBrowserStartup = window.arguments[0]
+ var isBrowserStartup = false
+ if (window.arguments)
+ {
+ let wargs = window.arguments || window.arguments.wrappedJSObject
+ isBrowserStartup = wargs[0]
+ dump(`window.arguments = ${wargs}\n`)
+ dump(`window.arguments.length = ${wargs.length}\n`)
- if (window.arguments.length > 1)
- gOpenerCallbackFunc = window.arguments[1]
- }
+ if (window.arguments.length > 1)
+ gInitialPanelID = window.arguments[1]
+ }
- if (gOpenerCallbackFunc)
- {
- // Dialog was opened from network settings: hide Open Settings button.
- var extraBtn = document.documentElement.getButton("extra2")
- extraBtn.setAttribute("hidden", true)
- }
- else
- {
- // Dialog was not opened from network settings: change Cancel to Quit.
- var cancelBtn = document.documentElement.getButton("cancel")
- var quitKey = (LauncherUtil.isWindows) ? "quit_win" : "quit"
- cancelBtn.label = 'Cancel'//LauncherUtil.getLocalizedString(quitKey)
- }
+ if (gOpenerCallbackFunc)
+ {
+ // Dialog was opened from network settings: hide Open Settings button.
+ var extraBtn = document.documentElement.getButton("extra2")
+ extraBtn.setAttribute("hidden", true)
+ }
+ else
+ {
+ // Dialog was not opened from network settings: change Cancel to Quit.
+ var cancelBtn = document.documentElement.getButton("cancel")
+ var quitKey = (LauncherUtil.isWindows) ? "quit_win" : "quit"
+ cancelBtn.label = 'Cancel'//LauncherUtil.getLocalizedString(quitKey)
+ }
- // If opened during browser startup, display the "please wait" message.
- if (isBrowserStartup)
- {
- var pleaseWait = document.getElementById("progressPleaseWait")
- if (pleaseWait)
- pleaseWait.removeAttribute("hidden")
+ // If opened during browser startup, display the "please wait" message.
+ if (isBrowserStartup)
+ {
+ var pleaseWait = document.getElementById("progressPleaseWait")
+ if (pleaseWait)
+ pleaseWait.removeAttribute("hidden")
+ }
+
+ // Test if the i2p console port is open or not
+
+ let consolePort = Services.prefs.getIntPref("extensions.i2pbutton.console_port_i2pj", 7647)
+ LauncherUtil.waitForPortToOpen(consolePort, () => {
+ var meter = document.getElementById("progressMeter")
+ if (meter) {
+ meter.value = meter.value + 30
+ }
+ setTimeout(() => {
+ window.close()
+ }, 5000)
+ })
}
+ catch (e) {
+ dump(`Error: ${e}\n`)
+ }
+ dump('initDialog done\n')
+}
+
+function onCancel() {
+ //
+ dump('onCancel\n')
+ cleanup()
}
@@ -104,13 +135,9 @@ function stopI2PBootstrap()
const kErrorPrefix = "Setting DisableNetwork=1 failed: ";
try
{
- var svc = Cc["@torproject.org/torlauncher-protocol-service;1"]
- .getService(Ci.nsISupports);
- svc = svc.wrappedJSObject;
var settings = {};
settings["DisableNetwork"] = true;
var errObj = {};
- if (!svc.I2PSetConfWithReply(settings, errObj))
I2PLauncherLogger.log(5, kErrorPrefix + errObj.details);
}
catch(e)
@@ -119,31 +146,8 @@ function stopI2PBootstrap()
}
}
-// Fake it for now. The main goal is to could say with more confidence that
-// the router has had time to start before the user can start using the browser
-// as any other browser.
-setTimeout(() => {
- var meter = document.getElementById("progressMeter")
- if (meter)
- meter.value = meter.value + 15
-}, 5000)
-setTimeout(() => {
- var meter = document.getElementById("progressMeter")
- if (meter)
- meter.value = meter.value + 15
-}, 10000)
-
-setTimeout(() => {
- var meter = document.getElementById("progressMeter")
- if (meter)
- meter.value = meter.value + 15
-}, 15000)
-
-setTimeout(() => {
- window.close()
-}, 25000)
var gObserver = {
diff --git a/src/chrome/content/progress.xul b/src/chrome/content/progress.xul
index 83fe948..c4d9bf2 100644
--- a/src/chrome/content/progress.xul
+++ b/src/chrome/content/progress.xul
@@ -6,8 +6,7 @@
-->
-
+
@@ -18,7 +17,7 @@
persist="screenX screenY"
buttons="cancel"
buttonlabelextra2="&i2pprogress.openSettings;"
- ondialogcancel="return onCancel();"
+ ondialogcancel="onCancel();"
ondialogextra2="onOpenSettings();"
onload="initDialog();">
diff --git a/src/components/i2p-router-process.js b/src/components/i2p-router-process.js
index f3d2ad4..59d3d7b 100644
--- a/src/components/i2p-router-process.js
+++ b/src/components/i2p-router-process.js
@@ -117,6 +117,13 @@ I2PProcessService.prototype =
let prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch)
let shouldShowDelayUserDialog = prefs.getBoolPref("extensions.i2pbutton.delay_user_with_dialog", true)
+ let canStartPromise = self._config_checker.ensure_config()
+ canStartPromise.then(() => {
+ self._logger.log(3, 'Starting the router')
+ self.I2PStartAndControlI2P(true)
+
+ })
+
try {
if (shouldShowDelayUserDialog) {
self.openWaitForRouterDialog()
@@ -131,13 +138,6 @@ I2PProcessService.prototype =
self._logger.log(5, `Unknown error while executing delay user dialog: ${err}`)
}
- let canStartPromise = self._config_checker.ensure_config()
- canStartPromise.then(() => {
- self._logger.log(3, 'Starting the router')
- self.I2PStartAndControlI2P(true)
-
- })
-
// After the router process is spawned.
/*if (self.mDelayUserDialog) {
setTimeout(() => {
@@ -280,7 +280,13 @@ I2PProcessService.prototype =
//var win = ww.openWindow(null, "chrome://i2pbutton/content/progress.xul", "wizard", "chrome,dialog=no,modal,centerscreen", {blabla:0})
const ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher)
- self.mDelayUserDialog = ww.openWindow(null, "chrome://i2pbutton/content/progress.xul", "startingrouter", "chrome,dialog=no,modal,centerscreen", {blabla:0})
+ self.mDelayUserDialog = ww.openWindow(
+ null,
+ "chrome://i2pbutton/content/progress.xul",
+ "startingrouter",
+ "chrome,dialog=no,modal,centerscreen",
+ [true])
+ this._logger.log(3, 'After open wait for router dialog')
setTimeout(() => {
let progressmeter = self.mDelayUserDialog.document.getElementById('progressMeter')
@@ -396,7 +402,7 @@ I2PProcessService.prototype =
// Set an environment variable that points to the I2P data directory.
let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment)
- env.set("I2P_BROWSER_I2P_DATA_DIR", dataDir.path)
+ env.set('I2P_BROWSER_I2P_DATA_DIR', dataDir.path)
// On Windows, prepend the I2P program directory to PATH. This is
// needed so that pluggable transports can find OpenSSL DLLs, etc.
@@ -418,7 +424,7 @@ I2PProcessService.prototype =
p.init(exeFile)
for (var i = 0; i < args.length; ++i)
- this._logger.log(2, " " + args[i])
+ this._logger.log(2, ` ${args[i]}`)
// Possible fix for Windows and cmd.exe window spawn.
p.startHidden = true
@@ -478,10 +484,8 @@ I2PProcessService.prototype =
{
this.mBootstrapErrorOccurred = true
LauncherUtil.setBoolPref(this.kPrefPromptAtStartup, true)
- let phase = LauncherUtil.getLocalizedBootstrapStatus(aStatusObj,
- "TAG")
- let reason = LauncherUtil.getLocalizedBootstrapStatus(aStatusObj,
- "REASON")
+ let phase = LauncherUtil.getLocalizedBootstrapStatus(aStatusObj, "TAG")
+ let reason = LauncherUtil.getLocalizedBootstrapStatus(aStatusObj, "REASON")
let details = LauncherUtil.getFormattedLocalizedString(
"i2p_bootstrap_failed_details", [phase, reason], 2)
I2PLauncherLogger.log(5, "I2P bootstrap error: [" + aStatusObj.TAG +
diff --git a/src/components/router-config-manager.js b/src/components/router-config-manager.js
index 5feddef..888cb54 100644
--- a/src/components/router-config-manager.js
+++ b/src/components/router-config-manager.js
@@ -137,6 +137,8 @@ router.startup.jetty9.migrated=true
routerconsole.welcomeWizardComplete=true
`
+let noscript = Cu.import("resource://i2pbutton/modules/noscript-control.js")
+noscript.initialize()
function RouterConfigManager() {
this.version = '0.1'
diff --git a/src/install.rdf b/src/install.rdf
index 80be73b..66ffb37 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -6,7 +6,7 @@
I2pbutton
Meeh, Mikal Villa
i2pbutton@geti2p.net
- 0.3.7
+ 0.3.8
true
https://geti2p.net/en/download/lab
chrome://i2pbutton/skin/i2p.png
diff --git a/src/modules/launcher-util.jsm b/src/modules/launcher-util.jsm
index 2b08c1c..781d8f0 100644
--- a/src/modules/launcher-util.jsm
+++ b/src/modules/launcher-util.jsm
@@ -5,6 +5,8 @@ const Ci = Components.interfaces
const Cu = Components.utils
const Cr = Components.results
+Cu.importGlobalProperties(["XMLHttpRequest"])
+
const kPropBundleURI = "chrome://i2pbutton/locale/i2pbutton.properties"
const kPropNamePrefix = "i2pbutton."
@@ -19,6 +21,38 @@ let logger = {
}
}
+const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
+
+function delay(timeout, func) {
+ let timer = new Timer(function () {
+ // Remove the reference so that it can be reaped.
+ delete delay.timers[idx];
+
+ func();
+ }, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
+
+ // Store a reference to the timer so that it's not reaped before it fires.
+ let idx = delay.timers.push(timer) - 1;
+ return idx
+}
+delay.timers = []
+
+function repeat(timeout, func) {
+ let timer = new Timer(function () {
+ func();
+ }, timeout, Ci.nsITimer.TYPE_REPEATING_SLACK);
+
+ // Store a reference to the timer so that it's not reaped before it fires.
+ let idx = delay.timers.push(timer) - 1;
+ return idx
+}
+repeat.timers = []
+
+// Wrapper since window.setTimeout isn't always available in context/scope.
+function setTimeout(func, interval) {
+ delay(interval, func)
+}
+
const LauncherUtil = {
get isMac()
@@ -83,6 +117,13 @@ const LauncherUtil = {
return argsArray;
},
+ setTimeout: (func, interval) => {
+ delay(interval, func)
+ },
+ setInterval: (func, interval) => {
+ repeat(interval, func)
+ },
+
get _networkSettingsWindow()
{
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator)
@@ -163,6 +204,33 @@ const LauncherUtil = {
asSvc.quit(0x12) // eAttemptQuit (0x02) + eRestart (0x10)
},
+
+
+ waitForPortToOpen: function(portNum, doneCallback, interval) {
+ interval = interval || 3000
+ let portOpen = false
+ let testPort = () => {
+ var xhr = new XMLHttpRequest()
+ xhr.open('GET', `http://127.0.0.1:${portNum}`)
+ xhr.onerror = () => {
+ console.log(`Still waiting for ${portNum} to open`)
+ if (!portOpen) {
+ setTimeout(testPort, interval)
+ }
+ }
+ xhr.onload = () => {
+ console.log(`Port ${portNum} seem open now finally`)
+ portOpen = true
+ if ('function' === typeof doneCallback) {
+ doneCallback(portNum)
+ }
+ }
+ xhr.send()
+ }
+ testPort()
+ },
+ //waitForPortToOpen(7647, () => { console.log('ALL DONE') })
+
getRouterDefaultArgs: function() {
let dataDir = this.getI2PConfigPath(true)
let exeFile = this.getI2PBinary()