Skip to content

Commit

Permalink
Show an alert when notifications permission is denied
Browse files Browse the repository at this point in the history
  • Loading branch information
grishka committed Apr 14, 2023
1 parent 50f62f6 commit 9216f4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions NearDrop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSUIElement = YES;
Expand All @@ -398,7 +398,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -417,7 +417,7 @@
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSUIElement = YES;
Expand All @@ -429,7 +429,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
18 changes: 18 additions & 0 deletions NearDrop/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class AppDelegate: NSObject, NSApplicationDelegate{

let nc=UNUserNotificationCenter.current()
nc.requestAuthorization(options: [.alert, .sound]) { granted, err in
if !granted{
self.showNotificationsDeniedAlert()
}
}
let incomingTransfersCategory=NDNotificationCenterHackery.hackedNotificationCategory()
let errorsCategory=UNNotificationCategory(identifier: "ERRORS", actions: [], intentIdentifiers: [])
Expand All @@ -40,5 +43,20 @@ class AppDelegate: NSObject, NSApplicationDelegate{
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}

func showNotificationsDeniedAlert(){
let alert=NSAlert()
alert.alertStyle = .critical
alert.messageText=NSLocalizedString("NotificationsDenied.Title", value: "Notification Permission Required", comment: "")
alert.informativeText=NSLocalizedString("NotificationsDenied.Message", value: "NearDrop needs to be able to display notifications for incoming file transfers. Please allow notifications in System Settings.", comment: "")
alert.addButton(withTitle: NSLocalizedString("NotificationsDenied.OpenSettings", value: "Open settings", comment: ""))
alert.addButton(withTitle: NSLocalizedString("Quit", value: "Quit NearDrop", comment: ""))
let result=alert.runModal()
if result==NSApplication.ModalResponse.alertFirstButtonReturn{
NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.notifications")!)
}else if result==NSApplication.ModalResponse.alertSecondButtonReturn{
NSApplication.shared.terminate(nil)
}
}
}

Binary file modified NearDrop/Base.lproj/Localizable.strings
Binary file not shown.
Binary file modified NearDrop/ru.lproj/Localizable.strings
Binary file not shown.

0 comments on commit 9216f4e

Please sign in to comment.