Skip to content

Commit

Permalink
Fix copy OTP feature & reorganize icons
Browse files Browse the repository at this point in the history
There was an issue where Soduto would copy OTP along with hidden/invisible characters which led to incorrect OTP validation.
  • Loading branch information
sannidhyaroy committed Jul 17, 2023
1 parent 6566179 commit 78d5f33
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 37 deletions.
1 change: 1 addition & 0 deletions SharedUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ struct SharedUserDefaults {
struct Preferences {
static let disableSharePopUp = ""
static let deviceType = ""
static let hostName = ""
}
}
20 changes: 10 additions & 10 deletions Soduto.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -464,26 +464,28 @@
name = Configuration;
sourceTree = "<group>";
};
312E770B2938AB7400F29BFA /* Notification Service */ = {
312E770B2938AB7400F29BFA /* App Icons */ = {
isa = PBXGroup;
children = (
8468BDFA1DE8F10D003B9925 /* NotificationsService.swift */,
319CBA292939F07D00DAE301 /* AirDrop.png */,
317ACC482A1C35A800D01DF4 /* Clock.png */,
312E76F82938A93E00F29BFA /* Discord.png */,
312E76FE2938A93F00F29BFA /* Facebook.png */,
312E76FC2938A93F00F29BFA /* Instagram.png */,
317ACC482A1C35A800D01DF4 /* Clock.png */,
317ACC472A1C35A800D01DF4 /* Gmail.png */,
317ACC492A1C35A800D01DF4 /* YouTube.png */,
312E76FC2938A93F00F29BFA /* Instagram.png */,
3144827C2940AF3200CCA098 /* Message.png */,
312E76FD2938A93F00F29BFA /* Messages.png */,
312E76F62938A93E00F29BFA /* Messenger.png */,
319CBA272939662400DAE301 /* Phone.png */,
312E76F92938A93E00F29BFA /* Reddit.png */,
312E76F42938A93D00F29BFA /* Signal.png */,
312E76F72938A93E00F29BFA /* Spike.png */,
312E76FB2938A93F00F29BFA /* Telegram.png */,
312E76FA2938A93F00F29BFA /* Twitter.png */,
312E76F52938A93E00F29BFA /* WhatsApp.png */,
317ACC492A1C35A800D01DF4 /* YouTube.png */,
);
path = "Notification Service";
path = "App Icons";
sourceTree = "<group>";
};
31F3A150293B5EA300550088 /* Soduto Share */ = {
Expand Down Expand Up @@ -595,6 +597,7 @@
8438A9251E45145F00922155 /* StatusBarApplication.swift */,
31864DCE293C3CE100334902 /* SharedUserDefaults.swift */,
843301651D2D8CB8008934BB /* Assets.xcassets */,
312E770B2938AB7400F29BFA /* App Icons */,
8456F4A41D7DE31A006EFE19 /* Core */,
849961B31D572664002B893A /* MyUtilities */,
84FA45EB1DDF51EB00EF3992 /* Services */,
Expand Down Expand Up @@ -794,15 +797,12 @@
84651A711E599A3C00D17601 /* BatteryService.swift */,
840FC2F81DEF6AF400AC4824 /* ClipboardService.swift */,
849237A01DE224CF00D95BBA /* FindMyPhoneService.swift */,
8468BDFA1DE8F10D003B9925 /* NotificationsService.swift */,
84FA45EC1DDF525200EF3992 /* PingService.swift */,
842505E81ED1BD3C00AEE25F /* RemoteKeyboardService.swift */,
84651A751E5AEBE100D17601 /* SftpService.swift */,
843B67031DF1E64A00289EC9 /* ShareService.swift */,
847E9D2A1DF5E2640042D3CE /* TelephonyService.swift */,
319CBA272939662400DAE301 /* Phone.png */,
319CBA292939F07D00DAE301 /* AirDrop.png */,
3144827C2940AF3200CCA098 /* Message.png */,
312E770B2938AB7400F29BFA /* Notification Service */,
);
path = Services;
sourceTree = "<group>";
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions Soduto/Base.lproj/DeviceInfoWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="515" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="515" height="269"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<visualEffectView appearanceType="vibrantLight" blendingMode="behindWindow" material="popover" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="q4D-5l-CMl">
<visualEffectView blendingMode="behindWindow" material="popover" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="q4D-5l-CMl">
<rect key="frame" x="0.0" y="0.0" width="515" height="269"/>
</visualEffectView>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" alphaValue="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="Hq9-nH-nzu">
Expand Down
8 changes: 2 additions & 6 deletions Soduto/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="XN7-yK-oPR"/>
<menuItem title="Launch on Login" id="tU8-jY-Cw3">
<modifierMask key="keyEquivalentModifierMask"/>
<menuItem title="Launch on Login" keyEquivalent="l" id="tU8-jY-Cw3">
<connections>
<action selector="toggleLaunchOnLogin:" target="vQj-dd-GoX" id="tjq-3a-oye"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Zv9-hp-heD"/>
<menuItem title="Check for Updates" id="zow-ql-WNV">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Check for Updates" keyEquivalent="u" id="zow-ql-WNV"/>
<menuItem title="Preferences" keyEquivalent="," id="NNU-ep-Fgn" userLabel="Open Soduto Preferences">
<connections>
<action selector="openPreferences:" target="vQj-dd-GoX" id="rrW-aH-Gim"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="NAb-Li-52a"/>
<menuItem title="About" id="sNE-CC-2Jm">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showAboutWindow:" target="vQj-dd-GoX" id="Z8y-Zi-KJK"/>
</connections>
Expand Down
8 changes: 4 additions & 4 deletions Soduto/Base.lproj/PreferencesWindow.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@
<objects>
<viewController title="Devices" id="DvB-YZ-h1x" customClass="DevicePreferencesViewController" customModule="Soduto" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="gnx-Qc-teH">
<rect key="frame" x="0.0" y="0.0" width="680" height="400"/>
<rect key="frame" x="0.0" y="0.0" width="750" height="450"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView translatesAutoresizingMaskIntoConstraints="NO" id="1St-dx-ejH">
<rect key="frame" x="240" y="20" width="420" height="360"/>
<rect key="frame" x="240" y="20" width="490" height="410"/>
<connections>
<segue destination="NJm-NZ-OS4" kind="embed" id="sAC-j9-Ov0"/>
</connections>
</containerView>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Nu6-PX-g25">
<rect key="frame" x="40" y="248" width="172" height="112"/>
<rect key="frame" x="40" y="298" width="172" height="112"/>
<constraints>
<constraint firstAttribute="height" constant="112" id="BRh-GY-Swb"/>
<constraint firstAttribute="width" constant="172" id="CFB-5S-goK"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSApplicationIcon" id="HWE-4F-dhu"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JI8-Vn-Ayd" userLabel="Host name">
<rect key="frame" x="18" y="204" width="216" height="16"/>
<rect key="frame" x="18" y="254" width="216" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Host name" id="sAG-f5-P1a">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand Down
6 changes: 2 additions & 4 deletions Soduto/Base.lproj/SendMessageWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</view>
<toolbar key="toolbar" implicitIdentifier="5BE39696-EFAC-49AF-9F6E-A29CE9AB6426" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconOnly" sizeMode="regular" id="Ym2-od-Q4Z">
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="ADB3F3EF-D77C-4FC3-B069-7B693D402546" label="" paletteLabel="" image="paperplane" catalog="system" sizingBehavior="auto" id="0Jl-d3-6gn">
<toolbarItem implicitItemIdentifier="ADB3F3EF-D77C-4FC3-B069-7B693D402546" label="Send" paletteLabel="" image="paperplane" catalog="system" sizingBehavior="auto" id="0Jl-d3-6gn">
<nil key="toolTip"/>
<button key="view" verticalHuggingPriority="750" id="yeu-Uf-cat">
<rect key="frame" x="0.0" y="14" width="46" height="32"/>
Expand Down Expand Up @@ -157,11 +157,9 @@ DQ
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="0Jl-d3-6gn"/>
<toolbarItem reference="J90-T3-Kgn"/>
<toolbarItem reference="yMl-8L-h3M"/>
<toolbarItem reference="J90-T3-Kgn"/>
<toolbarItem reference="IIh-6i-MIz"/>
<toolbarItem reference="0Jl-d3-6gn"/>
</defaultToolbarItems>
</toolbar>
<connections>
Expand Down
19 changes: 14 additions & 5 deletions Soduto/Base.lproj/WelcomeWindow.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="welcomeBackground" id="tek-XU-n4o"/>
</imageView>
<visualEffectView wantsLayer="YES" appearanceType="vibrantDark" fixedFrame="YES" blendingMode="withinWindow" material="ultraDark" state="active" translatesAutoresizingMaskIntoConstraints="NO" id="tTi-lY-RjK">
<visualEffectView wantsLayer="YES" appearanceType="vibrantDark" blendingMode="withinWindow" material="ultraDark" state="active" translatesAutoresizingMaskIntoConstraints="NO" id="tTi-lY-RjK">
<rect key="frame" x="0.0" y="0.0" width="560" height="350"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pHn-2N-2sT">
<button wantsLayer="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pHn-2N-2sT">
<rect key="frame" x="209" y="13" width="142" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="128" id="QUg-1b-2N8"/>
</constraints>
<buttonCell key="cell" type="push" title="Quick Setup" bezelStyle="rounded" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" inset="2" id="91x-gB-fj6">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -89,6 +90,10 @@
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="pHn-2N-2sT" firstAttribute="centerX" secondItem="tTi-lY-RjK" secondAttribute="centerX" id="V8B-gH-i1O"/>
<constraint firstAttribute="bottom" secondItem="pHn-2N-2sT" secondAttribute="bottom" constant="20" symbolic="YES" id="jfL-eH-oFJ"/>
</constraints>
<ciFilter key="compositingFilter" name="CILightenBlendMode">
<configuration>
<null key="inputBackgroundImage"/>
Expand All @@ -99,8 +104,12 @@
</subviews>
<constraints>
<constraint firstItem="bRT-wU-evQ" firstAttribute="top" secondItem="YZH-Gg-XwB" secondAttribute="top" id="C4n-cJ-tII"/>
<constraint firstItem="tTi-lY-RjK" firstAttribute="leading" secondItem="bRT-wU-evQ" secondAttribute="leading" id="HC3-S3-VpL"/>
<constraint firstAttribute="trailing" secondItem="bRT-wU-evQ" secondAttribute="trailing" id="SAU-XU-UKK"/>
<constraint firstAttribute="bottom" secondItem="bRT-wU-evQ" secondAttribute="bottom" id="U7f-3X-BdU"/>
<constraint firstItem="tTi-lY-RjK" firstAttribute="bottom" secondItem="bRT-wU-evQ" secondAttribute="bottom" id="Uxw-PE-8X1"/>
<constraint firstItem="tTi-lY-RjK" firstAttribute="top" secondItem="bRT-wU-evQ" secondAttribute="top" id="l8X-VC-ip2"/>
<constraint firstItem="tTi-lY-RjK" firstAttribute="trailing" secondItem="bRT-wU-evQ" secondAttribute="trailing" id="tSg-ai-xWJ"/>
<constraint firstItem="bRT-wU-evQ" firstAttribute="leading" secondItem="YZH-Gg-XwB" secondAttribute="leading" id="taT-BW-yPR"/>
</constraints>
</view>
Expand Down Expand Up @@ -648,7 +657,7 @@ Don't worry if you couldn't setup all your devices right now — you can always
</scene>
</scenes>
<resources>
<image name="androidIcon" width="512" height="512"/>
<image name="androidIcon" width="64" height="64"/>
<image name="kdeConnectIcon" width="64" height="64"/>
<image name="linuxIcon" width="64" height="64"/>
<image name="macOSIcon" width="64" height="64"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,8 @@ public class NotificationsService: Service, UserNotificationActionHandler {
for action in actions! {
/// Don't show if there's a copy action from "Messages" app and instead copy it to clipboard automatically
if action.starts(with: "Copy") && appName == "Messages" {
let otp = action.replacingOccurrences(of: "\"", with: "").split(separator: " ")[1]
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(String(otp), forType: .string)
/// Copy OTP to clipboard
self.copyOTP(from: action)
} else {
notificationActions.append(UNNotificationAction(identifier: action, title: action))
}
Expand Down Expand Up @@ -418,6 +417,22 @@ public class NotificationsService: Service, UserNotificationActionHandler {
_ = self.notificationIds[device.id]?.remove(id)
}

private func copyOTP(from string:String) {
let regex = try! NSRegularExpression(pattern: #"Copy "(.*?)""#, options: [])
if let match = regex.firstMatch(in: string, options: [], range: NSRange(string.startIndex..., in: string)) {
let numberRange = Range(match.range(at: 1), in: string)!
let number = String(string[numberRange])

// Remove non-digit characters from the number
let nonDigitCharacters = CharacterSet.decimalDigits.inverted
let otp = number.components(separatedBy: nonDigitCharacters).joined()

let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(otp, forType: .string)
}
}

}


Expand Down
2 changes: 1 addition & 1 deletion Soduto/Services/ShareService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import UserNotifications
public class ShareService: NSObject, Service, DownloadTaskDelegate, UserNotificationActionHandler, NSDraggingDestination {

let un = UNUserNotificationCenter.current()
let notificationIconPath = Bundle.main.path(forResource: "AirDrop", ofType: ".png")
let notificationIconPath = Bundle.main.pathForImageResource(NSImage.Name("AirDrop"))
let connectedDevices = AppDelegate.shared().validDevices

// MARK: Types
Expand Down
4 changes: 2 additions & 2 deletions Soduto/Services/TelephonyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public class TelephonyService: Service, UserNotificationActionHandler {
notification.title = "Incoming call from \(contactName)"
notification.subtitle = device.name

let notificationIconPath = Bundle.main.path(forResource: "Phone", ofType: ".png")
let notificationIconPath = Bundle.main.pathForImageResource(NSImage.Name("Phone"))
if (notificationIconPath != nil) {
let notificationIconURL = URL(fileURLWithPath: notificationIconPath!)
do {
Expand Down Expand Up @@ -370,7 +370,7 @@ public class TelephonyService: Service, UserNotificationActionHandler {
notification.title = "SMS from \(contactName) | \(device.name)"
notification.body = messageBody
notification.sound = UNNotificationSound.default()
let notificationIconPath = Bundle.main.path(forResource: "Message", ofType: ".png")
let notificationIconPath = Bundle.main.pathForImageResource(NSImage.Name("Message"))
if (notificationIconPath != nil) {
let notificationIconURL = URL(fileURLWithPath: notificationIconPath!)
do {
Expand Down

0 comments on commit 78d5f33

Please sign in to comment.