<commit_before>local sparkle = require 'sparkle'
local reporter = require 'sparkle/reporter'
local tasks = require 'sparkle/tasks'
local logging = require 'sparkle/logging'
local config = require 'sparkle/config'
local utils = require 'sparkle/utils'

function love.errhand(msg)
  reporter.log(msg)
end

function love.releaseerrhand(msg)
  reporter.log(msg)
end

local cmdargs = {}
local updater = nil
local downloading = false
local logo = nil
local message = ""
local time = 0
local updaterok = false
local progress = -1
local loaded = false
local logger = logging.new('foo')

local function reset()
  require "oldmain"

  love.load(cmdargs)

  updater = nil
  logo = nil
end

function love.load(arg)
  if loaded then return end

  local identity = ""

  if love.filesystem.getIdentity then
    identity = love.filesystem.getIdentity()
  end
    
  if config.identity and (identity == "" or identity == nil) then
    love.filesystem.setIdentity(config.identity)
  end

  love.graphics.setBackgroundColor(0, 0, 0)

  tasks.track('opens')

  cmdargs = arg
  message = ""
  time = 0
  progress = 0
  logo = love.graphics.newImage('sparkle/splash.png')


  updater = sparkle.newUpdater(arg, config.version, config.links.updates)
  updater:start()
  loaded = true
end

function love.update(dt)
  time = time + dt

  if updater and not updater:done() then
    local msg, percent, ok = updater:progress()

    if msg ~= "" then
      message = msg
      progress = (percent or 1) % 100
    end

    if msg == "Downloading" then
      downloading = true
    end

    return
  end

  if time < 2.5 then
    return
  end

  reset()
end

function love.draw()
  love.graphics.setColor(255, 255, 255, math.min(255, time * 200))

  local width = love.graphics.getWidth()
  local height = love.graphics.getHeight()

  if logo then
    love.graphics.draw(logo, width / 2 - logo:getWidth() / 2,
                       height / 2 - logo:getHeight() / 2)
  end

  if downloading then
    love.graphics.setColor(255, 255, 255)
    love.graphics.rectangle("line", 40, height - 75, width - 80, 10)
    love.graphics.rectangle("fill", 40, height - 75,  (width - 80) * progress / 100, 10)
    love.graphics.printf(message, 40, height - 55, width - 80, 'center')
  end
end
<commit_msg>Handle the case where the window hasn't been created yet<commit_after>local sparkle = require 'sparkle'
local reporter = require 'sparkle/reporter'
local tasks = require 'sparkle/tasks'
local logging = require 'sparkle/logging'
local config = require 'sparkle/config'
local utils = require 'sparkle/utils'

function love.errhand(msg)
  reporter.log(msg)
end

function love.releaseerrhand(msg)
  reporter.log(msg)
end

local cmdargs = {}
local updater = nil
local downloading = false
local logo = nil
local message = ""
local time = 0
local updaterok = false
local progress = -1
local loaded = false
local logger = logging.new('foo')

local function reset()
  require "oldmain"

  love.load(cmdargs)

  updater = nil
  logo = nil
end

function love.load(arg)
  if loaded then return end

  local identity = ""

  if love.filesystem.getIdentity then
    identity = love.filesystem.getIdentity()
  end
    
  if config.identity and (identity == "" or identity == nil) then
    love.filesystem.setIdentity(config.identity)
  end

  tasks.track('opens')

  cmdargs = arg
  message = ""
  time = 0
  progress = 0

  updater = sparkle.newUpdater(arg, config.version, config.links.updates)
  updater:start()
  loaded = true
end

function love.update(dt)
  time = time + dt

  if updater and not updater:done() then
    local msg, percent, ok = updater:progress()

    if msg ~= "" then
      message = msg
      progress = (percent or 1) % 100
    end

    if msg == "Downloading" then
      downloading = true
    end

    return
  end

  if time < 2.5 then
    return
  end

  reset()
end

function love.draw()
  if not logo then
    love.graphics.setBackgroundColor(0, 0, 0)
    logo = love.graphics.newImage('sparkle/splash.png')
  end

  love.graphics.setColor(255, 255, 255, math.min(255, time * 200))

  local width = love.graphics.getWidth()
  local height = love.graphics.getHeight()

  if logo then
    love.graphics.draw(logo, width / 2 - logo:getWidth() / 2,
                       height / 2 - logo:getHeight() / 2)
  end

  if downloading then
    love.graphics.setColor(255, 255, 255)
    love.graphics.rectangle("line", 40, height - 75, width - 80, 10)
    love.graphics.rectangle("fill", 40, height - 75,  (width - 80) * progress / 100, 10)
    love.graphics.printf(message, 40, height - 55, width - 80, 'center')
  end
end

{'fraction_non_alphanumeric': 0.11077257889009794, 'fraction_numerical': 0.028726877040261153, 'mean_word_length': 3.1405405405405404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7215439', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1463, 'n_words': 452}