Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Mac Mouse Fix not working [bug] #117

Closed
maddn opened this issue Jun 3, 2021 · 14 comments
Closed

Enable Mac Mouse Fix not working [bug] #117

maddn opened this issue Jun 3, 2021 · 14 comments

Comments

@maddn
Copy link

maddn commented Jun 3, 2021

Description

In the latest beta version (2.0.0 Beta 9), I'm unable to check the Enable Mac Mouse Fix button.
In the release version (1.0.4), I can check the Enable Mac Mouse Fix button but it doesn't do anything, and the next time I open the app it's unchecked again.

Context

Mac Mouse Fix Version: 2.0.0 Beta 9
macOS Version: 11.4

Console Logs

I see this error in the console log:
No legacy launchd plist file found at: /Users/mmaddern/Library/LaunchAgents/com.nuebling.mousefix.helper.plist

@noah-nuebling
Copy link
Owner

noah-nuebling commented Jun 3, 2021

Hey @maddn, thanks for reaching out!

Your bug has been occurring for a few people, but I can't seem to reproduce it, unfortunately.
However from what I understand, enabling might work again after you do this:

  1. Open Terminal.app
  2. Copy-paste this command and execute it by pressing the Enter key
launchctl remove mouse.fix.helper
  1. Restart Mac Mouse Fix

Let me know if that helps when you have time, because that'll really help fix the issue for everyone.

@maddn
Copy link
Author

maddn commented Jun 3, 2021

Hi, unfortunately that didn't work. Still have the same problem after running that command and restarting the app. I'm happy to try any other suggestions you have though!

Thanks!

@noah-nuebling
Copy link
Owner

Oh that's unfortunate,

If you're interested and have time, I could describe to you how things work so you could do your own investigations, but that would probably be quite time consuming and a little overwhelming if you don't have experience debugging apps, yet.

I'll hopefully have the opportunity to do some debugging on my dads computer soon. He had that problem, too, when he installed the 2.0.0 Beta a few weeks ago.
1.0.4 also stopped working for him afterwards if I recall correctly.
1.0.4 started working again for him later, but I'm not sure how. I'll ask him about it and get back to you if I find out more.

Thanks again for reaching out, and for your willingness to help out! Any info or help fixing this gnarly bug is appreciated.

@maddn
Copy link
Author

maddn commented Jun 3, 2021

Hi, I'm happy to do some investigation, but I don't know where to start really, so if you can point me in the right direction that would be great. Thanks!

@noah-nuebling
Copy link
Owner

Alright, cool! I'll try to give you and overview.

First off some basic concepts / terminology

  • Enable checkbox → The checkbox in the top left of the Mac Mouse Fix UI saying "Enable Mac Mouse Fix"
  • The main app → It's the app you've been interacting with. Its app bundle name is "Mac Mouse Fix".
  • The helper or helper app → It's hidden background app, that is embedded in the "main app". It runs while the enable checkbox is checked. It's what actually changes the behaviour of your mouse. It's app bundle name is "Mac Mouse Fix Helper".

My thoughts about the issue and how I arrived at them

I put all my assumptions that I'm not sure about, and that we would be useful to confirm or disprove in a

  • Bullet point

All that the enable checkbox really does is it starts / stops the helper app.

Starting from I think 2.0.0 Beta 10, once the helper has started up, it will send an "I'm running" message to the main app. That message will then cause the enable checkbox to be checked.

In previous versions, the enable checkbox would get checked as soon as you clicked it, and not only when the "I'm running" message was sent, if I recall correctly.

So because in your testing, you couldn't check the enable checkbox that seems to suggest, that

  • The 2.0.0 version that you were running was in fact Beta 10 and not Beta 9.

If that's true, and you were running Beta 10, then this leads me to think that:

  • The reason why you couldn't check the enable checkbox, is that the helper fails to send the "I'm running" message, that it normally sends after starting up.
    Which means that
    Either
  • The helper is not started at all
    Or
  • The helper does start up, but right afterwards, it crashes or freezes or something else happens that prevents it from sending the "I'm running" message
    There could also be other reasons, e.g. maybe the "I'm running" message is sent but it doesn't arrive. But to me these feel like the most likely explanations.

