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

Notifications for new devices and folders #54

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/xcode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# XCode tips and tricks

## xcodebuild requires Xcode

```
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
```

fixed with

```
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
```
170 changes: 3 additions & 167 deletions syncthing.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

116 changes: 0 additions & 116 deletions syncthing/Controllers/STPreferencesWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#import "STPreferencesWindowController.h"
#import "STPreferencesGeneralViewController.h"
#import "STPreferencesFoldersViewController.h"
#import "STPreferencesInfoViewController.h"
#import "STPreferencesDevicesViewController.h"
#import "STPreferencesAdvancedViewController.h"

@interface STPreferencesWindowController ()
Expand All @@ -22,9 +19,6 @@ @implementation STPreferencesWindowController
enum
{
kGeneralView = 0,
kFoldersView,
kDevicesView,
kInfoView,
kAdvancedView
};

Expand All @@ -51,21 +45,6 @@ - (void) setViewFromId:(NSInteger) tag {
_generalView = [[STPreferencesGeneralViewController alloc] init];
_currentViewController = self.generalView;
break;
case kFoldersView:
if (self.foldersView == nil)
_foldersView = [[STPreferencesFoldersViewController alloc] init];
_currentViewController = self.foldersView;
break;
case kDevicesView:
if (self.devicesView == nil)
_devicesView = [[STPreferencesDevicesViewController alloc] init];
_currentViewController = self.devicesView;
break;
case kInfoView:
if (self.infoView == nil)
_infoView = [[STPreferencesInfoViewController alloc] init];
_currentViewController = self.infoView;
break;
case kAdvancedView:
if (self.advancedView == nil)
_advancedView = [[STPreferencesAdvancedViewController alloc] init];
Expand All @@ -89,99 +68,4 @@ - (IBAction) toolbarButtonClicked:(id)sender {
[self setViewFromId:[button tag]];
}

/*
TODO: some day I will know how to dynamic resize the views without
views window height get broken

//[[self window] setFrame:[currentView bounds] display:YES animate:YES];

// embed the current view to our host view
//[currentView addSubview:_currentViewController.view];

//[self resizeWindowWithContentSize:_currentViewController.view.frame.size animated:YES];
//[self.window setContentSize:_currentViewController.view.frame.size];
//[self setContentView:[_currentViewController view]];

// make sure we automatically resize the controller's view to the current window size

//[self.window setContentSize:_currentViewController.view.frame.size];

- (CGFloat)toolbarHeight {
NSToolbar *toolbar = [self.window toolbar];
CGFloat toolbarHeight = 0.0;
NSRect windowFrame;

if (toolbar && [toolbar isVisible]) {
windowFrame = [self.window contentRectForFrameRect:self.window.frame
];
toolbarHeight = NSHeight(windowFrame) -
NSHeight([self.window.contentView frame]);
}
return toolbarHeight;
}

- (void)resizeToSize:(NSSize)newSize {
CGFloat newHeight = newSize.height + [self toolbarHeight];
CGFloat newWidth = newSize.width;

NSRect aFrame = [self.window contentRectForFrameRect:self.window.frame
];

aFrame.origin.y += aFrame.size.height;
aFrame.origin.y -= newHeight;
aFrame.size.height = newHeight;
aFrame.size.width = newWidth;

aFrame = [self.window frameRectForContentRect:aFrame
];
[self.window setFrame:aFrame display:YES animate:YES];
}

- (void) setContentView:(NSView *)view {
//[self resizeToSize:view.frame.size];
//[self.window setFrame:view.frame.size display:YES animate:YES];
[self resizeWindowWithContentSize:view.frame.size animated:YES];
[self.window setContentView:view];
}

- (void) resizeWindowWithContentSize:(NSSize)contentSize animated:(BOOL)animated {
CGFloat titleBarHeight = self.window.frame.size.height - ((NSView*)self.window.contentView).frame.size.height;
CGSize windowSize = windowSize = CGSizeMake(contentSize.width, contentSize.height + titleBarHeight);

// Optional: keep it centered
float originX = self.window.frame.origin.x + (self.window.frame.size.width - windowSize.width) / 2;
float originY = self.window.frame.origin.y + (self.window.frame.size.height - windowSize.height) / 2;
NSRect windowFrame = CGRectMake(originX, originY, windowSize.width, windowSize.height);

[self.window setFrame:windowFrame display:YES animate:animated];
}

- (void)resizeWindowForContentSize:(NSSize) size {
NSWindow *window = [self window];

NSRect windowFrame = [window contentRectForFrameRect:[window frame]];
NSRect newWindowFrame = [window frameRectForContentRect:
NSMakeRect( NSMinX( windowFrame ), NSMaxY( windowFrame ) - size.height, size.width, size.height )];
[window setFrame:newWindowFrame display:YES animate:[window isVisible]];
}


- (void) setContentView:(NSView *)view {

//NSRect wndFrame = [self.window frameRectForContentRect:[view bounds]];

//NSLog(@"wndFrame: %@", NSStringFromRect(wndFrame));
//wndFrame.origin.x = self.window.frame.origin.x + (self.window.frame.size.width - view.frame.size.width) / 2;
//wndFrame.origin.y = self.window.frame.origin.y + (self.window.frame.size.height - view.frame.size.height) / 2;

//[view setFrameOrigin:window.frame.origin];
[self resizeWindowWithContentSize:view.frame.size animated:YES];
//[self.window setFrame:wndFrame display:YES animate:YES];
[[self window] setContentView:view];

//[[self window] setFrame:newWindowFrame display:YES animate:YES];
//[[self window] setContentView:view];
}
*/

@end
2 changes: 2 additions & 0 deletions syncthing/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<string>https://xor-gate.github.io/syncthing-macosx/appcast.xml</string>
<key>SUScheduledCheckInterval</key>
<integer>86400</integer>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
<key>CFBundleGetInfoString</key>
<string>syncthing project Group</string>
</dict>
Expand Down
27 changes: 13 additions & 14 deletions syncthing/STApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ @interface STAppDelegate ()
@implementation STAppDelegate

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];

