1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 23:36:08 +03:00

Avoid force quit

This commit is contained in:
Tae Won Ha 2016-12-14 20:49:56 +01:00
parent f7c735950d
commit 3e369529b4
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 15 additions and 3 deletions

View File

@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface NeoVimAgent : NSObject
@property (nonatomic) bool useInteractiveZsh;
@property (readonly, atomic) bool neoVimIsQuitting;
@property (nonatomic, weak) id <NeoVimUiBridgeProtocol> bridge;
- (instancetype)initWithUuid:(NSString *)uuid;

View File

@ -111,6 +111,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return self;
}
- (bool)neoVimIsQuitting {
return _neoVimIsQuitting == 1;
}
// We cannot use -dealloc for this since -dealloc is not called until the run loop in the thread stops.
- (void)quit {
OSAtomicOr32Barrier(1, &_neoVimIsQuitting);
@ -407,9 +411,12 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
if (responseCode != kCFMessagePortSuccess) {
log_cfmachport_error(responseCode, msgid, data);
[_bridge ipcBecameInvalid:
[NSString stringWithFormat:@"Reason: sending msg to neovim failed for %d with %d", msgid, responseCode]
];
if (_neoVimIsQuitting == 0) {
[_bridge ipcBecameInvalid:
[NSString stringWithFormat:@"Reason: sending msg to neovim failed for %d with %d", msgid, responseCode]
];
}
return nil;
}

View File

@ -1441,6 +1441,10 @@ extension NeoVimView {
public func ipcBecameInvalid(_ reason: String) {
NSLog("ERROR \(#function): force-quitting")
DispatchUtils.gui {
if self.agent.neoVimIsQuitting {
return
}
self.delegate?.ipcBecameInvalid(reason: reason)
self.agent.quit()
}