@@ -189,7 +189,7 @@ bool InvokeBindEvent::isDown() const {
189189 return m_down;
190190}
191191
192- ListenerResult InvokeBindFilter::handle (utils::MiniFunction <Callback> fn, InvokeBindEvent* event) {
192+ ListenerResult InvokeBindFilter::handle (std::function <Callback> fn, InvokeBindEvent* event) {
193193 if (event->getID () == m_id) {
194194 return fn (event);
195195 }
@@ -211,7 +211,7 @@ bool PressBindEvent::isDown() const {
211211 return m_down;
212212}
213213
214- geode::ListenerResult PressBindFilter::handle (MiniFunction <Callback> fn, PressBindEvent* event) {
214+ geode::ListenerResult PressBindFilter::handle (std::function <Callback> fn, PressBindEvent* event) {
215215 return fn (event);
216216}
217217
@@ -232,7 +232,7 @@ bool DeviceEvent::wasDetached() const {
232232 return !m_attached;
233233}
234234
235- ListenerResult DeviceFilter::handle (MiniFunction <Callback> fn, DeviceEvent* event) {
235+ ListenerResult DeviceFilter::handle (std::function <Callback> fn, DeviceEvent* event) {
236236 if (!m_id || m_id == event->getID ()) {
237237 fn (event);
238238 }
@@ -309,7 +309,10 @@ matjson::Value BindManager::saveBind(Bind* bind) const {
309309
310310Bind* BindManager::loadBind (matjson::Value const & json) const {
311311 try {
312- auto device = json[" device" ].as_string ();
312+ auto res = json[" device" ].asString ();
313+ if (!res)
314+ return nullptr ;
315+ auto device = res.unwrap ();
313316 if (!m_devices.contains (device)) {
314317 return nullptr ;
315318 }
@@ -321,9 +324,9 @@ Bind* BindManager::loadBind(matjson::Value const& json) const {
321324}
322325
323326bool BindManager::loadActionBinds (ActionID const & action) {
324- try {
325- auto value = Mod::get ()->template getSavedValue <matjson::Object >(action);
326- for (auto bind : value[" binds" ]. as_array () ) {
327+ auto inner = [&]() -> Result<> {
328+ auto value = Mod::get ()->getSavedValue <matjson::Value >(action);
329+ for (auto bind : value[" binds" ]) {
327330 // try directly parsing the bind from a string if the device it's for
328331 // is already connected
329332 if (auto b = this ->loadBind (bind)) {
@@ -334,9 +337,9 @@ bool BindManager::loadActionBinds(ActionID const& action) {
334337 else {
335338 // if device ID exists, then add this to the list of unbound
336339 // binds
337- if (bind.contains (" device" )) {
340+ if (bind.contains (" device" ) && bind[ " device " ]. isString () ) {
338341 try {
339- m_devicelessBinds[bind[" device" ].as_string ()][action].insert (bind);
342+ m_devicelessBinds[bind[" device" ].asString (). unwrap ()][action].insert (bind);
340343 }
341344 catch (...) {}
342345 }
@@ -345,36 +348,34 @@ bool BindManager::loadActionBinds(ActionID const& action) {
345348 }
346349 // load repeat options
347350 if (value.contains (" repeat" )) {
348- auto rep = value[" repeat" ]. as_object () ;
351+ auto rep = value[" repeat" ];
349352 auto opts = RepeatOptions ();
350- opts.enabled = rep[" enabled" ].as_bool ( );
351- opts.rate = rep[" rate" ].as_int ( );
352- opts.delay = rep[" delay" ].as_int ( );
353+ GEODE_UNWRAP_INTO ( opts.enabled , rep[" enabled" ].asBool () );
354+ GEODE_UNWRAP_INTO ( opts.rate , rep[" rate" ].asInt () );
355+ GEODE_UNWRAP_INTO ( opts.delay , rep[" delay" ].asInt () );
353356 this ->setRepeatOptionsFor (action, opts);
354357 }
355- return true ;
356- }
357- catch (...) {
358- return false ;
359- }
358+ return Ok ();
359+ };
360+ return inner ().isOk ();
360361}
361362
362363void BindManager::saveActionBinds (ActionID const & action) {
363- auto obj = matjson::Object ();
364- auto binds = matjson::Array ();
364+ auto obj = matjson::Value::object ();
365+ auto binds = matjson::Value::array ();
365366 for (auto & bind : this ->getBindsFor (action)) {
366- binds.push_back (this ->saveBind (bind));
367+ binds.push (this ->saveBind (bind));
367368 }
368369 for (auto & [device, actions] : m_devicelessBinds) {
369370 if (actions.contains (action)) {
370371 for (auto & bind : actions.at (action)) {
371- binds.push_back (bind);
372+ binds.push (bind);
372373 }
373374 }
374375 }
375376 obj[" binds" ] = binds;
376377 if (auto opts = this ->getRepeatOptionsFor (action)) {
377- auto rep = matjson::Object ();
378+ auto rep = matjson::Value::object ();
378379 rep[" enabled" ] = opts.value ().enabled ;
379380 rep[" rate" ] = opts.value ().rate ;
380381 rep[" delay" ] = opts.value ().delay ;
0 commit comments