_syncthing = [[XGSyncthing alloc] init];

[self applicationLoadConfiguration];
Expand All @@ -27,23 +29,28 @@ - (void) applicationDidFinishLaunching:(NSNotification *)aNotification {
[_statusMonitor startMonitoring];
}

- (void) userNotificationCenter:(NSUserNotificationCenter *)center
didActivateNotification:(NSUserNotification *)notification
{
NSDictionary *ui = notification.userInfo;
NSLog(@"ui %@", ui);

[center removeDeliveredNotification:notification];
notification = nil;
}

- (void) clickedFolder:(id)sender {
NSString *path = [sender representedObject];
[[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""];
}

- (void) applicationWillTerminate:(NSNotification *)aNotification {
// TODO: is this needed -> remove?
}

- (void) awakeFromNib {
_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
_statusItem.menu = _Menu;

[self updateStatusIcon:@"StatusIconNotify"];
}

// TODO: move to STConfiguration class
- (void)applicationLoadConfiguration {
static int configLoadAttempt = 1;

Expand Down Expand Up @@ -91,13 +98,6 @@ - (void)applicationLoadConfiguration {
}
}

- (void) sendNotification:(NSString *)text {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Syncthing";
notification.informativeText = text;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}

- (void) updateStatusIcon:(NSString *)icon {
_statusItem.button.image = [NSImage imageNamed:icon];
[_statusItem.button.image setTemplate:YES];
Expand Down Expand Up @@ -125,9 +125,7 @@ - (void) syncMonitorStatusChanged:(SyncthingStatus)status {
}

- (void) syncMonitorEventReceived:(NSDictionary *)event {
NSNumber *eventId = [event objectForKey:@"id"];
NSString *eventType = [event objectForKey:@"type"];
NSDictionary *eventData = [event objectForKey:@"data"];

if ([eventType isEqualToString:@"ConfigSaved"]) {
[self refreshDevices];
Expand Down Expand Up @@ -167,6 +165,7 @@ - (void) updateFoldersMenu:(NSMenu *)menu {
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"label" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
return [(NSString *)obj1 compare:(NSString *)obj2 options:NSNumericSearch];
}];

NSArray *folders = [[self.syncthing getFolders] sortedArrayUsingDescriptors:@[sort]];

for (id dir in folders) {
Expand Down
19 changes: 19 additions & 0 deletions syncthing/STStatusMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,29 @@ - (void) processEvent:(NSDictionary *)event {

self.folderStates[folder] = newState;
[self updateCurrentStatus];
} else if ([eventType isEqualToString:@"FolderRejected"]) {
[self processEventNotificationAcceptDecline:[NSString stringWithFormat:@"New folder %@", [eventData objectForKey:@"folderLabel"]] identifier:[NSString stringWithFormat:@"%@-%@", eventId, eventType] userInfo:[[NSDictionary alloc] initWithDictionary:event]];
} else if ([eventType isEqualToString:@"DeviceRejected"]) {
[self processEventNotificationAcceptDecline:[NSString stringWithFormat:@"New device %@", [eventData objectForKey:@"name"]] identifier:[NSString stringWithFormat:@"%@-%@", eventId, eventType] userInfo:[[NSDictionary alloc] initWithDictionary:event]];
}
[self.delegate syncMonitorEventReceived:event];
}

- (void) processEventNotificationAcceptDecline: (NSString *) informativeText identifier:(NSString *)identifier userInfo:(NSDictionary *)userInfo {
NSUserNotification *n = [[NSUserNotification alloc] init];

n.informativeText = informativeText;
n.identifier = identifier;
n.userInfo = userInfo;

n.title = @"Syncthing";
n.hasActionButton = true;
n.actionButtonTitle = @"Accept";
n.otherButtonTitle = @"Decline";

[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:n];
}

- (void) updateStatusFromTimer {
if (![_syncthing ping]) {
self.currentStatus = SyncthingStatusOffline;
Expand Down
22 changes: 0 additions & 22 deletions syncthing/Tests/main.m

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading