-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.revery.examples</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
open Revery; | ||
open Revery.UI; | ||
open Revery.UI.Components; | ||
|
||
open Revery.Native; | ||
|
||
module Example = { | ||
let%component make = () => { | ||
let%hook (notification, setNotification) = | ||
Hooks.state( | ||
Notification.create( | ||
~title="Revery Test", | ||
~body="This is a test!", | ||
~mute=false, | ||
~onClick=() => Console.log("Notification clicked!"), | ||
(), | ||
), | ||
); | ||
<View> | ||
<Center> | ||
<Button | ||
title="Dispatch!" | ||
onClick={() => Notification.dispatch(notification)} | ||
/> | ||
</Center> | ||
</View>; | ||
}; | ||
}; | ||
|
||
let render = () => <Example />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
external setAppDelegate: unit => unit = "revery_cocoaSetAppDelegate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type t = { | ||
title: string, | ||
body: string, | ||
onClick: unit => unit, | ||
mute: bool, | ||
}; | ||
|
||
let create = | ||
(~title: string, ~body: string, ~onClick=() => (), ~mute=false, ()) => { | ||
title, | ||
body, | ||
onClick, | ||
mute, | ||
}; | ||
|
||
external dispatch: t => unit = "revery_dispatchNotification"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
module Dialog = Dialog; | ||
module Notification = Notification; | ||
module Cocoa = Cocoa; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifdef __APPLE__ | ||
#import "ReveryAppDelegate.h" | ||
#import <Cocoa/Cocoa.h> | ||
|
||
#import "utilities.h" | ||
|
||
// Implementation of ReveryAppDelegate | ||
@implementation ReveryAppDelegate | ||
|
||
/* init - initializes the AppDelegate | ||
Assigns a mutable dictionary to notificationActions | ||
*/ | ||
- (id)init { | ||
self = [super init]; | ||
if (self) { | ||
_notificationActions = [NSMutableDictionary new]; | ||
} | ||
return self; | ||
} | ||
|
||
/* applicationDidFinishLaunching | ||
Assigns self as the notification center delegate | ||
*/ | ||
- (void)applicationDidFinishLaunching:(NSNotification *)notification { | ||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; | ||
} | ||
|
||
/* didActivateNotification | ||
Gets the long from the NSDictionary from the notification's identifier and calls it | ||
*/ | ||
- (void)userNotificationCenter:(NSUserNotificationCenter *)center | ||
didActivateNotification:(NSUserNotification *)notification { | ||
NSNumber *num = _notificationActions[[notification identifier]]; | ||
long ocamlFunc = [num longValue]; | ||
revery_caml_call(ocamlFunc); | ||
} | ||
|
||
/* shouldPresentNotification | ||
Always presents the notification | ||
*/ | ||
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center | ||
shouldPresentNotification:(NSUserNotification *)notification { | ||
return YES; | ||
} | ||
@end | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#import <Cocoa/Cocoa.h> | ||
|
||
/* ReveryAppDelegate | ||
Contains all of the delegation code for the NSApplication, as well as the | ||
delegation for the NSUserNotificationCenter | ||
*/ | ||
@interface ReveryAppDelegate | ||
: NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate> | ||
/* [notificationActions] - a mutable dictionary | ||
maps NSStrings (notification identifiers) -> NSNumbers | ||
(longs which represent OCaml callbacks) | ||
*/ | ||
@property(nonatomic, strong) NSMutableDictionary *notificationActions; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifdef __APPLE__ | ||
#include <caml/alloc.h> | ||
#include <caml/callback.h> | ||
#include <caml/memory.h> | ||
#include <caml/mlvalues.h> | ||
|
||
#import "ReveryAppDelegate.h" | ||
|
||
extern "C" { | ||
CAMLprim value revery_cocoaSetAppDelegate() { | ||
ReveryAppDelegate *delegate = [ReveryAppDelegate new]; | ||
[NSApp setDelegate:delegate]; | ||
return Val_unit; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <stdio.h> | ||
|
||
#include <caml/alloc.h> | ||
#include <caml/callback.h> | ||
#include <caml/memory.h> | ||
#include <caml/mlvalues.h> | ||
#include <string.h> | ||
|
||
|
||
#ifdef WIN32 | ||
#include "ReveryWin32.h" | ||
#elif __APPLE__ | ||
#include "ReveryCocoa.h" | ||
#else | ||
#include "ReveryGtk.h" | ||
#endif | ||
|
||
#define Val_none Val_int(0) | ||
static value Val_some(value v) { | ||
CAMLparam1(v); | ||
CAMLlocal1(some); | ||
some = caml_alloc(1, 0); | ||
Store_field(some, 0, v); | ||
CAMLreturn(some); | ||
} | ||
|
||
#define Some_val(v) Field(v, 0) | ||
|
||
extern "C" { | ||
CAMLprim value revery_dispatchNotification(value vNotificationT) { | ||
CAMLparam1(vNotificationT); | ||
|
||
const char *title; | ||
const char *body; | ||
int mute; | ||
|
||
title = String_val(Field(vNotificationT, 0)); | ||
body = String_val(Field(vNotificationT, 1)); | ||
value onClickCaml = Field(vNotificationT, 2); | ||
mute = Int_val(Field(vNotificationT, 3)); | ||
#ifdef __APPLE__ | ||
revery_dispatchNotification_cocoa(title, body, onClickCaml, mute); | ||
#endif | ||
|
||
CAMLreturn(Val_unit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifdef __APPLE__ | ||
#import "cocoa/ReveryAppDelegate.h" | ||
#import <Cocoa/Cocoa.h> | ||
|
||
#include "utilities.h" | ||
|
||
void revery_dispatchNotification_cocoa(const char *title, const char *body, | ||
long onClickFunc, int mute) { | ||
NSUserNotification *notification = [[NSUserNotification alloc] autorelease]; | ||
NSUserNotificationCenter *notificationCenter = | ||
[NSUserNotificationCenter defaultUserNotificationCenter]; | ||
ReveryAppDelegate *delegate = (ReveryAppDelegate *)[NSApp delegate]; | ||
NSString *nsTitle = | ||
[NSString stringWithCString:title encoding:NSUTF8StringEncoding]; | ||
NSString *nsBody = | ||
[NSString stringWithCString:body encoding:NSUTF8StringEncoding]; | ||
|
||
NSString *identifier = | ||
[NSString stringWithFormat:@"%@:notification:%@", | ||
[[NSBundle mainBundle] bundleIdentifier], | ||
[[[NSUUID alloc] init] UUIDString]]; | ||
[notification setIdentifier:identifier]; | ||
[notification setTitle:nsTitle]; | ||
[notification setInformativeText:nsBody]; | ||
[notification setSoundName:mute ? NULL : NSUserNotificationDefaultSoundName]; | ||
|
||
delegate.notificationActions[identifier] = | ||
[NSNumber numberWithLong:onClickFunc]; | ||
|
||
[notificationCenter deliverNotification:notification]; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <caml/alloc.h> | ||
#include <caml/callback.h> | ||
#include <caml/memory.h> | ||
#include <caml/mlvalues.h> | ||
#import <caml/threads.h> | ||
|
||
/* Sourced from Brisk's `BriskCocoa` | ||
Thank you @wokalski! | ||
*/ | ||
void revery_caml_call_n(value f, int argCount, value *args) { | ||
caml_c_thread_register(); | ||
caml_acquire_runtime_system(); | ||
caml_callbackN(f, argCount, args); | ||
caml_release_runtime_system(); | ||
} | ||
|
||
void revery_caml_call(value f) { | ||
value args[] = {Val_unit}; | ||
revery_caml_call_n(f, 1, args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
void revery_caml_call_n(long f, int numArgs, int* args); | ||
void revery_caml_call(long f); |