Skip to content

Commit 5d477bb

Browse files
authored
Merge pull request #2626 from Squidly271/Fix-DockerBlocking
Fix: Prevent docker installs / updates from blocking the GUI
2 parents f6555c4 + 0700194 commit 5d477bb

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

emhttp/plugins/dynamix.docker.manager/AddContainer.page

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ if (substr($_SERVER['REQUEST_URI'],0,7) != '/Docker') {
2222
$docker = "$docroot/languages/$locale/docker.dot";
2323
if (file_exists($docker)) $language = array_merge($language,unserialize(file_get_contents($docker)));
2424
}
25+
// Avoid blocking other browser tabs by releasing the PHP session lock
26+
// before running long-running container creation logic.
27+
if (session_status() === PHP_SESSION_ACTIVE) {
28+
session_write_close();
29+
}
2530
eval('?>'.parse_file("$docroot/plugins/dynamix.docker.manager/include/CreateDocker.php"));
2631
?>

emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,63 @@ function cpu_pinning() {
6868
## CREATE CONTAINER ##
6969
##########################
7070

71+
// Simple UI blocker used by create/update operations so the user can't keep clicking around mid-install.
72+
function dockerUIBlockerScript($enable) {
73+
if ($enable) {
74+
echo <<<HTML
75+
<script>
76+
(function () {
77+
try {
78+
var d = (window.parent && window.parent.document) ? window.parent.document : document;
79+
if (!d || !d.body) return;
80+
81+
// Define helpers once.
82+
if (!window.parent) window.parent = window;
83+
if (!window.parent.dockerUIBlock) {
84+
window.parent.dockerUIBlock = function (on) {
85+
try {
86+
var doc = (window.parent && window.parent.document) ? window.parent.document : document;
87+
if (!doc || !doc.body) return;
88+
89+
var blockerId = 'dockerInstallBlocker';
90+
var blockerClass = 'docker-install-blocker';
91+
92+
if (!on) {
93+
var o = doc.getElementById(blockerId);
94+
if (o) o.remove();
95+
return;
96+
}
97+
98+
var o2 = doc.getElementById(blockerId);
99+
if (!o2) {
100+
o2 = doc.createElement('div');
101+
o2.id = blockerId;
102+
o2.className = blockerClass;
103+
doc.body.appendChild(o2);
104+
}
105+
} catch (e) {}
106+
};
107+
}
108+
109+
window.parent.dockerUIBlock(true);
110+
} catch (e) {}
111+
})();
112+
</script>
113+
HTML;
114+
} else {
115+
echo <<<HTML
116+
<script>
117+
(function () {
118+
try {
119+
var w = window.parent || window;
120+
if (w && w.dockerUIBlock) w.dockerUIBlock(false);
121+
} catch (e) {}
122+
})();
123+
</script>
124+
HTML;
125+
}
126+
}
127+
71128
if (isset($_POST['contName'])) {
72129
$postXML = postToXML($_POST, true);
73130
$dry_run = isset($_POST['dryRun']) && $_POST['dryRun']=='true';
@@ -76,6 +133,8 @@ function cpu_pinning() {
76133
// Get the command line
77134
[$cmd, $Name, $Repository] = xmlToCommand($postXML, $create_paths);
78135
readfile("$docroot/plugins/dynamix.docker.manager/log.htm");
136+
echo '<link type="text/css" rel="stylesheet" href="'.autov("/plugins/dynamix.docker.manager/sheets/AddContainer.css",true).'">';
137+
if (!$dry_run) dockerUIBlockerScript(true);
79138
@flush();
80139
// Saving the generated configuration file.
81140
$userTmplDir = $dockerManPaths['templates-user'];
@@ -114,6 +173,7 @@ function cpu_pinning() {
114173
if (!$DockerClient->doesImageExist($Repository)) {
115174
// Pull image
116175
if (!pullImage($Name, $Repository)) {
176+
dockerUIBlockerScript(false);
117177
echo '<div style="text-align:center"><button type="button" onclick="done()">'._('Done').'</button></div><br>';
118178
goto END;
119179
}
@@ -166,6 +226,7 @@ function cpu_pinning() {
166226
execCommand($cmd);
167227
if ($startContainer) addRoute($Name); // add route for remote WireGuard access
168228

229+
dockerUIBlockerScript(false);
169230
echo '<div style="text-align:center"><button type="button" onclick="openTerminal(\'docker\',\''.addslashes($Name).'\',\'.log\')">'._('View Container Log').'</button> <button type="button" onclick="done()">'._('Done').'</button></div><br>';
170231
goto END;
171232
}
@@ -178,6 +239,8 @@ function cpu_pinning() {
178239
$echo = empty($_GET['mute']);
179240
if ($echo) {
180241
readfile("$docroot/plugins/dynamix.docker.manager/log.htm");
242+
echo '<link type="text/css" rel="stylesheet" href="'.autov("/plugins/dynamix.docker.manager/sheets/AddContainer.css",true).'">';
243+
dockerUIBlockerScript(true);
181244
@flush();
182245
}
183246
foreach ($_GET['ct'] as $value) {
@@ -245,6 +308,9 @@ function cpu_pinning() {
245308
// remove old orphan image since it's no longer used by this container
246309
if ($oldImageID && $oldImageID != $newImageID) removeImage($oldImageID, $echo);
247310
}
311+
if ($echo) {
312+
dockerUIBlockerScript(false);
313+
}
248314
echo '<div style="text-align:center"><button type="button" onclick="window.parent.jQuery(\'#iframe-popup\').dialog(\'close\')">'._('Done').'</button></div><br>';
249315
goto END;
250316
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Only used for the UI blocker during long-running create/update operations */
2+
.docker-install-blocker {
3+
position: fixed;
4+
inset: 0;
5+
z-index: 2147483647;
6+
cursor: wait;
7+
}

0 commit comments

Comments
 (0)