yousseb / meld

Meld for macOS
https://yousseb.github.io/meld/
GNU General Public License v2.0
2.28k stars 119 forks source link

Meld for Mac won't open if previously closed without using Menu::Quit #93

Closed alpiepho closed 4 years ago

alpiepho commented 4 years ago

The problem is related how the app is closed. If you use the Menu option, the saved state is removed cleaning. If you close using the window close (read circle) or ctrl-c from terminal, the saved state remains. Somehow, when this there, the application will not open from command line. Sometimes it will open, but you need to manually switch to the Meld application from the tool bar.

I found a work around that is described at https://gist.github.com/alpiepho/20f07bf5365bc2617fcf8594b9e4a7f2

I tried to pull this branch and build it so I could investigate a fix, but could follow the build instructions.

yousseb commented 4 years ago

Please check this build: https://github.com/yousseb/meld/releases/tag/osx-16

And let me know how it goes. This commit should hopefully fix at least the ctrl-c part: https://github.com/yousseb/meld/commit/dc6b82f781438e0e310eac9a3f1574e2b9699822

I'll try to follow what happens when Window-close is used.

Build instructions should be good now. Let me know what breaks for you during build.

dalboris commented 4 years ago

Hi, any news on this front?

One temporary workaround could also be to delete the file ~/Library/Saved Application\ State/org.gnome.meld.savedState when Meld is launched.

See: https://github.com/Homebrew/homebrew-cask/pull/69864

dalboris commented 4 years ago

