Skip to content

Commit

Permalink
- bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed Jul 2, 2024
1 parent e7b2233 commit c550b2c
Show file tree
Hide file tree
Showing 9 changed files with 690 additions and 145 deletions.
121 changes: 121 additions & 0 deletions Telegram-Mac/Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,127 @@ public func generateDisclosureActionBoostLevelBadgeImage(text: String) -> CGImag
}
#endif


import Cocoa

func generateRoundedRectWithTailPath(rectSize: CGSize, cornerRadius: CGFloat? = nil, tailSize: CGSize = CGSize(width: 20.0, height: 9.0), tailRadius: CGFloat = 4.0, tailPosition: CGFloat? = 0.5, transformTail: Bool = true) -> NSBezierPath {
let cornerRadius: CGFloat = cornerRadius ?? rectSize.height / 2.0
let tailWidth: CGFloat = tailSize.width
let tailHeight: CGFloat = tailSize.height

let rect = CGRect(origin: CGPoint(x: 0.0, y: tailHeight), size: rectSize)

guard let tailPosition else {
let path = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius)
return path
}

let cutoff: CGFloat = 0.27

let path = NSBezierPath()
path.move(to: CGPoint(x: rect.minX, y: rect.minY + cornerRadius))

var leftArcEndAngle: CGFloat = .pi / 2.0
var leftConnectionArcRadius = tailRadius
var tailLeftHalfWidth: CGFloat = tailWidth / 2.0
var tailLeftArcStartAngle: CGFloat = -.pi / 4.0
var tailLeftHalfRadius = tailRadius

var rightArcStartAngle: CGFloat = -.pi / 2.0
var rightConnectionArcRadius = tailRadius
var tailRightHalfWidth: CGFloat = tailWidth / 2.0
var tailRightArcStartAngle: CGFloat = .pi / 4.0
var tailRightHalfRadius = tailRadius

if transformTail {
if tailPosition < 0.5 {
let fraction = max(0.0, tailPosition - 0.15) / 0.35
leftArcEndAngle *= fraction

let connectionFraction = max(0.0, tailPosition - 0.35) / 0.15
leftConnectionArcRadius *= connectionFraction

if tailPosition < cutoff {
let fraction = tailPosition / cutoff
tailLeftHalfWidth *= fraction
tailLeftArcStartAngle *= fraction
tailLeftHalfRadius *= fraction
}
} else if tailPosition > 0.5 {
let tailPosition = 1.0 - tailPosition
let fraction = max(0.0, tailPosition - 0.15) / 0.35
rightArcStartAngle *= fraction

let connectionFraction = max(0.0, tailPosition - 0.35) / 0.15
rightConnectionArcRadius *= connectionFraction

if tailPosition < cutoff {
let fraction = tailPosition / cutoff
tailRightHalfWidth *= fraction
tailRightArcStartAngle *= fraction
tailRightHalfRadius *= fraction
}
}
}

path.appendArc(withCenter: CGPoint(x: rect.minX + cornerRadius, y: rect.minY + cornerRadius),
radius: cornerRadius,
startAngle: 180,
endAngle: 180 + max(0.0001, leftArcEndAngle * 180 / .pi),
clockwise: false)

let leftArrowStart = max(rect.minX, rect.minX + rectSize.width * tailPosition - tailLeftHalfWidth - leftConnectionArcRadius)
path.appendArc(withCenter: CGPoint(x: leftArrowStart, y: rect.minY - leftConnectionArcRadius),
radius: leftConnectionArcRadius,
startAngle: 90,
endAngle: 45,
clockwise: true)

path.line(to: CGPoint(x: max(rect.minX, rect.minX + rectSize.width * tailPosition - tailLeftHalfRadius), y: rect.minY - tailHeight))

path.appendArc(withCenter: CGPoint(x: rect.minX + rectSize.width * tailPosition, y: rect.minY - tailHeight + tailRadius / 2.0),
radius: tailRadius,
startAngle: -90 + tailLeftArcStartAngle * 180 / .pi,
endAngle: -90 + tailRightArcStartAngle * 180 / .pi,
clockwise: false)

path.line(to: CGPoint(x: min(rect.maxX, rect.minX + rectSize.width * tailPosition + tailRightHalfRadius), y: rect.minY - tailHeight))

