Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 30, 2024
1 parent 02f48c6 commit 636ffa1
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 142 deletions.
12 changes: 4 additions & 8 deletions Actions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
E38BB1BF2B31CCED000C9B32 /* SwiftBluetooth in Frameworks */ = {isa = PBXBuildFile; productRef = E38BB1BE2B31CCED000C9B32 /* SwiftBluetooth */; };
E3963A5A292CAF9F00210AC2 /* RemoveDuplicatesFromList.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3EC2DC328D215A100A88E25 /* RemoveDuplicatesFromList.swift */; };
E39692CA2AE130F90030AE56 /* IsShakingDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = E39692C92AE130F90030AE56 /* IsShakingDevice.swift */; };
E3A246852AFEC35100453E9C /* Authenticate2.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A246842AFEC35100453E9C /* Authenticate2.swift */; };
E3AB2D8B29F840B900ED2913 /* GetActionsVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3AB2D8A29F840B900ED2913 /* GetActionsVersion.swift */; };
E3AFA5C32A9B58160044E2F1 /* Boolean.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3AFA5C22A9B58160044E2F1 /* Boolean.swift */; };
E3B8FD1629ED376F001249CF /* TruncateNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3B8FD1529ED376F001249CF /* TruncateNumber.swift */; };
Expand Down Expand Up @@ -272,7 +271,6 @@
E39692C92AE130F90030AE56 /* IsShakingDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsShakingDevice.swift; sourceTree = "<group>"; };
E39DC11A29A54E27004F4FB8 /* OpenURLsWithApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OpenURLsWithApp.swift; path = "Intents Extension/Actions/OpenURLsWithApp.swift"; sourceTree = SOURCE_ROOT; };
E39F4776272D516E00B99CB0 /* Actions.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Actions.entitlements; sourceTree = "<group>"; };
E3A246842AFEC35100453E9C /* Authenticate2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authenticate2.swift; sourceTree = "<group>"; };
E3A85FE428E94E7300F423F1 /* FormatPersonName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormatPersonName.swift; sourceTree = "<group>"; };
E3AB2D8A29F840B900ED2913 /* GetActionsVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetActionsVersion.swift; sourceTree = "<group>"; };
E3AFA5C22A9B58160044E2F1 /* Boolean.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Boolean.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -404,7 +402,6 @@
children = (
E352420928F6EEDE00A957A7 /* AskForText.swift */,
E34AB51528F58B500082AE78 /* Authenticate.swift */,
E3A246842AFEC35100453E9C /* Authenticate2.swift */,
E3EA7D7A28EAC2210043F782 /* BlurImages.swift */,
E3DB885528E727E200FEE8D6 /* ChooseFromListExtended.swift */,
E3722CEC2ACDE28D0007316D /* CombineVideos.swift */,
Expand Down Expand Up @@ -903,7 +900,6 @@
E33D4BA62744238300CC7A8A /* AppState.swift in Sources */,
E3CF4F9828FDA7EB00BD88D5 /* GenerateRandomData.swift in Sources */,
E3CB44A828D79EF90031D55F /* ScanQRCodesInImage.swift in Sources */,
E3A246852AFEC35100453E9C /* Authenticate2.swift in Sources */,
E303EED329529D0B007BE918 /* GetDefaultPrinter.swift in Sources */,
E3DB885228E6EFBB00FEE8D6 /* ScanDocuments.swift in Sources */,
E3B8FD1929ED4305001249CF /* GetTitleOfURL.swift in Sources */,
Expand Down Expand Up @@ -1072,8 +1068,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.4;
MACOSX_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1133,8 +1129,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.4;
MACOSX_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
2 changes: 1 addition & 1 deletion Intents Extension/Actions/IsOnline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ struct IsOnlineIntent: AppIntent {
}

func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
.result(value: Reachability.isOnlineExtensive())
.result(value: await Reachability.isOnline())
}
}
93 changes: 91 additions & 2 deletions Shared/Actions/Authenticate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,103 @@ import AppIntents
import LocalAuthentication
import SwiftUI

struct Authenticate: AppIntent {
struct Authenticate2: AppIntent {
static let title: LocalizedStringResource = "Authenticate"

static let description = IntentDescription(
"""
Authenticate the user using Face ID or Touch ID.
IMPORTANT: Use the “Authenticate (New)” action instead.
Unlike the old authenticate action, this one directly returns a boolean for whether the authentication succeeded.
On iOS & visionOS, it needs to momentarily open the Actions app to be able to present the authentication prompt. Afterwards, it goes back to the Shortcuts app. If you were running the shortcut in the background, there is unfortunately no way to go back to the previous app you were in, other than opening the app again from the shortcut.
""",
categoryName: "Device",
searchKeywords: [
"face id",
"touch id",
"faceid",
"touchid",
"biometry",
"password",
"passcode"
],
resultValueName: "Is Authenticated"
)

#if canImport(UIKit)
static let openAppWhenRun = true
#endif

@Parameter(
title: "Open When Finished",
description: "If provided, opens the URL instead of the Shortcuts app when finished."
)
var openURL: URL?

@Parameter(
title: "Timeout (seconds)",
description: "When it times out, it returns “false” as if the authentication failed. On iOS & visionOS, the max timeout is 25 seconds, and it will always timeout after that even if this settings is not specified."
)
var timeout: Double?

@MainActor
func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
// Work around issue with it not showing. (iOS 17.1)
try await Task.sleep(for: .seconds(0.1))

#if canImport(UIKit)
AppState.shared.isFullscreenOverlayPresented = true

defer {
Task {
try? await Task.sleep(for: .seconds(2))
AppState.shared.isFullscreenOverlayPresented = false
}
}

if timeout == nil {
timeout = 25
}
#endif

let result: Bool = await {
do {
let context = LAContext()

if let timeout {
delay(.seconds(timeout)) {
context.invalidate()
}
}

try await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Authenticate the shortcut")
return true
} catch {
return false
}
}()

if let openURL {
try await openURL.openAsyncOrOpenShortcutsApp()
} else {
#if canImport(UIKit)
ShortcutsApp.open()
#endif
}

return .result(value: result)
}
}

