Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
@@ -0,0 +1,19 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "MessageHaptics",
module_name = "MessageHaptics",
srcs = glob([
"Sources/**/*.swift",
]),
copts = [
"-warnings-as-errors",
],
deps = [
"//submodules/Display",
"//submodules/SSignalKit/SwiftSignalKit",
],
visibility = [
"//visibility:public",
],
)
@@ -0,0 +1,77 @@
import Foundation
import Display
import SwiftSignalKit
private let firstImpactTime: Double = 0.4
private let secondImpactTime: Double = 0.6
public final class CoffinHaptic: EmojiHaptic {
private var hapticFeedback = HapticFeedback()
private var timer: SwiftSignalKit.Timer?
private var time: Double = 0.0
public var enabled: Bool = false {
didSet {
if !self.enabled {
self.reset()
}
}
}
public var active: Bool {
return self.timer != nil
}
public init() {
}
private func reset() {
if let timer = self.timer {
self.time = 0.0
timer.invalidate()
self.timer = nil
}
}
private func beat(time: Double) {
let epsilon = 0.1
if fabs(firstImpactTime - time) < epsilon || fabs(secondImpactTime - time) < epsilon {
self.hapticFeedback.impact(.heavy)
}
}
public func start(time: Double) {
self.hapticFeedback.prepareImpact()
if time > firstImpactTime {
return
}
let startTime: Double = 0.0
let block = { [weak self] in
guard let strongSelf = self, strongSelf.enabled else {
return
}
strongSelf.time = startTime
strongSelf.beat(time: startTime)
strongSelf.timer = SwiftSignalKit.Timer(timeout: 0.2, repeat: true, completion: { [weak self] in
guard let strongSelf = self, strongSelf.enabled else {
return
}
strongSelf.time += 0.2
strongSelf.beat(time: strongSelf.time)
if strongSelf.time > secondImpactTime {
strongSelf.reset()
strongSelf.time = 0.0
strongSelf.timer?.invalidate()
strongSelf.timer = nil
}
}, queue: Queue.mainQueue())
strongSelf.timer?.start()
}
block()
}
}
@@ -0,0 +1,99 @@
import Foundation
import Display
import SwiftSignalKit
public protocol EmojiHaptic {
var enabled: Bool { get set }
var active: Bool { get }
func start(time: Double)
}
public final class HeartbeatHaptic: EmojiHaptic {
private var hapticFeedback = HapticFeedback()
private var timer: SwiftSignalKit.Timer?
private var time: Double = 0.0
public var enabled: Bool = false {
didSet {
if !self.enabled {
self.reset()
}
}
}
public var active: Bool {
return self.timer != nil
}
public init() {
}
private func reset() {
if let timer = self.timer {
self.time = 0.0
timer.invalidate()
self.timer = nil
}
}
private func beat(time: Double) {
let epsilon = 0.1
if fabs(0.0 - time) < epsilon || fabs(1.0 - time) < epsilon || fabs(2.0 - time) < epsilon {
self.hapticFeedback.impact(.medium)
} else if fabs(0.2 - time) < epsilon || fabs(1.2 - time) < epsilon || fabs(2.2 - time) < epsilon {
self.hapticFeedback.impact(.light)
}
}
public func start(time: Double) {
self.hapticFeedback.prepareImpact()
if time > 2.0 {
return
}
var startTime: Double = 0.0
var delay: Double = 0.0
if time > 0.0 {
if time <= 1.0 {
startTime = 1.0
} else if time <= 2.0 {
startTime = 2.0
}
}
delay = max(0.0, startTime - time)
let block = { [weak self] in
guard let strongSelf = self, strongSelf.enabled else {
return
}
strongSelf.time = startTime
strongSelf.beat(time: startTime)
strongSelf.timer = SwiftSignalKit.Timer(timeout: 0.2, repeat: true, completion: { [weak self] in
guard let strongSelf = self, strongSelf.enabled else {
return
}
strongSelf.time += 0.2
strongSelf.beat(time: strongSelf.time)
if strongSelf.time > 2.2 {
strongSelf.reset()
strongSelf.time = 0.0
strongSelf.timer?.invalidate()
strongSelf.timer = nil
}
}, queue: Queue.mainQueue())
strongSelf.timer?.start()
}
if delay > 0.0 {
Queue.mainQueue().after(delay, block)
} else {
block()
}
}
}
@@ -0,0 +1,76 @@
import Foundation
import Display
import SwiftSignalKit
private let impactTime: Double = 0.6
public final class PeachHaptic: EmojiHaptic {
private var hapticFeedback = HapticFeedback()
private var timer: SwiftSignalKit.Timer?
private var time: Double = 0.0
public var enabled: Bool = false {
didSet {
if !self.enabled {
self.reset()
}
}
}
public var active: Bool {
return self.timer != nil
}
public init() {
}
private func reset() {
if let timer = self.timer {
self.time = 0.0
timer.invalidate()
self.timer = nil
}
}
private func beat(time: Double) {
let epsilon = 0.1
if fabs(impactTime - time) < epsilon {
self.hapticFeedback.impact(.heavy)
}
}
public func start(time: Double) {
self.hapticFeedback.prepareImpact()
if time > impactTime {
return
}
let startTime: Double = 0.0
let block = { [weak self] in
guard let strongSelf = self, strongSelf.enabled else {
return
}
strongSelf.time = startTime
strongSelf.beat(time: startTime)
strongSelf.timer = SwiftSignalKit.Timer(timeout: 0.2, repeat: true, completion: { [weak self] in
guard let strongSelf = self, strongSelf.enabled else {
return
}
strongSelf.time += 0.2
strongSelf.beat(time: strongSelf.time)
if strongSelf.time > impactTime {
strongSelf.reset()
strongSelf.time = 0.0
strongSelf.timer?.invalidate()
strongSelf.timer = nil
}
}, queue: Queue.mainQueue())
strongSelf.timer?.start()
}
block()
}
}