I also think that

  • The problem you have with 1.0.4 and the 2.0.0 Beta are probably the exact same
    I think that because, the mechanism, where the enable checkbox only gets checked once the helper sends an "I'm running" message, was only introduced in Beta 10. In older versions like 1.0.4, the checkbox would get checked as soon as you clicked it, no matter if the helper actually started up successfully or not. So that would explain the different behaviour of the enabled checkbox you noted between 1.0.4 and 2.0.0, even if the underlying problem is the exact same. So I would go with the simplest explanation, and assume that the the problem is the exact same between the two versions you tested, because there is nothing to suggest otherwise.

And if that's true, and also because the issue seems to always first occur after installing 2.0.0, it's probably best to analyze 2.0.0 first.

How to analyze what's going wrong

The easiest thing you could do to find out more about what is going on, is probably by having a look at the Console:

  • Open Mac Mouse Fix
  • Uncheck the enable checkbox
  • Open Console.app
  • Check "Action → Include Info Messages" and "Action → Include Debug Messages"
  • Filter for "Mac Mouse Fix" by typing in the search bar in the top right
    • It might be better if you filter for "Mac Mouse Fix Helper" instead. That way, you will only see messages related to the helper and exclude messages related to the main app, which might be irrelevant to the issue, and will only clutter up the Console, making things harder to parse for you.
    • Note that you can clear the console output with ⌘K, and you can copy paste messages to easily share them
  • Check the enable checkbox and see what messages appear in the Console
    • This should give you an idea of what is happening internally when you click the enable checkbox
    • You could also copy-paste the messages and send them to me, if you want to. It'll probably be easier for me to make sense of it since I wrote these messages and the code that produces them.
    • Some more things you could check at this point beyond Console output:
      • Run the command launchctl list mouse.fix.helper If the "LastExitStatus" value is not 0, that could be a hint as to what's happening.
      • Open Activity Monitor.app and see if the "Mac Mouse Fix Helper" process shows up.

The next thing you could do is debugging Mac Mouse Fix Helper using Xcode

  • Download Xcode from the App Store
  • Download the source code for MMF 2.0.0 from the Github repo > branch "feature-remap"
  • Now you're gonna have to set up some things
    1. Set up signing in Xcode so you can build the app bundles
      • Make sure the Project Navigator is open (⌘1), then go to Mouse Fix (in the top left with the blue logo) → Signing & Capabilities → Mac Mouse Fix and configure the signing.
        • Then also configure the signing for the other 2 targets at Mouse Fix → Signing & Capabilities → Mac Mouse Fix Helper and Mouse Fix → Signing & Capabilities → Mac Mouse Fix Accomplice
      • image
    2. Set up the "Helper" build scheme.
      • A build scheme lets you build, run and debug an app
      • You select a build scheme, by clicking here
        image
      • And you can then run the selected build scheme by clicking the play button to the left
      • You want to run and debug the helper. There's a build scheme for that already called "Helper", but it won't work out of the box.
        • Why won't it work out of the box? - The helper needs to be embedded in the main app to run properly. So in the "Helper" build scheme we tell Xcode to compile the whole main app, which has the helper embedded within it, and then we tell it to run and debug the helper which was just built and embedded in the main app. The folder where Xcode builds the main app is different on your computer than mine, so the the path to the embedded helper which I specified won't work for you
        • How to make it work:
          • Build the main app by running the "App" build scheme
          • Reveal the built main app in Finder by going to Project Navigator → Products → Right click "Mac Mouse Fix.app" → Click "Show in Finder"
          • Find the embedded helper at Right click "Mac Mouse Fix" → Show Package Contents → Contents → Library → LoginItems → Mac Mouse Fix Helper
          • Go back to Xcode and select the "Helper" build scheme
          • Open the scheme selection menu again and click "Edit Scheme..."
          • Click the popup button at Run → Info → Executable and choose "Other..." image
          • A file selection dialog will pop up. Select the embedded helper by going to the Finder window you opened before and then dragging-and-dropping the embedded helper from Finder into the file selection dialog. Then click the "Choose" button in the bottom right.
          • Congrats, you did it! If I didn't forget anything, you can now run and debug the helper by running the "Helper" build scheme.

