2015-01-12 02:03:45 +01:00
class Loading
2018-02-22 23:34:18 +01:00
constructor: (@wrapper) ->
2015-01-12 02:03:45 +01:00
if window . show_loadingscreen then @ showScreen ( )
2016-08-10 12:27:37 +02:00
@timer_hide = null
2020-09-04 17:56:16 +02:00
@timer_set = null
2015-01-12 02:03:45 +01:00
2015-02-26 01:32:27 +01:00
setProgress: (percent) ->
2016-08-10 12:27:37 +02:00
if @ timer_hide
clearInterval @ timer_hide
2020-09-04 17:56:16 +02:00
@timer_set = RateLimit 500 , ->
2018-03-29 02:42:57 +02:00
$ ( " .progressbar " ) . css ( " transform " : " scaleX( #{ parseInt ( percent * 100 ) / 100 } ) " ) . css ( " opacity " , " 1 " ) . css ( " display " , " block " )
2015-02-26 01:32:27 +01:00
hideProgress: ->
2020-01-04 16:52:51 +01:00
@ log " hideProgress "
2020-09-04 17:56:16 +02:00
if @ timer_set
clearInterval @ timer_set
2016-08-10 12:27:37 +02:00
@timer_hide = setTimeout ( =>
2018-03-29 02:42:57 +02:00
$ ( " .progressbar " ) . css ( " transform " : " scaleX(1) " ) . css ( " opacity " , " 0 " ) . hideLater ( 1000 )
2016-08-10 12:27:37 +02:00
) , 300
2015-02-26 01:32:27 +01:00
2015-01-12 02:03:45 +01:00
showScreen: ->
$ ( " .loadingscreen " ) . css ( " display " , " block " ) . addClassLater ( " ready " )
@screen_visible = true
@ printLine " Connecting... "
2015-04-03 14:31:15 +02:00
showTooLarge: (site_info) ->
2020-01-04 16:52:51 +01:00
@ log " Displaying large site confirmation "
2015-04-03 14:31:15 +02:00
if $ ( " .console .button-setlimit " ) . length == 0 # Not displaying it yet
line = @ printLine ( " Site size: <b> #{ parseInt ( site_info . settings . size / 1024 / 1024 ) } MB</b> is larger than default allowed #{ parseInt ( site_info . size_limit ) } MB " , " warning " )
2016-11-18 20:07:26 +01:00
button = $ ( " <a href= ' # Set+limit ' class= ' button button-setlimit ' > " + " Open site and set size limit to #{ site_info . next_size_limit } MB " + " </a> " )
2018-02-22 23:34:18 +01:00
button . on " click " , =>
2018-04-28 22:05:38 +02:00
button . addClass ( " loading " )
2018-02-22 23:34:18 +01:00
return @ wrapper . setSizeLimit ( site_info . next_size_limit )
2015-04-03 14:31:15 +02:00
line . after ( button )
setTimeout ( =>
@ printLine ( ' Ready. ' )
) , 100
2018-04-28 22:05:38 +02:00
showTrackerTorBridge: (server_info) ->
if $ ( " .console .button-settrackerbridge " ) . length == 0 and not server_info . tor_use_meek_bridges
line = @ printLine ( " Tracker connection error detected. " , " error " )
button = $ ( " <a href= ' # Enable+Tor+bridges ' class= ' button button-settrackerbridge ' > " + " Use Tor meek bridges for tracker connections " + " </a> " )
button . on " click " , =>
button . addClass ( " loading " )
@ wrapper . ws . cmd " configSet " , [ " tor_use_bridges " , " " ]
@ wrapper . ws . cmd " configSet " , [ " trackers_proxy " , " tor " ]
2018-04-29 14:53:31 +02:00
@ wrapper . ws . cmd " siteUpdate " , { address: @ wrapper . site_info . address , announce: true }
2018-04-28 22:05:38 +02:00
@ wrapper . reloadIframe ( )
return false
line . after ( button )
if not server_info . tor_has_meek_bridges
button . addClass ( " disabled " )
@ printLine ( " No meek bridge support in your client, please <a href= ' https://github.com/HelloZeroNet/ZeroNet # how-to-join ' >download the latest bundle</a>. " , " warning " )
2015-01-12 02:03:45 +01:00
# We dont need loadingscreen anymore
hideScreen: ->
2020-01-04 16:52:51 +01:00
@ log " hideScreen "
2015-01-13 10:56:47 +01:00
if not $ ( " .loadingscreen " ) . hasClass ( " done " ) # Only if its not animating already
2015-01-13 00:29:40 +01:00
if @ screen_visible # Hide with animate
$ ( " .loadingscreen " ) . addClass ( " done " ) . removeLater ( 2000 )
else # Not visible, just remove
$ ( " .loadingscreen " ) . remove ( )
2015-01-12 02:03:45 +01:00
@screen_visible = false
# Append text to last line of loadingscreen
print: (text, type="normal") ->
if not @ screen_visible then return false
$ ( " .loadingscreen .console .cursor " ) . remove ( ) # Remove previous cursor
last_line = $ ( " .loadingscreen .console .console-line:last-child " )
if type == " error " then text = " <span class= ' console-error ' > #{ text } </span> "
last_line . html ( last_line . html ( ) + text )
# Add line to loading screen
printLine: (text, type="normal") ->
if not @ screen_visible then return false
$ ( " .loadingscreen .console .cursor " ) . remove ( ) # Remove previous cursor
if type == " error " then text = " <span class= ' console-error ' > #{ text } </span> " else text = text + " <span class= ' cursor ' > </span> "
2015-09-27 02:08:53 +02:00
2015-02-14 14:05:00 +01:00
line = $ ( " <div class= ' console-line ' > #{ text } </div> " ) . appendTo ( " .loadingscreen .console " )
if type == " warning " then line . addClass ( " console-warning " )
return line
2015-01-12 02:03:45 +01:00
2020-01-04 16:52:51 +01:00
log: (args...) ->
console . log " [Loading] " , args . . .
2015-01-12 02:03:45 +01:00
2018-02-22 23:34:18 +01:00
window . Loading = Loading