Skip to content

Commit

Permalink
New code field design (#119)
Browse files Browse the repository at this point in the history
* feat: removed all that shit about git submodules and reverted back to normal usage of SPM

* feat: implemented the pin code text field
@RobotsAndPencils, this is huge, lovin this thing!

* feat: improved menubar item design
also added a placeholder for a future "Chat Shortcut" feature
  • Loading branch information
voltangle authored Aug 7, 2022
1 parent bd8a9c3 commit ea43ab6
Show file tree
Hide file tree
Showing 15 changed files with 399 additions and 111 deletions.
18 changes: 0 additions & 18 deletions .gitmodules

This file was deleted.

4 changes: 2 additions & 2 deletions Backend/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let package = Package(
),
],
dependencies: [
.package(path: "../third-party/tdlibkit"),
.package(path: "../third-party/Resolver"),
.package(url: "https://github.com/hmlongco/Resolver.git", from: "1.0.0"),
.package(url: "https://github.com/mock-foundation/tdlibkit", from: "3.0.1-1.8.4-07b7faf6"),
.package(path: "../Utilities"),
.package(path: "../Caching"),
.package(path: "../Logs")
Expand Down
2 changes: 1 addition & 1 deletion Caching/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
targets: ["Caching"]),
],
dependencies: [
.package(path: "../third-party/GRDB.swift"),
.package(url: "https://github.com/groue/GRDB.swift.git", from: "5.26.0"),
.package(path: "../Utilities"),
.package(path: "../Logs")
],
Expand Down
143 changes: 96 additions & 47 deletions Moc.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Shared/Commands/About/AboutCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct BackportedAboutCommand: Commands {
Button {
openURL(URL(string: "moc://internal/openAbout")!)
} label: {
Image(systemName: "info.circle.fill")
Text("About Moc")
}
}
Expand Down
28 changes: 14 additions & 14 deletions Shared/Commands/AppCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import AppCenterAnalytics

struct AppCommands: Commands {
#if os(macOS)
Expand All @@ -15,32 +16,31 @@ struct AppCommands: Commands {
var body: some Commands {
#if os(macOS)
CommandGroup(after: .appInfo) {
Button("Check for updates...", action: updateManager.checkForUpdates)
.disabled(!updateManager.canCheckForUpdates)
Button(action: updateManager.checkForUpdates) {
Image(systemName: updateManager.canCheckForUpdates
? "arrow.triangle.2.circlepath"
: "exclamationmark.arrow.triangle.2.circlepath")
Text("Check for updates...")
}.disabled(!updateManager.canCheckForUpdates)
}
#endif
CommandGroup(after: .appSettings) {
Button(action: {
}, label: {
Button {

} label: {
Image(systemName: "bookmark")
Text("Saved messages")
}).keyboardShortcut("0")
Button(action: {

}, label: {
Image(systemName: "person.wave.2")
Text("Find people nearby")
})
}.keyboardShortcut("0")
Text("No chat shortcuts")
Divider()
Button(action: {

Analytics.trackEvent("Opened \"Telegram Tips\" channel from the menubar")
}, label: {
Image(systemName: "text.book.closed")
Text("Telegram Tips")
})
Button(action: {

Analytics.trackEvent("Opened \"Moc Updates\" channel from the menubar")
}, label: {
Image(systemName: "newspaper")
Text("Moc Updates")
Expand Down
6 changes: 6 additions & 0 deletions Shared/MocApp+Injection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ struct MocApp: App {
))
TdApi.shared[0].startTdLibUpdateHandler()

Task {
AppCenter.countryCode = try await TdApi.shared[0].getCountryCode().text
}

AppCenter.start(withAppSecret: Secret.appCenterSecret, services: [
Analytics.self,
Crashes.self
])

Analytics.enabled = true
}

#if os(macOS)
Expand Down
6 changes: 4 additions & 2 deletions Shared/ViewModels/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MainViewModel: ObservableObject {
}

@Published var showingLoginScreen = false
@Published var isSessionTerminationAlertShown = false
// @Published var isSessionTerminationAlertShown = false

@Published var sidebarSize: SidebarSize = .medium

Expand All @@ -147,7 +147,9 @@ class MainViewModel: ObservableObject {
case let .authorizationState(info):
switch info.authorizationState {
case .closed:
isSessionTerminationAlertShown = true
// isSessionTerminationAlertShown = true
allChats.removeAll()
chatFilters.removeAll()
case .ready, .waitEncryptionKey, .waitTdlibParameters: break // do nothing
default:
showingLoginScreen = true
Expand Down
26 changes: 13 additions & 13 deletions Shared/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,19 @@ struct ContentView: View {
LoginView()
.frame(width: 400, height: 500)
}
.alert("Your session was ended", isPresented: $mainViewModel.isSessionTerminationAlertShown) {
Button {
#if os(macOS)
NSApp.terminate(self)
#elseif os(iOS)
exit(0)
#endif
} label: {
Text("Close")
}
} message: {
Text("Please relogin to continue using Moc.")
}
// .alert("Your session was ended", isPresented: $mainViewModel.isSessionTerminationAlertShown) {
// Button {
// #if os(macOS)
// NSApp.terminate(self)
// #elseif os(iOS)
// exit(0)
// #endif
// } label: {
// Text("Close")
// }
// } message: {
// Text("Please relogin to continue using Moc.")
// }
}

private var chatPlaceholder: some View {
Expand Down
36 changes: 25 additions & 11 deletions Shared/Views/Login/LoginView+Code.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,34 @@ extension LoginView {
VStack {
Text("Enter the code")
.font(.title)
TextField("Code", text: $code)
.onSubmit {
Task {
do {
withAnimation { showLoadingSpinner = true }
try await service.checkAuth(code: code)
withAnimation { showLoadingSpinner = false }
} catch {
showErrorAlert = true
PinCodeTextField(code: $code, numberOfDigits: 5)
.onChange(of: code) { value in
if value.count == 5 {
Task {
do {
withAnimation { showLoadingSpinner = true }
try await service.checkAuth(code: code)
withAnimation { showLoadingSpinner = false }
} catch {
showErrorAlert = true
}
}
}
}
.frame(width: 156)
.textFieldStyle(.roundedBorder)
// TextField("Code", text: $code)
// .onSubmit {
// Task {
// do {
// withAnimation { showLoadingSpinner = true }
// try await service.checkAuth(code: code)
// withAnimation { showLoadingSpinner = false }
// } catch {
// showErrorAlert = true
// }
// }
// }
// .frame(width: 156)
// .textFieldStyle(.roundedBorder)

// Button {
// Task {
Expand Down
Loading

0 comments on commit ea43ab6

Please sign in to comment.