Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
fix connection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
playsamay4 committed Nov 10, 2023
1 parent 681dab6 commit 6724d2d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 45 deletions.
89 changes: 53 additions & 36 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ ffi = require "ffi"
local extension = jit.os == "Windows" and "dll" or jit.os == "Linux" and "so" or jit.os == "OSX" and "dylib"
local timer = require "lib.timer"
local dllExists = love.filesystem.read("libraries/cimgui.dll")
local sock = require "lib.sock"
sock = require "lib.sock"
Inspect = require "lib.inspect"

local showDebug = false

Expand Down Expand Up @@ -73,40 +74,52 @@ local automationList = {
}}
}

local gearIcon = love.graphics.newImage("assets/gear.png")

Settings = require "modules.settings"

GFX = sock.newClient(Settings.data.ip, 10655)
GFX:connect()

local connectedToViz = false

showError = false
errorTitle = ""
errorMessage = ""


GFX:on("connect", function(data)
GFX:send("headline", {Type = "GetTickerText", Text = ffi.string(TickerControl.tickerText), DefaultText = ffi.string(TickerControl.defaultTickerText)})
connectedToViz = true
local gearIcon = love.graphics.newImage("assets/gear.png")

Settings = require "modules.settings"

GFX = sock.newClient(Settings.data.Connections.IP or "localhost", 10655)
local connectSuccess, connectError = pcall(function() GFX:connect() end)

if connectSuccess == false then
--temporarily set GFX to a dummy object so it doesn't error
GFX = {error = true, on = function() end, send = function() end, update = function() end, disconnect = function() end, connect = function() end}
showError = true
errorTitle = "Connection Error"
errorMessage = "Couldn't connect to Viz2.0: \n"..connectError
end

--This breaks figure out why \/\/\/

-- local sendData = {Type = "Set-Branding"}
-- sendData.channelName = brandingPresets[brandingPresetSelected].channelName
-- sendData.opaque = brandingPresets[brandingPresetSelected].opaque
-- sendData.coloredStrap = brandingPresets[brandingPresetSelected].coloredStrap
-- sendData.ThemeColor = brandingPresets[brandingPresetSelected].themeColor
-- sendData.mode = brandingPresets[brandingPresetSelected].mode
-- sendData.clockMode = brandingPresets[brandingPresetSelected].clockMode
-- GFX:send("headline", sendData)
function registerCallbacks()
GFX:on("connect", function(data)
GFX:send("headline", {Type = "GetTickerText", Text = ffi.string(TickerControl.tickerText), DefaultText = ffi.string(TickerControl.defaultTickerText)})
connectedToViz = true

end)
--This breaks figure out why \/\/\/

GFX:on("disconnect", function(data)
connectedToViz = false
end)
-- local sendData = {Type = "Set-Branding"}
-- sendData.channelName = brandingPresets[brandingPresetSelected].channelName
-- sendData.opaque = brandingPresets[brandingPresetSelected].opaque
-- sendData.coloredStrap = brandingPresets[brandingPresetSelected].coloredStrap
-- sendData.ThemeColor = brandingPresets[brandingPresetSelected].themeColor
-- sendData.mode = brandingPresets[brandingPresetSelected].mode
-- sendData.clockMode = brandingPresets[brandingPresetSelected].clockMode
-- GFX:send("headline", sendData)

end)

GFX:on("disconnect", function(data)
connectedToViz = false
end)
end
registerCallbacks()

function love.load()
imgui.love.Init() -- or imgui.love.Init("RGBA32") or imgui.love.Init("Alpha8")
Expand Down Expand Up @@ -325,25 +338,29 @@ function love.draw()
end
if imgui.Button(text) then
if connectedToViz == false then
GFX:connect()

GFX = sock.newClient(Settings.data.Connections.IP, 10655)

local connectSuccess, connectError = pcall(function() GFX:connect() end)

if connectSuccess == false then
--temporarily set GFX to a dummy object so it doesn't error
GFX = {error = true, on = function() end, send = function() end, update = function() end, disconnect = function() end, connect = function() end}
showError = true
errorTitle = "Connection Error"
errorMessage = "Couldn't connect to Viz2.0: \n"..connectError
end

registerCallbacks()

else
GFX:disconnect()
end
end
imgui.PopStyleColor()

imgui.SameLine()

if connectedToViz == false then imgui.BeginDisabled() end




if imgui.IsItemHovered() then
imgui.SetTooltip("Use only if VizHelper still thinks it's connected to Viz2.0 even when it's not")
end
if connectedToViz == false then imgui.EndDisabled() end


imgui.Separator()


Expand Down
28 changes: 19 additions & 9 deletions modules/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ local function SaveSettings(new)
if new == true then
settings.data = {
Connections = {
{
IP = "localhost",
}
IP = "localhost",
}
}
end
Expand Down Expand Up @@ -52,27 +50,39 @@ function LoadSettings()
settings.data = json:decode(settings.data)
end

windowItems.conIpInput = ffi.new("char[1024]", settings.data.Connections[1].IP)
windowItems.conIpInput = ffi.new("char[1024]", settings.data.Connections.IP)

end

LoadSettings()

local function connectionsWindow()
imgui.Text("IP Address: ") imgui.SameLine()
if imgui.InputText("###conIpInput", windowItems.conIpInput, 1024, imgui.love.InputTextFlags("EnterReturnsTrue")) == true then
if imgui.InputText("###conIpInput", windowItems.conIpInput, 1024) == true then
--disconnect from current connection
GFX:send("disconnect")
GFX:disconnect()
settings.data.Connections[1].IP = ffi.string(windowItems.conIpInput)
settings.data.Connections.IP = ffi.string(windowItems.conIpInput)
SaveSettings()
end

imgui.SameLine()


if connectedToViz == false then imgui.BeginDisabled() end

if imgui.Button("Force disconnect") then
GFX:disconnect()
connectedToViz = false
end
GFX:disconnect()
connectedToViz = false
end

if imgui.IsItemHovered() then
imgui.SetTooltip("Use only if VizHelper still thinks it's connected to Viz2.0 even when it's not")
end
if connectedToViz == false then imgui.EndDisabled() end




imgui.SameLine()
end
Expand Down

0 comments on commit 6724d2d

Please sign in to comment.