From 9216f4e718ffcedc1178a8f2d506c7d24e0ca435 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 14 Apr 2023 05:46:34 +0300 Subject: [PATCH] Show an alert when notifications permission is denied --- NearDrop.xcodeproj/project.pbxproj | 8 ++++---- NearDrop/AppDelegate.swift | 18 ++++++++++++++++++ NearDrop/Base.lproj/Localizable.strings | Bin 1638 -> 2442 bytes NearDrop/ru.lproj/Localizable.strings | Bin 1656 -> 2474 bytes 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/NearDrop.xcodeproj/project.pbxproj b/NearDrop.xcodeproj/project.pbxproj index f508cdb..3d10ebc 100644 --- a/NearDrop.xcodeproj/project.pbxproj +++ b/NearDrop.xcodeproj/project.pbxproj @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/NearDrop/AppDelegate.swift b/NearDrop/AppDelegate.swift index 35e3cdc..e1ce77a 100644 --- a/NearDrop/AppDelegate.swift +++ b/NearDrop/AppDelegate.swift @@ -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: []) @@ -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) + } + } } diff --git a/NearDrop/Base.lproj/Localizable.strings b/NearDrop/Base.lproj/Localizable.strings index 7a2a9e58859211f333fe8be20d25d8ff6b1eb522..73b3883c1d580fdee3071e17fc04a9d264f67067 100644 GIT binary patch literal 2442 zcmc(hK~KU!5QXRLuV{>1I7sxUG0`X{9z+!4y+R=*wMB{=|GfIWU27K%(SxfY>~?3j zGjC?z%=YcIV{J>UXC>o^@t$91g)LdnZGq&;W;RAPMsjB_jM|?fEqKZ}vx}^49ow>P zJ3-3`=^PE)$dCB1OAk4@#rfa0e1_GL~AcxA@)Xtf6Bvp{3mhIUNXcG1+#%kq_gv^)r=n(I_bFol&VU&0$UY#<& zI4+d|(k?!XK6hrEEx;uv`uF|M@OVp~;{2k1^&tBM{$B|fB7!rx)+ZOE;vcM@bh z4&&5E!(SR6Nv2cI}e6;+Mk3EQno?RZ3*fTy*DP_C03o7^!Hh2W5;YvlyIU zPf{_vf+;yW>QTi;B#MLBC7z2%%9gK+CPLD>KvRLv304-&>T-Q&GiBv5GlP zCpG|Ah29K%T4g*dR;ov7kHy-b=H!a#DM#zbnl4tK@Vy~K|KHe$#Bu3z)1cktx3Z{= zD(m84U7I&ZAE??HdtzxUpZZuR=xil6LhkqNf}11uop9|u4DaSzqOX9}>WdYD;aY7q z9ly!mIo0RyD0MDhu}{KK5XR4NaWHP~ik%H9jkQo{DHIY3N(W7hBT+O&1BP~RBdl(w|Amu(o}<6_ zT+|q&Y2Mwv@7>*Z{qAl1W#{#AvwW(ISB{KjA%)E3hI1to8!u!ox%6d