struct Authenticate: AppIntent {
static let title: LocalizedStringResource = "Authenticate (Legacy)"

static let description = IntentDescription(
"""
Authenticate the user using Face ID or Touch ID.
IMPORTANT: Use the “Authenticate” action instead.
IMPORTANT: The result is copied to the clipboard as the text “true” or “false”. Add the “Wait to Return” and “Get Clipboard” actions after this one. Use the “If” action to decide what to do with the result.
Expand Down
92 changes: 0 additions & 92 deletions Shared/Actions/Authenticate2.swift

This file was deleted.

2 changes: 2 additions & 0 deletions Shared/Actions/ChooseFromListExtended.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct ChooseFromListExtendedIntent: AppIntent {
IMPORTANT: Add the “Wait to Return” and “Get Clipboard” actions after this one.
NOTE: It will convert each input into a string, so some types may not work properly.
Note: If you get the error “The operation failed because Shortcuts couldn't convert from Text to NSString.”, just change the preview to show a list view instead. This is a bug in the Shortcuts app.
""",
categoryName: "Utility",
Expand Down
35 changes: 18 additions & 17 deletions Shared/Actions/CreateMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct CreateMenuItem: AppIntent {
You can later use one or more of these menu items in a “Choose from List” action.
Add an “Add to Variable” action below this one to populate a list and then use that variable in the “Choose From List” action.
NOTE: If you pass in the color as a variable, you may have to write it in lowercase, “red” instead of “Red”, because of a iOS bug.
""",
categoryName: "Miscellaneous",
searchKeywords: [
Expand Down Expand Up @@ -245,24 +247,23 @@ enum MenuItemStyle: String, AppEnum {

static let typeDisplayRepresentation: TypeDisplayRepresentation = "Menu Item Style"

// TODO: Make them uppercase again when the bug is fixed.
static let caseDisplayRepresentations: [Self: DisplayRepresentation] = [
.default: "default", // It's lowercase so users would use that in variables as the variable text has to match the enum case for it to work.
.red: "red",
.orange: "orange",
.yellow: "yellow",
.green: "green",
.mint: "mint",
.teal: "teal",
.cyan: "cyan",
.blue: "blue",
.purple: "purple",
.pink: "pink",
.brown: "brown",
.white: "white",
.gray: "gray",
.black: "black",
.clear: "clear"
.default: "Default",
.red: "Red",
.orange: "Orange",
.yellow: "Yellow",
.green: "Green",
.mint: "Mint",
.teal: "Teal",
.cyan: "Cyan",
.blue: "Blue",
.purple: "{urple",
.pink: "{ink",
.brown: "Brown",
.white: "White",
.gray: "Gray",
.black: "Black",
.clear: "Clear"
]

func color(isBackground: Bool = false) -> Color {
Expand Down
4 changes: 4 additions & 0 deletions Shared/Actions/GetBluetoothDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ struct GetBluetoothDevice: AppIntent {
NOTE: You need to have been connected to the device at least once before.
NOTE: It only works for BLE (Bluetooth Low Energy) peripherals, not legacy Bluetooth peripherals.
NOTE: Bluetooth has a lot of limitations on iOS and if this action doesn't work for you, it's unfortunately unlikely there is anything I can do about it.
NOTE: The `transmitPowerLevel` property is not provided for this action.
NOTE: The RSSI and signal strength are available for only one of the two AirPods. If it shows RSSI of 0, try the identifier of the other AirPods device.
Expand Down
2 changes: 2 additions & 0 deletions Shared/Actions/GetBluetoothDevices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct GetBluetoothDevices: AppIntent {
"""
Returns the Bluetooth devices in range.
DO NOT COPY THE IDENTIFIER FROM THE PREVIEW. Shortcuts sometimes adds an extra dash. Instead, fetch the "identifier" property.
On iOS & visionOS, it has to open the main app while scanning because they do not allow scanning for arbitrary devices in the background.
Use the “Get Bluetooth Device” action to check for a specific device.
Expand Down
Loading

0 comments on commit 636ffa1

Please sign in to comment.