(Note: I know that the suggestion above is probably not the cleanest solution, but given that it's been one year that this bug has been around, that it is affecting hundreds of users, and that it is still not fixed, my opinion is that a temporary fix right now would be very helpful, while we wait for a better and reliable fix to be found)

yousseb commented 4 years ago

Did you get a chance to test any of the preview builds that I created? I was hoping they fixed this issue.

On Sat, Sep 28, 2019 at 10:06 AM Boris Dalstein notifications@github.com wrote:

(Note: I know that the suggestion above is probably not the cleanest solution, but given that it's been one year that this bug has been around, that it is affecting hundreds of users, and that it is still not fixed, my opinion is that a temporary fix right now would be very helpful, while we wait for a better and reliable fix to be found)

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/yousseb/meld/issues/93?email_source=notifications&email_token=ABEAHCWFDGJRCSHPN4C342TQL6FIZA5CNFSM4IUTUB72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD726CJA#issuecomment-536207652, or mute the thread https://github.com/notifications/unsubscribe-auth/ABEAHCRMEDTAXNV5UMMAXFLQL6FIZANCNFSM4IUTUB7Q .

gibfahn commented 4 years ago

Did you get a chance to test any of the preview builds that I created? I

I tried https://github.com/yousseb/meld/releases/tag/osx-16 but I see the same behaviour as with the latest homebrew version:

# Check it hangs with existing Meld.app
/Applications/Meld.app/Contents/MacOS/Meld ~/tmp/old ~/tmp/new

# Clean up so we start at a known good state
rm -rf ~/Library/Saved\ Application\ State/org.gnome.meld.savedState

# Use osx-16 release
~/tmp/Meld.app/Contents/MacOS/Meld ~/tmp/old ~/tmp/new

# This runs fine, Ctrl-c it

# Try the osx-16 release
~/tmp/Meld.app/Contents/MacOS/Meld ~/tmp/old ~/tmp/new

# This time it hangs...
yousseb commented 4 years ago

Perfect issue report. Thank you. I'll try to figure it out. The sad part is that this is likely either glib or gtk/Mac issue, not Meld itself. I'll see if I can work around it.

On Tue, Oct 1, 2019 at 4:09 AM Gibson Fahnestock notifications@github.com wrote:

Did you get a chance to test any of the preview builds that I created? I

I tried https://github.com/yousseb/meld/releases/tag/osx-16 but I see the same behaviour as with the latest homebrew version:

Check it hangs with existing Meld.app

/Applications/Meld.app/Contents/MacOS/Meld ~/tmp/old ~/tmp/new

Clean up so we start at a known good state

rm -rf ~/Library/Saved\ Application\ State/org.gnome.meld.savedState

Use osx-16 release~/tmp/Meld.app/Contents/MacOS/Meld ~/tmp/old ~/tmp/new

This runs fine, Ctrl-c it

Try the osx-16 release~/tmp/Meld.app/Contents/MacOS/Meld ~/tmp/old ~/tmp/new

This time it hangs...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yousseb/meld/issues/93?email_source=notifications&email_token=ABEAHCXRA4KQA5WY4WCD6O3QMMVU5A5CNFSM4IUTUB72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAA4M2A#issuecomment-536987240, or mute the thread https://github.com/notifications/unsubscribe-auth/ABEAHCSXE7YN7O4HLUKESIDQMMVU5ANCNFSM4IUTUB7Q .

gibfahn commented 4 years ago

Perfect issue report. Thank you. I'll try to figure it out.

Least I can do :). Let me know if there's anything else that might help debug.

I'll see if I can work around it.

Would just cleaning up that file on startup be an option or is it too late by the time Meld starts?

dalboris commented 4 years ago

Hi everyone! Sorry for not replying earlier. I have just tried Meld osx-16, and I can 100% reproduce the behaviour reported by @gibfahn.

However, note that for some reason, I can't reproduce the hanging behaviour when using the close button instead of Ctrl+C. Neither with osx-16, nor with the latest homebrew version (3.19.2-r6,osx-15). I don't think I've ever pressed Ctrl+C explicitly when I first experienced the issue, but maybe it didn't close correctly for some other reasons.

A few other remarks:

Thanks for you work on this issue!

dsbecker commented 4 years ago

I've found that if you close the compare/merge tab first, THEN close the app. It exits cleanly then.

yousseb commented 4 years ago

I tried many things to figure this out and I still can't.

If you have any idea how to stop macOS from loading/saving application state, I would be grateful if you can point me to it. I tried the following, but they don't seem to work:

  1. 'NSQuitAlwaysKeepsWindows': False,
    'ApplePersistenceIgnoreState': True
  2. https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623089-application?language=objc
  3. https://developer.apple.com/documentation/appkit/nswindow/1526239-disablesnapshotrestoration?language=objc

Any thoughts?

dalboris commented 4 years ago

@yousseb Have you tried, at the very beginning of the main() function, to delete the ~/Library/Saved Application State/org.gnome.meld.savedState folder?

yousseb commented 4 years ago

@dalboris That was the first thing I tried actually.

It seems to be something that either macOS or Gtk does before it even reaches the main of the Python app. My bet is on macOS doing this and Gtk not playing nicely with it. The links above were my experiments inside Gtk/quartz, but that still didn't work.

I'll try to do that in the py2app main, but my guess is that it won't work either. I'll try that one.

yousseb commented 4 years ago

@dalboris So... Adding the following:

import os
import shutil
home_dir = os.path.expanduser('~')
if home_dir is not None:
    saved_state_dir = os.path.join(home_dir, 'Library', 'Saved Application State', 'org.gnome.meld.savedState')
    if os.path.isdir(saved_state_dir):
        try:
            shutil.rmtree(saved_state_dir, ignore_errors=1)
        except:
            pass

Right before _argv_emulation() in argv_emulation.py (in py2app site-package folder) - which gets injected in the __boot__.py file that you'll find the final dmg - fixes this issue. Not the best thing to do, but I guess it's a feasible workaround for now. I'll have to modify the build script so that it patches the final __boot__.py.

Just giving news that the next build will have this fix - hopefully sometime this week.

dalboris commented 4 years ago

@yousseb Thanks for your work, let's hope that this works (I'm not familiar with py2app at all, and I rarely use macOS). I'll try to think about testing this fix next week when it's released. Feel free to ping me if I forget.

yousseb commented 4 years ago

@dalboris done. Please verify and let's close this one once and for all.

dalboris commented 4 years ago

Thanks @yousseb, I can confirm that this seems fixed :-) I could reproduce the bug with the osx-18 release, but not with the osx-19 release.

alpiepho commented 4 years ago

I am not at point I can test it, but I did review the code. Looks good.
Thanks for taking care of this.