From 943afa47f9b67561915c01082e3339c974c81eb9 Mon Sep 17 00:00:00 2001
From: DarkGod <darkgod@net-core.org>
Date: Fri, 28 Mar 2014 15:34:03 +0100
Subject: [PATCH] regen the addons list after the browsing

---
 game/engines/default/engine/utils.lua              | 14 +++++++-------
 .../default/modules/boot/dialogs/Addons.lua        | 14 ++++++++++++--
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/game/engines/default/engine/utils.lua b/game/engines/default/engine/utils.lua
index ae59451ca1..4b633ab4cb 100644
--- a/game/engines/default/engine/utils.lua
+++ b/game/engines/default/engine/utils.lua
@@ -1970,12 +1970,12 @@ function util.uuid()
 	return uuid
 end
 
-function util.browserOpenUrl(url)
-	if core.steam and core.steam.openOverlayUrl(url) then return true end
-	if core.webview then
-		require("engine.ui.Dialog"):webPopup(url)
-		return true
-	end
+function util.browserOpenUrl(url, forbid_methods)
+	forbid_methods = forbid_methods or {}
+	if core.webview and not forbid_methods.webview then local d = require("engine.ui.Dialog"):webPopup(url) return "webview", d end
+	if core.steam and not forbid_methods.steam and core.steam.openOverlayUrl(url) then return "steam", true end
+
+	if forbid_methods.native then return false end
 
 	local tries = {
 		"rundll32 url.dll,FileProtocolHandler %s",	-- Windows
@@ -1992,7 +1992,7 @@ function util.browserOpenUrl(url)
 		local urlbase = table.remove(tries, 1)
 		urlbase = urlbase:format(url)
 		print("Trying to run URL with command: ", urlbase)
-		if os.execute(urlbase) == 0 then return true end
+		if os.execute(urlbase) == 0 then return "native", true end
 	end
 	return false
 end
diff --git a/game/engines/default/modules/boot/dialogs/Addons.lua b/game/engines/default/modules/boot/dialogs/Addons.lua
index 548efff18d..e42185a647 100644
--- a/game/engines/default/modules/boot/dialogs/Addons.lua
+++ b/game/engines/default/modules/boot/dialogs/Addons.lua
@@ -34,8 +34,11 @@ function _M:init()
 	local url1 = Textzone.new{text="You can get new addons at #LIGHT_BLUE##{underline}#http://te4.org/addons/tome#{normal}#", auto_height=true, auto_width=true, fct=function() util.browserOpenUrl("http://te4.org/addons/tome") end}
 	local url2 = Textzone.new{text=" ", auto_height=true, auto_width=true, fct=function()end}
 	if core.steam then
-		url1 = Textzone.new{text="You can get new addons at #LIGHT_BLUE##{underline}#Steam Workshop#{normal}#", auto_height=true, auto_width=true, fct=function() util.browserOpenUrl("http://steamcommunity.com/app/"..core.steam.appid().."/workshop/ ") end}
-		url2 = Textzone.new{text=" or at #LIGHT_BLUE##{underline}#http://te4.org/addons/tome#{normal}#", auto_height=true, auto_width=true, fct=function() util.browserOpenUrl("http://te4.org/addons/tome") end}
+		url1 = Textzone.new{text="You can get new addons at #LIGHT_BLUE##{underline}#Steam Workshop#{normal}#", auto_height=true, auto_width=true, fct=function() util.browserOpenUrl("http://steamcommunity.com/app/"..core.steam.appid().."/workshop/", {webview=true}) end}
+		url2 = Textzone.new{text=" or at #LIGHT_BLUE##{underline}#http://te4.org/addons/tome#{normal}#", auto_height=true, auto_width=true, fct=function()
+			local method, d = util.browserOpenUrl("http://te4.org/addons/tome", {steam=true})
+			if method == "webview" and d then d.unload = function() self:regen() end end
+		end}
 	end
 
 	self.c_compat = Checkbox.new{default=false, width=math.floor(self.iw / 3 - 40), title="Show incompatible", on_change=function() self:switch() end}
@@ -82,6 +85,13 @@ function _M:init()
 	}
 end
 
+function _M:regen()
+	local d = new()
+	d.__showup = false
+	game:replaceDialog(self, d)
+	self.next_dialog = d
+end
+
 function _M:select(item)
 	if item and item.adds and self.c_adds then
 		self.c_adds:setList(item.adds)
-- 
GitLab