77 lines
3.5 KiB
Lua
77 lines
3.5 KiB
Lua
-- Loaded once after GlueParent. Numeric actions use the existing owned C_Login
|
|
-- registration; backend networking never runs on the Lua/UI thread.
|
|
if not C_OctoUpdate then
|
|
C_OctoUpdate = {};
|
|
local function action(which)
|
|
local f = C_Login and C_Login.GetTurtleRealmSnapshot;
|
|
if type(f) ~= "function" then return 0; end
|
|
local ok, value = pcall(f, which, 0, 0);
|
|
return ok and value or 0;
|
|
end
|
|
function C_OctoUpdate.GetState()
|
|
local value = action(14);
|
|
return value == 1 and "current" or value == 2 and "pending" or "unknown";
|
|
end
|
|
function C_OctoUpdate.ApplyAndRestart()
|
|
-- Never launch without a usable original quit API, and never quit if
|
|
-- CreateProcess failed. This API is only called after confirmation.
|
|
if type(ForceQuit) ~= "function" then return false; end
|
|
if action(15) ~= 1 then return false; end
|
|
ForceQuit();
|
|
return true;
|
|
end
|
|
local function installButtons()
|
|
local button = CreateFrame("Button", "OctoUpdateAvailable", GlueParent, "GlueButtonTemplate");
|
|
button:SetSize(190, 32);
|
|
button:SetPoint("BOTTOM", GlueParent, "BOTTOM", 0, 44);
|
|
button:SetText("Update available");
|
|
button:Hide();
|
|
local dialog = CreateFrame("Frame", "OctoUpdateConfirmation", GlueParent);
|
|
dialog:SetSize(400, 150);
|
|
dialog:SetPoint("CENTER");
|
|
dialog:SetFrameStrata("DIALOG");
|
|
dialog:EnableMouse(true);
|
|
local background = dialog:CreateTexture(nil, "BACKGROUND");
|
|
background:SetAllPoints();
|
|
background:SetColorTexture(0.05, 0.05, 0.05, 0.98);
|
|
local text = dialog:CreateFontString(nil, "OVERLAY", "OptionsFontLarge");
|
|
text:SetPoint("TOP", 0, -22);
|
|
text:SetWidth(360);
|
|
text:SetText("Update and restart OctoWoW?");
|
|
local accept = CreateFrame("Button", nil, dialog, "GlueButtonTemplate");
|
|
accept:SetSize(150, 30); accept:SetPoint("BOTTOMLEFT", 24, 20); accept:SetText("Update and restart");
|
|
local cancel = CreateFrame("Button", nil, dialog, "GlueButtonTemplate");
|
|
cancel:SetSize(150, 30); cancel:SetPoint("BOTTOMRIGHT", -24, 20); cancel:SetText("Cancel");
|
|
cancel:SetScript("OnClick", function() dialog:Hide(); end);
|
|
accept:SetScript("OnClick", function()
|
|
if C_OctoUpdate.GetState() ~= "pending" then dialog:Hide(); return; end
|
|
if not C_OctoUpdate.ApplyAndRestart() then
|
|
text:SetText("Could not start OctoUpdater. Close the game and run OctoUpdater.exe.");
|
|
end
|
|
end);
|
|
button:SetScript("OnClick", function()
|
|
text:SetText("Update and restart OctoWoW?"); dialog:Show();
|
|
end);
|
|
dialog:Hide();
|
|
local poll, elapsed = CreateFrame("Frame"), 1;
|
|
poll:SetScript("OnUpdate", function(_, delta)
|
|
elapsed = elapsed + delta;
|
|
if elapsed < 1 then return; end
|
|
elapsed = 0;
|
|
local state = C_OctoUpdate.GetState(); -- first call starts async check
|
|
local login = AccountLogin and AccountLogin:IsShown();
|
|
local select = CharacterSelect and CharacterSelect:IsShown();
|
|
if state == "pending" and (login or select) then button:Show();
|
|
else button:Hide(); dialog:Hide(); end
|
|
end);
|
|
end
|
|
-- GlueParent.lua can load before its XML frames exist.
|
|
if GlueParent then installButtons(); else
|
|
local bootstrap = CreateFrame("Frame");
|
|
bootstrap:SetScript("OnUpdate", function(self)
|
|
if not GlueParent then return; end
|
|
self:SetScript("OnUpdate", nil); self:Hide(); installButtons();
|
|
end);
|
|
end
|
|
end
|