So now you can set breakpoints and properly debug the app. First thing you want to do is probably add an exception breakpoint at Breakpoint Navigator (⌘8) → + → Exception Breakpoint...

If you want more info on how to debug the helper and which parts of the app to look into to track down your issue, just let me know.

If the helper turns out to work just fine, when you run the "Helper" build scheme, then, probably, the issue is not in the helper itself, but in the mechanism that we use to start the helper after the user clicks the enable checkbox. If that's the case just let me know and I'll give you more info on how that works and how to investigate it.

I hope this helps - thank you for helping! :) - and if you're overwhelmed by this or don't have time to get into it, then I totally understand that of course.
I hope this wasn't too verbose or confusing, and if you have any more questions of if you could use another explanation of anything I described, just let me know.

@maddn
Copy link
Author

maddn commented Jun 3, 2021

Hi, thanks for all the detailed steps. It will take a little while for me to download and setup Xcode.

You're right I was using beta 10, not beta 9.

There are no entries in the console log when I filter for "Mac Mouse Fix Helper", but there are entries for "Mac Mouse Fix".

I get the following error when running launchctl command:

launchctl list mouse.fix.helper
Could not find service "mouse.fix.helper" in domain for port

I also noticed there is no folder in ~/Library/LaunchAgents for the app, so maybe it didn't install properly?

@noah-nuebling
Copy link
Owner

noah-nuebling commented Jun 4, 2021

Hey thanks for getting back! That's really useful information.

So the helper doesn't seem to start in the first place.
Which would mean, that the problem doesn't lie with the helper itself, but instead with the mechanism we use to start it.

I'll detail the mechanism for starting the helper here so we're on the same page:

How enabling the helper really works

What the enable checkbox really does is, it doesn't start the helper directly, but instead it tells a system process called launchd to run the helper. It does so like this

  1. It creates a file at ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist which contains the helpers executable path and some options that tell launchd how and under which circumstances to run it. This file is also called the launchd.plist.
  2. It then executes the command launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist to make launchd load the launchd.plist it just created. Upon loading the launchd.plist, launchd will then immediately start up the helper and keep it running in the background.

What the list command really does

When you execute launchctl list mouse.fix.helper, it basically tells you what launchd knows and thinks about the helper. I'm spotty on the exact concepts here but you get the gist.
The list command usually outputs Could not find service "mouse.fix.helper" in domain for port when the launchd.plist is not loaded, and when, therefore, launchd doesn't know anything about the helper.

It makes sense that it's not loaded since the launchd.plist doesn't exist on your system as you said.

How I interpret your findings

So that seems to be where things are going wrong - when creating the launchd.plist

What to debug

Knowing that, the most interesting parts of the program to debug are probably

  • Mac Mouse Fix Project Root → Shared → HelperServices → HelperServices.m → enableHelperAsUserAgent:
  • Mac Mouse Fix Project Root → Shared → HelperServices → HelperServices.m → repairLaunchdPlist:

How to Analyze the problem without a debugger

