Skip to content

Commit

Permalink
Update v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Feb 8, 2023
1 parent c344f0e commit cad3e7e
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Foundation/Source/Sources/Source/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class Source: ObservableObject, Identifiable, Equatable {
DispatchQueue.global().async {
self.populateInstanceInfo()
}
DispatchQueue.global().async {
DispatchQueue.global().asyncAfter(deadline: .now() + 2) {
self.timeline.requestUpdate(direction: .newer)
self.bookmark.reloadBookmark()
self.notifications.fetchNotification(direction: .new)
Expand Down
10 changes: 5 additions & 5 deletions Kimis.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1857,8 +1857,8 @@
CODE_SIGN_ENTITLEMENTS = Kimis/Kimis.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = M4Z5DVY94F;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 6CMYQQFFT8;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Kimis/Info.plist;
Expand All @@ -1875,7 +1875,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = wiki.qaq.kimis.inhouse;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand All @@ -1896,7 +1896,7 @@
CODE_SIGN_ENTITLEMENTS = Kimis/Kimis.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 6CMYQQFFT8;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1914,7 +1914,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = as.wiki.qaq.kimis;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
6 changes: 0 additions & 6 deletions Kimis/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_: UIApplication, didDiscardSceneSessions _: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

func applicationWillTerminate(_ application: UIApplication) {
print("[*] \(application) \(#function)")
// clean up
Expand Down
4 changes: 0 additions & 4 deletions Kimis/App/AppTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import BackgroundTasks
import Bugsnag
import Foundation
import UIKit

Expand All @@ -24,9 +23,6 @@ enum AppTask: String, CaseIterable, Codable {
print("[*] success fully scheduled task \(AppTask.fetchNotifications.rawValue)")
} catch {
print("[?] could not schedule app refresh: \(error)")
#if !DEBUG
Bugsnag.notifyError(error)
#endif
}
}

Expand Down
36 changes: 10 additions & 26 deletions Kimis/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Lakr Aream on 2022/11/14.
//

import AVFoundation
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
Expand All @@ -29,32 +30,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window.makeKeyAndVisible()
}

func sceneDidDisconnect(_: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}

func sceneDidBecomeActive(_: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
Account.shared.requestStatusUpdate()
}

func sceneWillResignActive(_: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}

func sceneWillEnterForeground(_: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}

func sceneDidEnterBackground(_: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
do {
_ = try AVAudioSession.sharedInstance().setCategory(
.playback,
mode: .default,
options: .mixWithOthers
)
} catch {
print(error.localizedDescription)
}
}
}
1 change: 1 addition & 0 deletions Kimis/Backend/Account/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ final class Account {
func delete(receiptID: LoginChallengeReceipt.ID) {
assert(Thread.isMainThread)
accounts.removeValue(forKey: receiptID)
cleanUp()
if source?.receiptId == receiptID { deactivateCurrent() }
}

Expand Down
9 changes: 2 additions & 7 deletions Kimis/Backend/TextParser/Render/TextParser+Username.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import Foundation
import UIKit

extension TextParser {
func replaceAttributeForUsername(with string: NSMutableAttributedString, defaultHost: String? = nil) {
replaceAttributeForUnifiedUsername(with: string)
replaceAttributeForSimpleUsername(with: string, defaultHost: defaultHost)
}

private func replaceAttributeForSimpleUsername(with string: NSMutableAttributedString, defaultHost: String? = nil) {
func replaceAttributeForSimpleUsername(with string: NSMutableAttributedString, defaultHost: String? = nil) {
enumeratedModifyingWithRegex(withinString: string, matching: .username) { string in
guard !string.attributes.keys.contains(.link) else { return nil }
var username = string.string
Expand All @@ -28,7 +23,7 @@ extension TextParser {
}
}

private func replaceAttributeForUnifiedUsername(with string: NSMutableAttributedString) {
func replaceAttributeForUnifiedUsername(with string: NSMutableAttributedString) {
enumeratedModifyingWithRegex(withinString: string, matching: .unifiedUsername) { string in
guard !string.attributes.keys.contains(.link) else { return nil }
guard let message = string.string.base64Encoded else { return nil }
Expand Down
4 changes: 2 additions & 2 deletions Kimis/Backend/TextParser/TextParser+RegEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Foundation
extension TextParser {
enum RegEx: String, CaseIterable {
case username = #"(?<=(^|\s))@([A-Za-z0-9_])+(?=($|\s))"#
case unifiedUsername = #"(?<=(^|\s))@([A-Za-z0-9_])+?@([A-Za-z0-9\-\.]+)\.([A-Za-z]+)(?=($|\s))"#
case unifiedUsername = #"@([A-Za-z0-9_])+?@([A-Za-z0-9\-\.]+)\.([A-Za-z]+)(?=($|\s))"#

case emoji = #":[A-Za-z0-9._]+:"#
case hashtag = #"#[\u4E00-\u9FCCA-Za-z0-9\.]+"#
case hashtag = #"#[\u4E00-\u9FCCA-Za-z0-9_\.]+"#
case repliesMentionPrefix = #"^((@([A-Za-z0-9_])+?@([A-Za-z0-9\-\.]+)\.([A-Za-z]+)) )+"#
case mail = #"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}"#
case link = #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&,//=]*)"#
Expand Down
3 changes: 2 additions & 1 deletion Kimis/Backend/TextParser/TextParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ extension TextParser {
attributeFullFill(string)
replaceAllAttributeForMarkdownSyntax(with: string)
replaceAttributeForHashtag(with: string)
replaceAttributeForUnifiedUsername(with: string)
replaceAttributeForEmails(with: string)
replaceAttributeForUsername(with: string, defaultHost: defaultHost)
replaceAttributeForSimpleUsername(with: string, defaultHost: defaultHost)
replaceAttributeForLinks(with: string)
replaceTinyEmoji(from: string, defaultHost: defaultHost)
while string.string.hasPrefix(" ") { string.deleteCharacters(in: NSRange(location: 0, length: 1)) }
Expand Down
1 change: 1 addition & 0 deletions Kimis/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</dict>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>fetch</string>
<string>processing</string>
</array>
Expand Down
1 change: 1 addition & 0 deletions Kimis/Interface/Component/Misc/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TextView: SubviewAttachingTextView, UITextViewDelegate {
textContainerInset = .zero
textContainer.lineBreakMode = .byTruncatingTail
isScrollEnabled = false
clipsToBounds = false

textDragInteraction?.isEnabled = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class NoteTableView: TableView {
if layoutWidth != bounds.width {
renderVisibleCellAndUpdate()
layoutWidth = bounds.width
} else {
reconfigureVisibleCells()
}
super.layoutSubviews()
}
Expand All @@ -85,8 +87,13 @@ class NoteTableView: TableView {
defer { if locked {
dataUpdateLock.unlock()
} }
let visibleIndexPaths = indexPathsForVisibleRows ?? []
beginUpdates()
reconfigureVisibleCells()
endUpdates()
}

func reconfigureVisibleCells() {
let visibleIndexPaths = indexPathsForVisibleRows ?? []
for indexPath in visibleIndexPaths {
guard let cell = cellForRow(at: indexPath) as? NoteCell else {
continue
Expand All @@ -96,6 +103,5 @@ class NoteTableView: TableView {
}
cell.load(data: context)
}
endUpdates()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extension TimelineTableView {
assert(DispatchQueue.isCurrent(_dataBuildQueue))

var insertContentHeight = false
var resetToTop = false
let ctx = Self.translate(rawNodes: patch.nodes)

switch patch.kind {
Expand All @@ -67,6 +68,7 @@ extension TimelineTableView {
order: patch.order,
context: ctx
)
resetToTop = true
case .insert:
patchContainer = .init(
order: patch.order,
Expand All @@ -90,7 +92,8 @@ extension TimelineTableView {
let item = DispatchWorkItem {
self.applyDataSource(
result,
insertContentHeight: insertContentHeight
insertContentHeight: insertContentHeight,
resetToTop: resetToTop
)
}
DispatchQueue.main.asyncAndWait(execute: item)
Expand Down Expand Up @@ -180,7 +183,7 @@ extension TimelineTableView {
.count
let newNotesCount = currentNotes - previousNotes
if newNotesCount > 0 {
guider?.setCountMax(newNotesCount)
guider?.setCountMax(newNotesCount, appending: true)
presentNewItemGuider()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ extension NoteTableView {
get { _realCount }
}

func setCountMax(_ cnt: Int) {
_realCount = cnt
func setCountMax(_ cnt: Int, appending: Bool = false) {
_realCount = cnt + (appending ? _realCount : 0)
}

override init(frame _: CGRect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ private final class VideoPreviewLoopedPlayerView: UIView {
}

func prepareVideo(_ videoURL: URL) {
requestMixWithOthers()
let playerItem = AVPlayerItem(url: videoURL)
self.queuePlayer = AVQueuePlayer(playerItem: playerItem)
self.playerLayer = AVPlayerLayer(player: self.queuePlayer)
Expand Down Expand Up @@ -211,22 +210,4 @@ private final class VideoPreviewLoopedPlayerView: UIView {
deinit {
unload()
}

func requestMixWithOthers() {
// aviod block main thread when syscall is blocking by AirPlay using some kinda HomePod
DispatchQueue.global().async {
do {
// this may access microphone with pop up
// guard !AVAudioSession.sharedInstance().categoryOptions.contains(.mixWithOthers)
// else { return }
_ = try AVAudioSession.sharedInstance().setCategory(
.playback,
mode: .default,
options: .mixWithOthers
)
} catch {
print(error.localizedDescription)
}
}
}
}
6 changes: 4 additions & 2 deletions Kimis/Interface/Component/NoteView/NotePreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Source
import UIKit

class NotePreview: UIView {
// # line 325, reason icon height = text height
static let hintTextLimit = 1 // <- must be 1
static let userTextLimit = 2
static let mainTextLimit = 8
static let verticalSpacing: CGFloat = 8
Expand Down Expand Up @@ -43,7 +45,7 @@ class NotePreview: UIView {
init() {
super.init(frame: .zero)

previewReason.textContainer.maximumNumberOfLines = Self.userTextLimit
previewReason.textContainer.maximumNumberOfLines = Self.hintTextLimit
userText.textContainer.maximumNumberOfLines = Self.userTextLimit
mainText.textContainer.maximumNumberOfLines = Self.mainTextLimit

Expand Down Expand Up @@ -315,7 +317,7 @@ extension NotePreview.Snapshot {

var previewResaonRect: CGRect = .zero
let previewReasonHeight = previewReasonText
.measureHeight(usingWidth: contentWidth, lineLimit: NotePreview.userTextLimit)
.measureHeight(usingWidth: contentWidth, lineLimit: NotePreview.hintTextLimit)
previewResaonRect = .init(
x: contentLeftAlign,
y: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class SettingController: ViewController {
} action: { tableView in
let alert = UIAlertController(title: "⚠️", message: "Are you sure you want to sign out?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Sign Out", style: .destructive) { _ in
if let id = Account.shared.source?.receiptId {
Account.shared.delete(receiptID: id)
}
Account.shared.deactivateCurrent()
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
Expand Down

0 comments on commit cad3e7e

Please sign in to comment.