let rightArrowStart = min(rect.maxX, rect.minX + rectSize.width * tailPosition + tailRightHalfWidth + rightConnectionArcRadius)
path.appendArc(withCenter: CGPoint(x: rightArrowStart, y: rect.minY - rightConnectionArcRadius),
radius: rightConnectionArcRadius,
startAngle: 180 - 45,
endAngle: 90,
clockwise: true)

path.appendArc(withCenter: CGPoint(x: rect.minX + rectSize.width - cornerRadius, y: rect.minY + cornerRadius),
radius: cornerRadius,
startAngle: min(-0.0001, rightArcStartAngle * 180 / .pi),
endAngle: 0,
clockwise: false)

path.line(to: CGPoint(x: rect.minX + rectSize.width, y: rect.minY + rectSize.height - cornerRadius))

path.appendArc(withCenter: CGPoint(x: rect.minX + rectSize.width - cornerRadius, y: rect.minY + rectSize.height - cornerRadius),
radius: cornerRadius,
startAngle: 0,
endAngle: 90,
clockwise: false)

path.line(to: CGPoint(x: rect.minX + cornerRadius, y: rect.minY + rectSize.height))

path.appendArc(withCenter: CGPoint(x: rect.minX + cornerRadius, y: rect.minY + rectSize.height - cornerRadius),
radius: cornerRadius,
startAngle: 90,
endAngle: 180,
clockwise: false)

return path
}