Alternatively, it would probably also be really insightful, if you set up and loaded the launchd.plist manually to see how / if that works:

  1. Find a launchd.plist template at Mac Mouse Fix Project Root → Shared → HelperServices → default_launchd.plist
  2. Copy-paste this file to ~/Library/LaunchAgents and rename it to com.nuebling.mac-mouse-fix.helper.plist (The name doesn't really matter but like this you can easily copy-paste the commands below)
  3. Find the executable path of the helper app on your system and copy it. Then open the launchd.plist template and replace the text that says "((insert path to mouse remap helper executable here))" with the executable path.
    • If you have MMF in the Applications Folder, then the helper executable path is /Applications/Mac Mouse Fix.app/Contents/Library/LoginItems/Mac Mouse Fix Helper.app/Contents/MacOS/Mac Mouse Fix Helper
    • In Finder, you can copy a file-path using Command-Option-C

You did it! Now you can use the launchd.plist file you just created like so:

  • To load the launchd.plist use launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist
    • Alternatively you could try
      • launchctl load ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist
  • To unload the launchd.plist use launchctl bootout gui/$UID ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist
    • Alternatively you could try
      • `launchctl unload ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist``
      • launchctl remove mouse.fix.helper

Then you could take a look at these things to get a better idea of what's going on:

  • Terminal output from running the loading and unloading commands above
  • Output for launchctl list mouse.fix.helper
  • Console, to see any error messages related to "launchd" and "Mac Mouse Fix Helper"
  • Maybe Activity Monitor, to see if the Helper is running
  • Maybe other stuff I can't think of

@maddn
Copy link
Author

maddn commented Jun 4, 2021

Hi,

Thanks for the help with this. I found the problem was that my LaunchAgents folder was owned by root. I don't know how this happened. But once I changed the ownership back to my user, it works okay now.

What was strange was that there was no error in the log to say the app didn't have permission to create the plist file. Looking at the code, I'd expect to see the error:

repairUserAgentConfigFile() -- Data Serialization Error

Let me know if you want me to try anything else.

@noah-nuebling
Copy link
Owner

noah-nuebling commented Jun 7, 2021

I’m glad that’s sorted out.
You’re right, a log like that would have made everything much easier. I’ll look into improving the error logging around creating the launchd.plist file.

Thanks for your help!

@RandyZ
Copy link

RandyZ commented Aug 14, 2022

Hi, i have the same problem. log is

2022-08-14 15:28:16.606 Mac Mouse Fix[22486:501710] Sending message: checkAccessibility with payload: (null) from bundle: com.nuebling.mac-mouse-fix via message port
2022-08-14 15:28:16.606 Mac Mouse Fix[22486:501710] Can't send message, because there is no CFMessagePort
2022-08-14 15:28:17.107 Mac Mouse Fix[22486:501710] Removing AuthorizeAccessibilityView
2022-08-14 15:28:19.640 Mac Mouse Fix[22486:501710] Sending message: checkAccessibility with payload: (null) from bundle: com.nuebling.mac-mouse-fix via message port
2022-08-14 15:28:19.640 Mac Mouse Fix[22486:501710] Can't send message, because there is no CFMessagePort
2022-08-14 15:28:19.799 Mac Mouse Fix[22486:501710] Repairing User Agent Config File
2022-08-14 15:28:19.800 Mac Mouse Fix[22486:501710] launchdPlistExists 1, launchdPlistIsCorrect: 1
2022-08-14 15:28:19.800 Mac Mouse Fix[22486:501710] Nothing to repair
2022-08-14 15:28:19.800 Mac Mouse Fix[22486:501710] Cleaning up stuff from previous versions
Could not find service "mouse.fix.helper" in domain for port
2022-08-14 15:28:19.805 Mac Mouse Fix[22486:501710] Strange Helper: not found
2022-08-14 15:28:19.805 Mac Mouse Fix[22486:501710] Removing legacy launchd plist
2022-08-14 15:28:19.805 Mac Mouse Fix[22486:501710] No legacy launchd plist file found at: /Users/randy/Library/LaunchAgents/com.nuebling.mousefix.helper.plist
2022-08-14 15:28:19.805 Mac Mouse Fix[22486:501710] Removing Helper from launchd
2022-08-14 15:28:19.809 Mac Mouse Fix[22486:501710] Terminating other Helper instances
2022-08-14 15:28:19.810 Mac Mouse Fix[22486:501710] 0 other running Helper instances found
2022-08-14 15:28:19.813 Mac Mouse Fix[22486:505968] launchctl terminated with stdout/stderr: Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
, error: (null)
2022-08-14 15:28:20.141 Mac Mouse Fix[22486:501710] Removing AuthorizeAccessibilityView

My LaunchAgents folder's permission is owned to me. Need a help

@RandyZ
Copy link

RandyZ commented Aug 14, 2022

Oh, by the way, app version 2.2.0

@noah-nuebling
Copy link
Owner

Hey @RandyZ!

Something you could try is to open Terminal and run the command sudo launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist . This might tell us more about what's going on.

The command launchctl list mouse.fix.helper might also be interesting.

@RandyZ
Copy link

RandyZ commented Aug 15, 2022

Hey @RandyZ!

Something you could try is to open Terminal and run the command sudo launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.nuebling.mac-mouse-fix.helper.plist . This might tell us more about what's going on.

The command launchctl list mouse.fix.helper might also be interesting.

I restart my mac. Works. Maybe the helper service didn't start properly.

@noah-nuebling
Copy link
Owner

Great! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants