diff --git a/lwfs.rb b/lwfs.rb index 04c81a4..2e13271 100644 --- a/lwfs.rb +++ b/lwfs.rb @@ -159,6 +159,20 @@ def getLWFSConf(name) end end +HEAD_COMMON = <<-"EOF" + + + + +EOF +HEAD_COMMON.chomp! +HEAD_MOBILE = <<-"EOF" + + + +EOF +HEAD_MOBILE.chomp! + configure do set :port, 10080 set :public_folder, File.dirname(__FILE__) + '/htdocs' @@ -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) @@ -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 @@ -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 @@ -728,6 +748,7 @@ def outputRaw(lwfsconf, update_time, folder) +#{HEAD_COMMON} @@ -777,7 +798,8 @@ def outputOK(lwfsconf, update_time, folder, name, prefix, commandline) - +#{HEAD_COMMON} +#{HEAD_MOBILE} WARNINGS: #{name} @@ -899,8 +921,8 @@ def outputOK(lwfsconf, update_time, folder, name, prefix, commandline) - - +#{HEAD_COMMON} +#{HEAD_MOBILE} LWF Loader: #{name} @@ -998,10 +1020,8 @@ def outputOK(lwfsconf, update_time, folder, name, prefix, commandline) - - - - +#{HEAD_COMMON} +#{HEAD_MOBILE} #{target.upcase}: #{name} @@ -1093,7 +1113,7 @@ def outputNG(lwfsconf, update_time, folder, name, prefix, commandline, msg) - +#{HEAD_COMMON} ERROR: #{name} @@ -1237,7 +1257,7 @@ def updateTopIndex(update_time, mode = :default, exceptions = []) - +#{HEAD_COMMON} lwfs diff --git a/tmpl/js/loading.js b/tmpl/js/loading.js index a241642..848471a 100644 --- a/tmpl/js/loading.js +++ b/tmpl/js/loading.js @@ -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); } } } @@ -34,11 +34,21 @@ 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) { @@ -46,13 +56,13 @@ } } } + 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(); },