Add object detection, tracking, mobile notifications, and search to any security camera.
rename email to notification
roryclear7c0af535e2c4
diff --git a/clearcam/Email.h b/clearcam/Notification.hsimilarity index 80%rename from clearcam/Email.hrename to clearcam/Notification.hindex f8ed556..c2f6a18 100644--- a/clearcam/Email.h+++ b/clearcam/Notification.h@@ -1,6 +1,6 @@#import <Foundation/Foundation.h>-@interface Email : NSObject+@interface notification : NSObject+ (instancetype)sharedInstance;- (void)uploadImageAtPath:(NSString *)imagePath;diff --git a/clearcam/Email.m b/clearcam/Notification.msimilarity index 95%rename from clearcam/Email.mrename to clearcam/Notification.mindex 9353bca..6bff3dc 100644--- a/clearcam/Email.m+++ b/clearcam/Notification.m@@ -1,13 +1,13 @@-#import "Email.h"+#import "notification.h"#import "SecretManager.h"#import "StoreManager.h"#import "FileServer.h"#import <UIKit/UIKit.h>-@implementation Email+@implementation notification+ (instancetype)sharedInstance {- static Email *sharedInstance = nil;+ static notification *sharedInstance = nil;static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{sharedInstance = [[self alloc] init];@@ -19,7 +19,7 @@NSString *server = @"https://www.rors.ai";if ([[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_server_enabled"]) {- server = [[NSUserDefaults standardUserDefaults] valueForKey:@"own_email_server_address"];+ server = [[NSUserDefaults standardUserDefaults] valueForKey:@"own_notification_server_address"];if (![server hasPrefix:@"http"]) {server = [@"http://" stringByAppendingString:server];}@@ -52,7 +52,7 @@NSString *server = @"https://www.rors.ai";if ([[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_server_enabled"]) {- server = [[NSUserDefaults standardUserDefaults] valueForKey:@"own_email_server_address"];+ server = [[NSUserDefaults standardUserDefaults] valueForKey:@"own_notification_server_address"];if (![server hasPrefix:@"http"]) {server = [@"http://" stringByAppendingString:server];}@@ -101,7 +101,7 @@[bodyData appendData:fileData];[bodyData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];- // Include session_token if not using own email server+ // Include session_token if not using own notification serverif (![[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_server_enabled"]) {NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];if (sessionToken) {diff --git a/clearcam/SceneState.h b/clearcam/SceneState.hindex 6bce864..6b09f21 100644--- a/clearcam/SceneState.h+++ b/clearcam/SceneState.h@@ -11,6 +11,6 @@@property (strong, nonatomic) NSManagedObjectContext *backgroundContext;@property (strong, nonatomic) NSDate *last_notif_time;- (void)processOutput:(NSArray *)array withImage:(CIImage *)image;-- (void)sendEmail:(NSString *)filePath; //todo, remove+- (void)sendnotification:(NSString *)filePath; //todo, remove@enddiff --git a/clearcam/SceneState.m b/clearcam/SceneState.mindex aa159bb..35e3dc8 100644--- a/clearcam/SceneState.m+++ b/clearcam/SceneState.m@@ -4,7 +4,7 @@#import "AppDelegate.h"#import "StoreManager.h"#import "FileServer.h"-#import "Email.h"+#import "notification.h"#import <MobileCoreServices/MobileCoreServices.h> // Add this import#import <CommonCrypto/CommonCryptor.h>@@ -103,10 +103,10 @@if(![[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || ![[NSDate date] compare:[[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"]] || [[NSDate date] compare:[[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"]] == NSOrderedDescending){NSLog(@"verifying subscription");[[StoreManager sharedInstance] verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {- [self sendEmail:filePath];+ [self sendnotification:filePath];}];} else {- [self sendEmail:filePath];+ [self sendnotification:filePath];}}}@@ -131,7 +131,7 @@}}-- (void)sendEmail:(NSString *)filePath {+- (void)sendnotification:(NSString *)filePath {if ([[NSUserDefaults standardUserDefaults] boolForKey:@"send_notif_enabled"] || !([[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || [[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_server_enabled"])){ //todo add back other stuffNSDate *now = [NSDate date];NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday) fromDate:now];@@ -146,14 +146,14 @@NSInteger endTime = [schedule[@"endHour"] integerValue] * 60 + [schedule[@"endMinute"] integerValue];if (currentTime >= startTime && currentTime <= endTime) {- [[Email sharedInstance] sendNotification];+ [[notification sharedInstance] sendNotification];if([FileServer sharedInstance].segment_length > 3) [FileServer sharedInstance].segment_length = 3;NSTimeInterval start = [[NSDate dateWithTimeIntervalSinceNow:-7.5] timeIntervalSince1970];NSTimeInterval end = [[NSDate dateWithTimeIntervalSinceNow:7.5] timeIntervalSince1970];id context = [FileServer sharedInstance].context;dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{NSString *filePath = [[FileServer sharedInstance] processVideoDownloadWithLowRes:YES startTime:start endTime:end context:context];- [[Email sharedInstance] uploadImageAtPath:filePath];+ [[notification sharedInstance] uploadImageAtPath:filePath];});break;}diff --git a/clearcam/ScheduleManagementViewController.h b/clearcam/ScheduleManagementViewController.hindex b83c246..f7cd480 100644--- a/clearcam/ScheduleManagementViewController.h+++ b/clearcam/ScheduleManagementViewController.h@@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN@interface ScheduleManagementViewController : UITableViewController-@property (nonatomic, strong) NSMutableArray<NSDictionary *> *emailSchedules;+@property (nonatomic, strong) NSMutableArray<NSDictionary *> *notificationSchedules;@property (nonatomic, copy) void (^completionHandler)(NSArray<NSDictionary *> *schedules);@enddiff --git a/clearcam/ScheduleManagementViewController.m b/clearcam/ScheduleManagementViewController.mindex 3ec538b..b12f173 100644--- a/clearcam/ScheduleManagementViewController.m+++ b/clearcam/ScheduleManagementViewController.m@@ -26,18 +26,18 @@- (void)doneTapped:(id)sender {// Save changes and pop backif (self.completionHandler) {- self.completionHandler(self.emailSchedules);+ self.completionHandler(self.notificationSchedules);}[self.navigationController popViewControllerAnimated:YES];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {- return self.emailSchedules.count;+ return self.notificationSchedules.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScheduleCell" forIndexPath:indexPath];- NSDictionary *schedule = self.emailSchedules[indexPath.row];+ NSDictionary *schedule = self.notificationSchedules[indexPath.row];cell.textLabel.text = [self scheduleDescriptionFor:schedule];cell.detailTextLabel.text = nil;@@ -68,17 +68,17 @@- (void)toggleSwitchChanged:(UISwitch *)sender {NSInteger index = sender.tag;- NSMutableDictionary *schedule = [self.emailSchedules[index] mutableCopy];+ NSMutableDictionary *schedule = [self.notificationSchedules[index] mutableCopy];schedule[@"enabled"] = @(sender.on);- self.emailSchedules[index] = schedule;+ self.notificationSchedules[index] = schedule;[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {ScheduleEditorViewController *editorVC = [[ScheduleEditorViewController alloc] init];- editorVC.schedule = [self.emailSchedules[indexPath.row] mutableCopy];+ editorVC.schedule = [self.notificationSchedules[indexPath.row] mutableCopy];editorVC.completionHandler = ^(NSDictionary *updatedSchedule) {- self.emailSchedules[indexPath.row] = updatedSchedule;+ self.notificationSchedules[indexPath.row] = updatedSchedule;[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];};[self.navigationController pushViewController:editorVC animated:YES];@@ -86,13 +86,13 @@}- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {- NSDictionary *schedule = self.emailSchedules[indexPath.row];+ NSDictionary *schedule = self.notificationSchedules[indexPath.row];return ([schedule[@"days"] count] == 7 && [schedule[@"startHour"] isEqual:@0] && [schedule[@"startMinute"] isEqual:@0] && [schedule[@"endHour"] isEqual:@23] && [schedule[@"endMinute"] isEqual:@59]) ? UITableViewCellEditingStyleNone : UITableViewCellEditingStyleDelete;}- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {if (editingStyle == UITableViewCellEditingStyleDelete) {- [self.emailSchedules removeObjectAtIndex:indexPath.row];+ [self.notificationSchedules removeObjectAtIndex:indexPath.row];[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];}}@@ -106,14 +106,14 @@@"endMinute": @59,@"enabled": @YES} mutableCopy];- [self.emailSchedules addObject:newSchedule];- NSInteger newIndex = self.emailSchedules.count - 1;+ [self.notificationSchedules addObject:newSchedule];+ NSInteger newIndex = self.notificationSchedules.count - 1;[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:newIndex inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];ScheduleEditorViewController *editorVC = [[ScheduleEditorViewController alloc] init];editorVC.schedule = newSchedule;editorVC.completionHandler = ^(NSDictionary *updatedSchedule) {- self.emailSchedules[newIndex] = updatedSchedule;+ self.notificationSchedules[newIndex] = updatedSchedule;[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:newIndex inSection:0]] withRowAnimation:UITableViewRowAnimationNone];};[self.navigationController pushViewController:editorVC animated:YES];diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.mindex bde370e..dba9fc2 100644--- a/clearcam/SettingsViewController.m+++ b/clearcam/SettingsViewController.m@@ -3,7 +3,7 @@#import "SecretManager.h"#import "StoreManager.h"#import "NumberSelectionViewController.h"-#import "Email.h"+#import "notification.h"#import "FileServer.h"#import "ScheduleManagementViewController.h"#import <UserNotifications/UserNotifications.h>@@ -17,8 +17,8 @@@property (nonatomic, assign) BOOL sendNotifEnabled;@property (nonatomic, assign) BOOL receiveNotifEnabled; // New property for receiving notifications@property (nonatomic, assign) BOOL useOwnServerEnabled;-@property (nonatomic, assign) BOOL isEmailServerSectionExpanded; // Track if email server section is expanded-@property (nonatomic, strong) NSString *emailServerAddress; // Store the email server address+@property (nonatomic, assign) BOOL isnotificationServerSectionExpanded; // Track if notification server section is expanded+@property (nonatomic, strong) NSString *notificationServerAddress; // Store the notification server address@property (nonatomic, strong) NSMutableArray<NSDictionary *> *notificationSchedules; // Array to store notification schedules@property (nonatomic, assign) BOOL streamViaWiFiEnabled;@property (nonatomic, strong) id ipAddressObserver;@@ -106,8 +106,8 @@[defaults setObject:self.notificationSchedules forKey:@"notification_schedules"];}- self.isEmailServerSectionExpanded = self.useOwnServerEnabled;- self.emailServerAddress = [defaults stringForKey:@"own_email_server_address"] ?: @"http://192.168.1.1";+ self.isnotificationServerSectionExpanded = self.useOwnServerEnabled;+ self.notificationServerAddress = [defaults stringForKey:@"own_notification_server_address"] ?: @"http://192.168.1.1";[defaults synchronize];@@ -151,9 +151,9 @@NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];NSString *ipAddress = [defaults stringForKey:@"DeviceIPAddress"];if (ipAddress && ipAddress.length > 0) {- self.emailServerAddress = [NSString stringWithFormat:@"http://%@", ipAddress];+ self.notificationServerAddress = [NSString stringWithFormat:@"http://%@", ipAddress];} else {- self.emailServerAddress = @"Waiting for IP...";+ self.notificationServerAddress = @"Waiting for IP...";}}@@ -307,7 +307,7 @@- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {if (section == 0) { // Camera SettingsNSInteger baseRows = 9; // All settings except Receive Notifications- if (self.useOwnServerEnabled && self.isEmailServerSectionExpanded) {+ if (self.useOwnServerEnabled && self.isnotificationServerSectionExpanded) {baseRows += 2;}if (self.isPresetsSectionExpanded) {@@ -417,16 +417,16 @@} else if (indexPath.row == 8 + offset) {cell.textLabel.text = @"Use Own Notification Server";cell.accessoryType = UITableViewCellAccessoryNone;- UISwitch *useOwnEmailServerSwitch = [[UISwitch alloc] init];- useOwnEmailServerSwitch.on = self.useOwnServerEnabled;- [useOwnEmailServerSwitch addTarget:self action:@selector(useOwnEmailServerSwitchToggled:) forControlEvents:UIControlEventValueChanged];- cell.accessoryView = useOwnEmailServerSwitch;+ UISwitch *useOwnnotificationServerSwitch = [[UISwitch alloc] init];+ useOwnnotificationServerSwitch.on = self.useOwnServerEnabled;+ [useOwnnotificationServerSwitch addTarget:self action:@selector(useOwnnotificationServerSwitchToggled:) forControlEvents:UIControlEventValueChanged];+ cell.accessoryView = useOwnnotificationServerSwitch;cell.userInteractionEnabled = YES;- } else if (self.useOwnServerEnabled && self.isEmailServerSectionExpanded && indexPath.row == 9 + offset) {+ } else if (self.useOwnServerEnabled && self.isnotificationServerSectionExpanded && indexPath.row == 9 + offset) {cell.textLabel.text = @"Server Address";- cell.detailTextLabel.text = self.emailServerAddress;+ cell.detailTextLabel.text = self.notificationServerAddress;cell.userInteractionEnabled = YES;- } else if (self.useOwnServerEnabled && self.isEmailServerSectionExpanded && indexPath.row == 10 + offset) {+ } else if (self.useOwnServerEnabled && self.isnotificationServerSectionExpanded && indexPath.row == 10 + offset) {cell.textLabel.text = @"Test own server";cell.textLabel.textColor = [UIColor systemBlueColor];cell.detailTextLabel.text = nil;@@ -537,7 +537,7 @@}} else if (indexPath.row == 7 + offset) {ScheduleManagementViewController *scheduleVC = [[ScheduleManagementViewController alloc] init];- scheduleVC.emailSchedules = [self.notificationSchedules mutableCopy];+ scheduleVC.notificationSchedules = [self.notificationSchedules mutableCopy];scheduleVC.completionHandler = ^(NSArray<NSDictionary *> *schedules) {self.notificationSchedules = [schedules mutableCopy];NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];@@ -548,10 +548,10 @@[self.navigationController pushViewController:scheduleVC animated:YES];} else if (indexPath.row == 8 + offset) {// Use Own Notification Server - handled by switch- } else if (self.useOwnServerEnabled && self.isEmailServerSectionExpanded && indexPath.row == 9 + offset) {- [self showEmailServerAddressInputDialog];- } else if (self.useOwnServerEnabled && self.isEmailServerSectionExpanded && indexPath.row == 10 + offset) {- [self testEmailServer];+ } else if (self.useOwnServerEnabled && self.isnotificationServerSectionExpanded && indexPath.row == 9 + offset) {+ [self shownotificationServerAddressInputDialog];+ } else if (self.useOwnServerEnabled && self.isnotificationServerSectionExpanded && indexPath.row == 10 + offset) {+ [self testnotificationServer];}}} else if (indexPath.section == 1) { // Viewer Settings@@ -579,9 +579,9 @@[self presentViewController:alert animated:YES completion:nil];}-- (void)useOwnEmailServerSwitchToggled:(UISwitch *)sender {+- (void)useOwnnotificationServerSwitchToggled:(UISwitch *)sender {self.useOwnServerEnabled = sender.on;- self.isEmailServerSectionExpanded = sender.on;+ self.isnotificationServerSectionExpanded = sender.on;NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];[defaults setBool:self.useOwnServerEnabled forKey:@"use_own_server_enabled"];@@ -590,14 +590,14 @@[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];}-- (void)showEmailServerAddressInputDialog {+- (void)shownotificationServerAddressInputDialog {UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Server Address"- message:@"Please enter the address of your email server."+ message:@"Please enter the address of your notification server."preferredStyle:UIAlertControllerStyleAlert];[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {textField.placeholder = @"Server Address";- textField.text = self.emailServerAddress;+ textField.text = self.notificationServerAddress;}];UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save"@@ -605,9 +605,9 @@handler:^(UIAlertAction * _Nonnull action) {NSString *address = alert.textFields.firstObject.text;if (address.length > 0) {- self.emailServerAddress = address;+ self.notificationServerAddress = address;NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];- [defaults setObject:address forKey:@"own_email_server_address"];+ [defaults setObject:address forKey:@"own_notification_server_address"];[defaults synchronize];[self.tableView reloadData];}@@ -623,10 +623,10 @@[self presentViewController:alert animated:YES completion:nil];}-- (void)testEmailServer {- [[Email sharedInstance] sendNotification];+- (void)testnotificationServer {+ [[notification sharedInstance] sendNotification];UIAlertController *resultAlert = [UIAlertController alertControllerWithTitle:@"Test Initiated"- message:@"Test email has been initiated. Check your server logs for results."+ message:@"Test notification has been initiated. Check your server logs for results."preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault