Skip to content

Commit

Permalink
fixed lwfs.rb and loading.js to surely hard-reload on chrome.
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Jun 26, 2015
1 parent 829ec3d commit f0b4a17
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
44 changes: 32 additions & 12 deletions lwfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ def getLWFSConf(name)
end
end

HEAD_COMMON = <<-"EOF"
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT">
EOF
HEAD_COMMON.chomp!
HEAD_MOBILE = <<-"EOF"
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
EOF
HEAD_MOBILE.chomp!

configure do
set :port, 10080
set :public_folder, File.dirname(__FILE__) + '/htdocs'
Expand Down Expand Up @@ -320,7 +334,7 @@ def needUpdate?(src, dst)
path = File.join(settings.public_folder, path)
end
begin
if path =~ /\.(html|status)$/
if path =~ /\.(html|status|loading)$/
$mutex_p.synchronize do
begin
last_modified File.mtime(path)
Expand Down Expand Up @@ -403,10 +417,16 @@ def needUpdate?(src, dst)
$is_start = false
is_in_progress = true
exceptions = []
checkInterruptionWait = 0.0
while is_in_progress
catch :restart do
$mutex_p.synchronize do
updateLoadingStatus("#{DST_DIR}/", true)
end
checkInterruptionWait += 0.5
checkInterruptionWait = 3.0 if checkInterruptionWait > 3.0
t1 = Time.now
checkInterruption(__LINE__, 1.0)
checkInterruption(__LINE__, checkInterruptionWait)
t2 = Time.now
changes = {:vanishes => [], :updates => [], :unchanges => []}
begin
Expand Down Expand Up @@ -475,7 +495,7 @@ def checkInterruption(line, wait, is_end = false)
$mutex_i.synchronize do
if $is_interrupted
$is_interrupted = false
$log.info("restart at #{line}")
$log.info("restart at #{line} after waiting #{wait} sec.")
throw :restart
end
if is_end
Expand Down Expand Up @@ -728,6 +748,7 @@ def outputRaw(lwfsconf, update_time, folder)
<!DOCTYPE HTML>
<html>
<head>
#{HEAD_COMMON}
<meta http-equiv="refresh" content="0; URL=index.html?renderer=#{target}">
</head>
<body>
Expand Down Expand Up @@ -777,7 +798,8 @@ def outputOK(lwfsconf, update_time, folder, name, prefix, commandline)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
#{HEAD_COMMON}
#{HEAD_MOBILE}
<title>WARNINGS: #{name}</title>
<link rel="shortcut icon" href="#{relative}img/favicon-yellow.png" />
<link rel="icon" href="#{relative}img/favicon-yellow.png" />
Expand Down Expand Up @@ -899,8 +921,8 @@ def outputOK(lwfsconf, update_time, folder, name, prefix, commandline)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
#{HEAD_COMMON}
#{HEAD_MOBILE}
<title>LWF Loader: #{name}</title>
<link rel="shortcut icon" href="#{relative}img/#{favicon}" />
<link rel="icon" href="#{relative}img/#{favicon}" />
Expand Down Expand Up @@ -998,10 +1020,8 @@ def outputOK(lwfsconf, update_time, folder, name, prefix, commandline)
<!DOCTYPE HTML>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
#{HEAD_COMMON}
#{HEAD_MOBILE}
<title>#{target.upcase}: #{name}</title>
<link rel="shortcut icon" href="#{relative}img/#{favicon}" />
<link rel="icon" href="#{relative}img/#{favicon}" />
Expand Down Expand Up @@ -1093,7 +1113,7 @@ def outputNG(lwfsconf, update_time, folder, name, prefix, commandline, msg)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
#{HEAD_COMMON}
<title>ERROR: #{name}</title>
<link rel="shortcut icon" href="#{relative}img/favicon-red.png" />
<link rel="icon" href="#{relative}img/favicon-red.png" />
Expand Down Expand Up @@ -1237,7 +1257,7 @@ def updateTopIndex(update_time, mode = :default, exceptions = [])
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
#{HEAD_COMMON}
<title>lwfs</title>
<link rel="shortcut icon" href="../img/favicon.png" />
<link rel="icon" href="../img/favicon.png" />
Expand Down
20 changes: 15 additions & 5 deletions tmpl/js/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if (attr.name === "interval") {
INTERVAL = ~~Math.round(parseFloat(attr.value) * 1000);
} else if (attr.name === "update_time") {
UPDATE_TIME = attr.value;
UPDATE_TIME = parseFloat(attr.value);
}
}
}
Expand All @@ -34,25 +34,35 @@
var res = JSON.parse(xhr.responseText);
if (! res.is_in_conversion) {
if (res.update_time != UPDATE_TIME) {
var ut = res.update_time;
setTimeout(
function() {
window.location.reload();
// window.location.reload(true);
// window.location.href = href;
var href = window.location.href;
var search = window.location.search;
if (/[?&]\.=[.\d]+/.test(href)) {
href = href.replace(/([?&]\.=)[.\d]+/, '$1' + ut);
} else {
href = href.replace(/$/, ((search == '') ? '?' : '&') + '.=' + ut);
}
window.location.replace(href);
},
100);
50);
}
} else {
if (elm != null) {
elm.style.visibility = 'visible';
}
}
}
setTimeout(checkStatus, INTERVAL);
}
};
xhr.setRequestHeader('Pragma', 'no-cache');
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('If-Modified-Since', 'Thu, 01 Jun 1970 00:00:00 GMT');
setTimeout(checkStatus, INTERVAL);
xhr.send('');
xhr.send();
};
checkStatus();
},
Expand Down

0 comments on commit f0b4a17

Please sign in to comment.