Welcome to mirror list, hosted at ThFree Co, Russian Federation.

systray.mm « gui « src - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f564fcd2215e3b66da0300df82530004315c011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <QString>
#include <QWindow>
#import <Cocoa/Cocoa.h>

@interface NotificationCenterDelegate : NSObject
@end
@implementation NotificationCenterDelegate
// Always show, even if app is active at the moment.
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
     shouldPresentNotification:(NSUserNotification *)notification
{
    Q_UNUSED(center);
    Q_UNUSED(notification);
    return YES;
}
@end

namespace OCC {

double statusBarThickness()
{
    return [NSStatusBar systemStatusBar].thickness;
}

bool canOsXSendUserNotification()
{
    return NSClassFromString(@"NSUserNotificationCenter") != nil;
}

void sendOsXUserNotification(const QString &title, const QString &message)
{
    Class cuserNotificationCenter = NSClassFromString(@"NSUserNotificationCenter");
    id userNotificationCenter = [cuserNotificationCenter defaultUserNotificationCenter];

    static dispatch_once_t once;
    dispatch_once(&once, ^{
            id delegate = [[NotificationCenterDelegate alloc] init];
            [userNotificationCenter setDelegate:delegate];
    });

    Class cuserNotification = NSClassFromString(@"NSUserNotification");
    id notification = [[cuserNotification alloc] init];
    [notification setTitle:[NSString stringWithUTF8String:title.toUtf8().data()]];
    [notification setInformativeText:[NSString stringWithUTF8String:message.toUtf8().data()]];

    [userNotificationCenter deliverNotification:notification];
    [notification release];
}

void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window)
{
    NSView *nativeView = (NSView *)window->winId();
    NSWindow *nativeWindow = (NSWindow *)[nativeView window];
    [nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle |
                  NSWindowCollectionBehaviorTransient];
    [nativeWindow setLevel:NSMainMenuWindowLevel];
}

bool osXInDarkMode()
{
    NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
    return [osxMode containsString:@"Dark"];
}

}