Skip to content

Commit

Permalink
Try to find opened shell first
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Oct 11, 2017
1 parent 3d78d39 commit e68c92b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Blink/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>com.blink.cmdline</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down
30 changes: 29 additions & 1 deletion Blink/SpaceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,35 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender

- (void)restoreUserActivityState:(NSUserActivity *)activity
{
[self _createShellWithUserActivity:activity animated:YES completion:nil];
[super restoreUserActivityState:activity];

NSInteger idx = [_viewports indexOfObject:self.currentTerm];
if(idx == NSNotFound) {
[self _createShellWithUserActivity:activity animated:YES completion:nil];
return;
}

NSInteger targetIdx = [_viewports indexOfObjectPassingTest:^BOOL(TermController *term, NSUInteger idx, BOOL * _Nonnull stop) {
return [activity.title isEqualToString:term.activityKey];
}];

if (targetIdx == NSNotFound) {
[self _createShellWithUserActivity:activity animated:YES completion:nil];
return;
}

// we are already here
if (idx == targetIdx) {
return;
}

UIPageViewControllerNavigationDirection direction =
idx < targetIdx ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;


[self switchShellIdx: targetIdx
direction: direction
animated: NO];
}


Expand Down
1 change: 1 addition & 0 deletions Blink/TermController.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@property (strong, nonatomic) TermView *terminal;
@property (strong, nonatomic) UIScrollView *containerView;
@property (weak) id<TermControlDelegate> delegate;
@property (strong, nonatomic) NSString* activityKey;

- (void)setRawMode:(BOOL)raw;
- (BOOL)rawMode;
Expand Down
7 changes: 6 additions & 1 deletion Blink/TermController.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ - (void)indexCommand:(NSString *)cmdLine {
activity.eligibleForSearch = YES;
activity.eligibleForHandoff = YES;

[activity setTitle:[NSString stringWithFormat:@"run: %@ ", cmdLine]];

_activityKey = [NSString stringWithFormat:@"run: %@ ", cmdLine];
[activity setTitle:_activityKey];

_activityUserInfo = @{BKUserActivityCommandLineKey: cmdLine ?: @"help"};

activity.userInfo = _activityUserInfo;

self.userActivity = activity;
Expand All @@ -193,8 +196,10 @@ - (void)indexCommand:(NSString *)cmdLine {

- (void)updateUserActivityState:(NSUserActivity *)activity
{
[activity setTitle:_activityKey];
[activity addUserInfoEntriesFromDictionary:_activityUserInfo];
activity.keywords = [NSSet setWithArray:@[@"blink", @"shell", @"mosh", @"ssh", @"terminal", @"remote"]];

[activity setRequiredUserInfoKeys:[NSSet setWithArray:_activityUserInfo.allKeys]];
}

Expand Down

0 comments on commit e68c92b

Please sign in to comment.