Skip to content

Commit

Permalink
fix: fix parent identifier with no prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
marmos91 committed Jan 28, 2024
1 parent 85b08ca commit 6f9309d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 28 deletions.
16 changes: 8 additions & 8 deletions CubbitDS3Sync.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@
D5A221EC2B571FED00F1413B /* SyncRecap */ = {
isa = PBXGroup;
children = (
D5A221ED2B571FED00F1413B /* ViewModels */,
D5A221EF2B571FED00F1413B /* Views */,
D5A221ED2B571FED00F1413B /* ViewModels */,
);
path = SyncRecap;
sourceTree = "<group>";
Expand Down Expand Up @@ -767,9 +767,9 @@
D5A221F72B571FED00F1413B /* Login */ = {
isa = PBXGroup;
children = (
D5A221F82B571FED00F1413B /* ViewModels */,
D5A221FA2B571FED00F1413B /* Models */,
D5A221FC2B571FED00F1413B /* Views */,
D5A221F82B571FED00F1413B /* ViewModels */,
);
path = Login;
sourceTree = "<group>";
Expand Down Expand Up @@ -1333,7 +1333,7 @@
CODE_SIGN_ENTITLEMENTS = CubbitDS3Sync/CubbitDS3Sync.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_ASSET_PATHS = "\"CubbitDS3Sync/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = X889956QSM;
Expand Down Expand Up @@ -1382,7 +1382,7 @@
CODE_SIGN_ENTITLEMENTS = CubbitDS3Sync/CubbitDS3Sync.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_ASSET_PATHS = "\"CubbitDS3Sync/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = X889956QSM;
Expand Down Expand Up @@ -1428,7 +1428,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = X889956QSM;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down Expand Up @@ -1465,7 +1465,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = X889956QSM;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down Expand Up @@ -1501,7 +1501,7 @@
CODE_SIGN_ENTITLEMENTS = Provider/Provider.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = X889956QSM;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -1534,7 +1534,7 @@
CODE_SIGN_ENTITLEMENTS = Provider/Provider.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = X889956QSM;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down
13 changes: 7 additions & 6 deletions CubbitDS3Sync/CubbitDS3SyncApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import os.log

@main
struct ds3syncApp: App {
private let logger: Logger = Logger(subsystem: "io.cubbit.CubbitDS3Sync", category: "MainApp")

@AppStorage(DefaultSettings.UserDefaultsKeys.tutorial) var tutorialShown: Bool = DefaultSettings.tutorialShown
@AppStorage(DefaultSettings.UserDefaultsKeys.loginItemSet) var loginItemSet: Bool = DefaultSettings.loginItemSet

private let logger: Logger = Logger(subsystem: "io.cubbit.CubbitDS3Sync", category: "MainApp")

@State var showTrayIcon: Bool = true
@State var ds3Authentication: DS3Authentication = DS3Authentication.loadFromPersistenceOrCreateNew()
@State var appStatusManager: AppStatusManager = AppStatusManager.default()
@State var ds3DriveManager: DS3DriveManager = DS3DriveManager(appStatusManager: AppStatusManager.default())

var appStatusManager: AppStatusManager = AppStatusManager.default()
var ds3DriveManager: DS3DriveManager = DS3DriveManager(appStatusManager: AppStatusManager.default())
// TODO: Hide tray menu when not logged in
@State var trayMenuVisible: Bool = true

var body: some Scene {
// MARK: - Main view
Expand Down Expand Up @@ -79,7 +80,7 @@ struct ds3syncApp: App {
#if os(macOS)
// MARK: - Tray Menu

MenuBarExtra(isInserted: $showTrayIcon) {
MenuBarExtra(isInserted: $trayMenuVisible) {
TrayMenuView()
.environment(ds3Authentication)
.environment(ds3DriveManager)
Expand Down
1 change: 1 addition & 0 deletions CubbitDS3Sync/Views/Login/ViewModels/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import os.log

var loginError: Error?
var need2FA: Bool = false
var tfaError: Error?
var isLoading: Bool = false

/// Logs in the account with the provided credentials
Expand Down
13 changes: 12 additions & 1 deletion CubbitDS3Sync/Views/Login/Views/LoginView.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import SwiftUI

struct LoginView: View {
enum FocusedField {
case email, password
}
@Environment(DS3Authentication.self) var ds3Authentication: DS3Authentication

@State var email: String = ""
@State var password: String = ""
@FocusState private var focusedField: FocusedField?

var loginViewModel: LoginViewModel = LoginViewModel()

Expand All @@ -16,7 +20,8 @@ struct LoginView: View {
.environment(ds3Authentication)
} else {
ZStack {
Color(.background).ignoresSafeArea()
Color(.background)
.ignoresSafeArea()

VStack(alignment: .center) {
Image(.cubbitLogo)
Expand All @@ -35,6 +40,12 @@ struct LoginView: View {
error: loginViewModel.loginError,
text: $email
)
.focused(self.$focusedField, equals: .email)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) {
self.focusedField = .email
}
}

IconTextField(
iconName: .passwordIcon,
Expand Down
14 changes: 14 additions & 0 deletions CubbitDS3Sync/Views/Login/Views/MFAView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct MFAView: View {
var password: String

@State var tfaCode: String = ""
@FocusState var focused: Bool?

var body: some View {
ZStack {
Expand Down Expand Up @@ -40,6 +41,12 @@ struct MFAView: View {
placeholder: "2FA 6-digit code",
text: $tfaCode
)
.focused($focused, equals: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) {
self.focused = true
}
}
.onSubmit {
self.loginWithMFA()
}
Expand All @@ -53,6 +60,13 @@ struct MFAView: View {
.onSubmit {
self.loginWithMFA()
}

if let loginError = loginViewModel.loginError {
Text(loginError.localizedDescription)
.font(.custom("Nunito", size: 14))
.foregroundStyle(Color.red)
.multilineTextAlignment(.center)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI

struct SyncRecapNameSelectionView: View {
@Environment(SyncRecapViewModel.self) var syncRecapViewModel: SyncRecapViewModel
@FocusState var focused: Bool?

var onComplete: (() -> Void)?

Expand All @@ -19,11 +20,18 @@ struct SyncRecapNameSelectionView: View {
} set: {
syncRecapViewModel.setDS3DriveName($0)
}
).onSubmit {
)
.focused($focused, equals: true)
.onSubmit {
if let ds3DriveName = syncRecapViewModel.ds3DriveName, ds3DriveName.count > 0 {
onComplete?()
}
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) {
self.focused = true
}
}
}
.padding(.vertical, 5)

Expand Down
2 changes: 0 additions & 2 deletions CubbitDS3Sync/Views/Tray/ViewModels/DS3DriveViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ import os.log
updateDriveStatusNotification.driveId == self.drive.id // Only update if the notification is for this drive
else { return }

self.logger.debug("Updating drive status to \(updateDriveStatusNotification.status.rawValue) for drive \(self.drive.name)")

self.driveStatus = updateDriveStatusNotification.status
}

Expand Down
9 changes: 4 additions & 5 deletions CubbitDS3Sync/Views/Tray/Views/TrayMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,19 @@ struct TrayMenuView: View {
NSApplication.shared.terminate(self)
}

Divider()

Spacer()

Divider()

TrayMenuFooterView(
status: appStatusManager.status.toString(),
version: DefaultSettings.appVersion
)
}
}
.frame(
minWidth: 280,
maxWidth: 280,
maxHeight: .infinity
minWidth: 310,
maxWidth: 310
)
.fixedSize(horizontal: true, vertical: false)

Expand Down
1 change: 0 additions & 1 deletion Provider/S3Enumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class S3Enumerator: NSObject, NSFileProviderEnumerator {
var page: NSFileProviderPage? = nil

if continuationToken != nil {
self.logger.debug("Continuation token found \(continuationToken!). Creating new page for enumeration")
page = NSFileProviderPage(continuationToken!)
}

Expand Down
10 changes: 7 additions & 3 deletions Provider/S3Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class S3Item: NSObject, NSFileProviderItem {
drive: DS3Drive,
objectMetadata: S3Item.Metadata
) {

self.metadata = objectMetadata
self.drive = drive

Expand All @@ -31,7 +30,10 @@ class S3Item: NSObject, NSFileProviderItem {
}
}

init(from item: NSFileProviderItem, drive: DS3Drive) {
init(
from item: NSFileProviderItem,
drive: DS3Drive
) {
self.identifier = item.itemIdentifier
self.drive = drive
self.metadata = S3Item.Metadata(
Expand All @@ -47,7 +49,9 @@ class S3Item: NSObject, NSFileProviderItem {
var parentItemIdentifier: NSFileProviderItemIdentifier {
var pathSegments = self.identifier.rawValue.split(separator: self.separator)

if pathSegments.count == 2 {
let prefixSegmentsCount = (self.drive.syncAnchor.prefix?.split(separator: self.separator) ?? []).count

if pathSegments.count == prefixSegmentsCount + 1 {
// NOTE: e.g. parent of prefix/folder/ is prefix/ (remember prefix == .rootContainer)
return .rootContainer
}
Expand Down
4 changes: 3 additions & 1 deletion Provider/S3Lib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class S3Lib {
// NOTE: Skipping the prefix itself as we don't want the folder root to be listed
continue
}

let s3Item = S3Item(
identifier: NSFileProviderItemIdentifier(key),
drive: drive,
Expand All @@ -110,6 +110,8 @@ class S3Lib {
}
}

self.logger.debug("Listed \(items.count) items")

guard let isTruncated = response.isTruncated else {
throw EnumeratorError.missingParameters
}
Expand Down

0 comments on commit 6f9309d

Please sign in to comment.