func chatReplyLineDashTemplateImage(_ colors: PeerNameColors.Colors, flipped: Bool) -> CGImage? {
let radius: CGFloat = 3.0
var offset: CGFloat = 5.0
Expand Down
2 changes: 1 addition & 1 deletion Telegram-Mac/ApplicationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ final class AuthorizedApplicationContext: NSObject, SplitViewDelegate {

//showModal(with: StoryFoundListController(context: context, source: .hashtag("#telegram"), presentation: theme), for: context.window)

showModal(with: CallSettingsModalController(context.sharedContext), for: context.window)
showModal(with: Star_ReactionsController(context: context), for: context.window)

// showModal(with: Star_TransactionScreen(context: context, peer: .init(context.myPeer!), transaction: StarsContext.State.Transaction.init(id: "kqwjeflklqwkejflqwkejflqkwejflqkwejf", count: 1000, date: Int32(Date().timeIntervalSince1970), peer: StarsContext.State.Transaction.Peer.appStore)), for: context.window)
// showModal(with: FactCheckController(context: context), for: context.window)
Expand Down
122 changes: 0 additions & 122 deletions Telegram-Mac/BoostChannelModalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,128 +77,6 @@ enum BoostSubject: Equatable {



private func generateBadgePath(rectSize: CGSize, tailPosition: CGFloat = 0.5) -> CGPath {
let cornerRadius: CGFloat = rectSize.height / 2.0
let tailWidth: CGFloat = 20.0
let tailHeight: CGFloat = 9.0
let tailRadius: CGFloat = 4.0

let rect = CGRect(origin: CGPoint(x: 0.0, y: tailHeight), size: rectSize)

let path = CGMutablePath()

path.move(to: CGPoint(x: rect.minX, y: rect.minY + cornerRadius))

var leftArcEndAngle: CGFloat = .pi / 2.0
var leftConnectionArcRadius = tailRadius
var tailLeftHalfWidth: CGFloat = tailWidth / 2.0
var tailLeftArcStartAngle: CGFloat = -.pi / 4.0
var tailLeftHalfRadius = tailRadius

var rightArcStartAngle: CGFloat = -.pi / 2.0
var rightConnectionArcRadius = tailRadius
var tailRightHalfWidth: CGFloat = tailWidth / 2.0
var tailRightArcStartAngle: CGFloat = .pi / 4.0
var tailRightHalfRadius = tailRadius

if tailPosition < 0.5 {
let fraction = max(0.0, tailPosition - 0.15) / 0.35
leftArcEndAngle *= fraction

let connectionFraction = max(0.0, tailPosition - 0.35) / 0.15
leftConnectionArcRadius *= connectionFraction

if tailPosition < 0.27 {
let fraction = tailPosition / 0.27
tailLeftHalfWidth *= fraction
tailLeftArcStartAngle *= fraction
tailLeftHalfRadius *= fraction
}
} else if tailPosition > 0.5 {
let tailPosition = 1.0 - tailPosition
let fraction = max(0.0, tailPosition - 0.15) / 0.35
rightArcStartAngle *= fraction

let connectionFraction = max(0.0, tailPosition - 0.35) / 0.15
rightConnectionArcRadius *= connectionFraction

if tailPosition < 0.27 {
let fraction = tailPosition / 0.27
tailRightHalfWidth *= fraction
tailRightArcStartAngle *= fraction
tailRightHalfRadius *= fraction
}
}

path.addArc(
center: CGPoint(x: rect.minX + cornerRadius, y: rect.minY + cornerRadius),
radius: cornerRadius,
startAngle: .pi,
endAngle: .pi + leftArcEndAngle,
clockwise: true
)

let leftArrowStart = max(rect.minX, rect.minX + rectSize.width * tailPosition - tailLeftHalfWidth - leftConnectionArcRadius)
path.addArc(
center: CGPoint(x: leftArrowStart, y: rect.minY - leftConnectionArcRadius),
radius: leftConnectionArcRadius,
startAngle: .pi / 2.0,
endAngle: .pi / 4.0,
clockwise: false
)

path.addLine(to: CGPoint(x: max(rect.minX, rect.minX + rectSize.width * tailPosition - tailLeftHalfRadius), y: rect.minY - tailHeight))

path.addArc(
center: CGPoint(x: rect.minX + rectSize.width * tailPosition, y: rect.minY - tailHeight + tailRadius / 2.0),
radius: tailRadius,
startAngle: -.pi / 2.0 + tailLeftArcStartAngle,
endAngle: -.pi / 2.0 + tailRightArcStartAngle,
clockwise: true
)

path.addLine(to: CGPoint(x: min(rect.maxX, rect.minX + rectSize.width * tailPosition + tailRightHalfRadius), y: rect.minY - tailHeight))

let rightArrowStart = min(rect.maxX, rect.minX + rectSize.width * tailPosition + tailRightHalfWidth + rightConnectionArcRadius)
path.addArc(
center: CGPoint(x: rightArrowStart, y: rect.minY - rightConnectionArcRadius),
radius: rightConnectionArcRadius,
startAngle: .pi - .pi / 4.0,
endAngle: .pi / 2.0,
clockwise: false
)

path.addArc(
center: CGPoint(x: rect.minX + rectSize.width - cornerRadius, y: rect.minY + cornerRadius),
radius: cornerRadius,
startAngle: rightArcStartAngle,
endAngle: 0.0,
clockwise: true
)

path.addLine(to: CGPoint(x: rect.minX + rectSize.width, y: rect.minY + rectSize.height - cornerRadius))

path.addArc(
center: CGPoint(x: rect.minX + rectSize.width - cornerRadius, y: rect.minY + rectSize.height - cornerRadius),
radius: cornerRadius,
startAngle: 0.0,
endAngle: .pi / 2.0,
clockwise: true
)

path.addLine(to: CGPoint(x: rect.minX + cornerRadius, y: rect.minY + rectSize.height))

path.addArc(
center: CGPoint(x: rect.minX + cornerRadius, y: rect.minY + rectSize.height - cornerRadius),
radius: cornerRadius,
startAngle: .pi / 2.0,
endAngle: .pi,
clockwise: true
)

return path
}


private final class Arguments {
let context: AccountContext
Expand Down
2 changes: 1 addition & 1 deletion Telegram-Mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>265398</string>
<string>265501</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
Expand Down
8 changes: 8 additions & 0 deletions Telegram-Mac/Star_PurchaseInApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ func Star_PurschaseInApp(context: AccountContext, invoice: TelegramMediaInvoice,
text = strings().starPurchasePaidMediaSuccess(strings().starPurchaseTextInCountable(Int(state.request.count)))
}
showModalText(for: window, text: text)

switch type {
case .paidMedia:
PlayConfetti(for: window, stars: true)
default:
break
}

completion(.paid)
procced = true
close?()
Expand Down
Loading

0 comments on commit c550b2c

Please sign in to comment.