Skip to content

Commit

Permalink
also push changes at app start
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Bethge committed Sep 24, 2024
1 parent 7187521 commit a7ae758
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions SparkleShare-Mac/SparkleShare_MacApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
name: NSWorkspace.didWakeNotification,
object: nil)
setupPullDirectoriesTimer()
print("Checking all remote directories for changes...")
pullAllDirectories()
print("Checking all directories for changes...")
syncAllDirectories()
}

private func setupStatusBar() {
Expand All @@ -55,7 +55,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
let menu = NSMenu()
menu.addItem(NSMenuItem(title: "SparkleShare Mac", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Settings", action: #selector(showAddDirectoryWindow), keyEquivalent: "a"))
menu.addItem(NSMenuItem(title: "Force sync", action: #selector(pullAllDirectories), keyEquivalent: "s"))
menu.addItem(NSMenuItem(title: "Force sync", action: #selector(syncAllDirectories), keyEquivalent: "s"))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Quit", action: #selector(quitApp), keyEquivalent: "q"))
statusItem?.menu = menu
Expand Down Expand Up @@ -95,11 +95,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
window?.orderFrontRegardless()
NSApp.activate(ignoringOtherApps: true)
}

@objc private func pullAllDirectories() {
syncHandler.pullAllDirectories()
}

@objc private func syncAllDirectories() {
syncHandler.pullAllDirectories()
syncHandler.pushAllDirectories()
}

private func setupPullDirectoriesTimer() {
pullDirectoriesTimer = Timer.scheduledTimer(timeInterval: 300, target: self, selector: #selector(pullAllDirectories), userInfo: nil, repeats: true)
}
Expand Down
6 changes: 6 additions & 0 deletions SparkleShare-Mac/SyncHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class SyncHandler: ObservableObject {
}
}

func pushAllDirectories() {
for directory in monitoredDirectories {
syncChangesUp(in: directory, changedFiles: [])
}
}

func cloneRepository(from url: URL, to localParentUrl: URL, errorMessage: inout String) -> URL? {
let gitRepository = GitRepository(repositoryPath: localParentUrl)
let result = gitRepository.clone(from: url, errorMessage: &errorMessage)
Expand Down

0 comments on commit a7ae758

Please sign in to comment.