Skip to content

Commit

Permalink
feat: vision pro (#120)
Browse files Browse the repository at this point in the history
* feat: visionos

* feat: visionos

* feat: visionos

* feat: visionos
  • Loading branch information
AugustDev authored May 27, 2024
1 parent b15697f commit 6bf1414
Show file tree
Hide file tree
Showing 45 changed files with 482 additions and 330 deletions.
114 changes: 63 additions & 51 deletions Enchanted.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "833fa47aa42a8385a50e6f20c5125e66acefe26c9777986dddce89968d1daceb",
"originHash" : "2ecdf9d081540d56a3d35c3ac234eabac50668e7cc364d29a44a05e51449bba1",
"pins" : [
{
"identity" : "activityindicatorview",
Expand All @@ -15,17 +15,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "723fa5a6c65812aec4a0d7cc432ee198883b6e00",
"version" : "5.9.0"
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
"version" : "5.9.1"
}
},
{
"identity" : "keyboardshortcuts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sindresorhus/KeyboardShortcuts",
"state" : {
"revision" : "09e4a10ed6b65b3a40fe07b6bf0c84809313efc4",
"version" : "2.0.0"
"revision" : "2e5f15581fefb821d4b366e57d817be8bf12aa58",
"version" : "2.0.1"
}
},
{
Expand Down Expand Up @@ -67,10 +67,10 @@
{
"identity" : "splash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/Splash",
"location" : "https://github.com/AugustDev/Splash",
"state" : {
"revision" : "7f4df436eb78fe64fe2c32c58006e9949fa28ad8",
"version" : "0.16.0"
"branch" : "master",
"revision" : "c31eba0866102be9be29391dac641ecb46795702"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.ConcurrencyDebug 1"
argument = "-com.apple.CoreData.ConcurrencyDebug 0"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>Enchanted.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"filename" : "vision-back.png",
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
17 changes: 17 additions & 0 deletions Enchanted/Assets.xcassets/AppIcon.solidimagestack/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.solidimagestacklayer"
},
{
"filename" : "Middle.solidimagestacklayer"
},
{
"filename" : "Back.solidimagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"filename" : "vision-front.png",
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"filename" : "vision-front.png",
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
29 changes: 29 additions & 0 deletions Enchanted/Extensions/AVSpeechSynthesisVoice+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// AVSpeechSynthesisVoice+Extension.swift
// Enchanted
//
// Created by Augustinas Malinauskas on 27/05/2024.
//

import Foundation
import AVFoundation

extension AVSpeechSynthesisVoice {
var prettyName: String {
let name = self.name
if name.lowercased().contains("default") || name.lowercased().contains("premium") || name.lowercased().contains("enhanced") {
return name
}

let qualityString = {
switch self.quality.rawValue {
case 1: return "Default"
case 2: return "Enhanced"
case 3: return "Premium"
default: return "Unknown"
}
}()

return "\(name) (\(qualityString))"
}
}
24 changes: 24 additions & 0 deletions Enchanted/Extensions/Image+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Image+Extension.swift
// Enchanted
//
// Created by Augustinas Malinauskas on 27/05/2024.
//

import SwiftUI

#if os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
extension Image {
init?(data: Data) {
guard let uiImage = UIImage(data: data) else { return nil }
self.init(uiImage: uiImage)
}
}
#elseif os(macOS)
extension Image {
init?(data: Data) {
guard let nsImage = NSImage(data: data) else { return nil }
self.init(nsImage: nsImage)
}
}
#endif
2 changes: 1 addition & 1 deletion Enchanted/Extensions/KeyboardReadable+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension KeyboardReadable {
.eraseToAnyPublisher()
}
}
#elseif os(macOS)
#elseif os(macOS) || os(visionOS)
/// Mock protocol
protocol KeyboardReadable {}
#endif
3 changes: 2 additions & 1 deletion Enchanted/Extensions/SplashSyntaxHighlighter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
//

import MarkdownUI
import Splash
import SwiftUI
import Splash


struct SplashCodeSyntaxHighlighter: CodeSyntaxHighlighter {
private let syntaxHighlighter: SyntaxHighlighter<TextOutputFormat>
Expand Down
2 changes: 1 addition & 1 deletion Enchanted/Extensions/UIImage+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

#if os(iOS)
#if os(iOS) || os(visionOS)
extension UIImage {
func convertImageToBase64String() -> String {
return self.jpegData(compressionQuality: 1)?.base64EncodedString() ?? ""
Expand Down
18 changes: 17 additions & 1 deletion Enchanted/Extensions/View+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension View {

renderer.scale = displayScale

#if os(iOS)
#if os(iOS) || os(visionOS)
let image = renderer.uiImage
#elseif os(macOS)
let image = renderer.nsImage
Expand All @@ -54,6 +54,22 @@ extension View {
}
}

extension View {
/// Applies the given transform if the given condition evaluates to `true`.
/// - Parameters:
/// - condition: The condition to evaluate.
/// - transform: The transform to apply to the source `View`.
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`.
/// https://www.avanderlee.com/swiftui/conditional-view-modifier/
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
if condition {
transform(self)
} else {
self
}
}
}

struct GradientForegroundStyle: ViewModifier {
func body(content: Content) -> some View {
content.foregroundStyle(
Expand Down
4 changes: 2 additions & 2 deletions Enchanted/Services/Clipboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import UIKit
#endif


class Clipboard {
final class Clipboard: Sendable {
static let shared = Clipboard()

func setString(_ message: String) {
Expand Down Expand Up @@ -42,7 +42,7 @@ class Clipboard {
}

func getText() -> String? {
#if os(iOS)
#if os(iOS) || os(visionOS)
return UIPasteboard.general.string
#elseif os(macOS)
return NSPasteboard.general.string(forType: .string)
Expand Down
2 changes: 1 addition & 1 deletion Enchanted/Services/HapticsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Haptics: @unchecked Sendable {
play(.medium)
}
}
#elseif os(macOS)
#else
class Haptics {
static let shared = Haptics()
func lightTap() {}
Expand Down
15 changes: 12 additions & 3 deletions Enchanted/Services/SpeechService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SpeechSynthesizerDelegate: NSObject, AVSpeechSynthesizerDelegate {
override init() {
super.init()
synthesizer.delegate = delegate
voices = listAllVoices()
fetchVoices()
}

func getVoiceIdentifier() -> String? {
Expand Down Expand Up @@ -103,10 +103,19 @@ class SpeechSynthesizerDelegate: NSObject, AVSpeechSynthesizerDelegate {
}


func listAllVoices() -> [AVSpeechSynthesisVoice] {
func fetchVoices() {
let voices = AVSpeechSynthesisVoice.speechVoices().sorted { (firstVoice: AVSpeechSynthesisVoice, secondVoice: AVSpeechSynthesisVoice) -> Bool in
return firstVoice.quality.rawValue > secondVoice.quality.rawValue
}
return voices

/// prevent state refresh if there are no new elements
let diff = self.voices.elementsEqual(voices, by: { $0.identifier == $1.identifier })
if diff {
return
}

DispatchQueue.main.async {
self.voices = voices
}
}
}
6 changes: 6 additions & 0 deletions Enchanted/Stores/AppStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import Foundation
import Combine
import SwiftUI

enum AppState {
case chat
case voice
}

@Observable
final class AppStore {
static let shared = AppStore()
Expand All @@ -19,6 +24,7 @@ final class AppStore {
@MainActor var isReachable: Bool = true
@MainActor var notifications: [NotificationMessage] = []
@MainActor var menuBarIcon: String? = nil
var appState: AppState = .chat

init() {
if let storedIntervalString = UserDefaults.standard.string(forKey: "pingInterval") {
Expand Down
6 changes: 4 additions & 2 deletions Enchanted/UI/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import SwiftUI

#if os(iOS)
#if os(iOS) || os(visionOS)
typealias PlatformImage = UIImage
#elseif os(macOS)
#else
typealias PlatformImage = NSImage
#endif

//Image(nsImage: nsImage)
Loading

0 comments on commit 6bf1414

Please sign in to comment.