-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc3bd88
commit 3bdad24
Showing
26 changed files
with
259 additions
and
71 deletions.
There are no files selected for viewing
Submodule translate
updated
5 files
+11 −5 | src/debug.js | |
+1 −1 | src/translation/sandboxManager.js | |
+0 −8 | src/translation/translate.js | |
+16 −7 | src/translator.js | |
+1 −1 | testTranslators/testTranslators.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// AutoEmptyTrashController.swift | ||
// Zotero | ||
// | ||
// Created by Michal Rentka on 09.10.2024. | ||
// Copyright © 2024 Corporation for Digital Scholarship. All rights reserved. | ||
// | ||
|
||
import CocoaLumberjackSwift | ||
|
||
final class AutoEmptyTrashController { | ||
private unowned let dbStorage: DbStorage | ||
private let queue: DispatchQueue | ||
|
||
init(dbStorage: DbStorage) { | ||
self.dbStorage = dbStorage | ||
queue = DispatchQueue(label: "org.zotero.AutoEmptyTrashController.queue", qos: .utility) | ||
} | ||
|
||
func autoEmptyIfNeeded() { | ||
if Defaults.shared.trashAutoEmptyThreshold == 0 { | ||
DDLogInfo("AutoEmptyTrashController: auto emptying disabled") | ||
return | ||
} | ||
|
||
// Auto empty trash once a day | ||
guard Date.now.timeIntervalSince(Defaults.shared.trashLastAutoEmptyDate) >= 86400 else { return } | ||
|
||
DDLogInfo("AutoEmptyTrashController: perform auto empty") | ||
Defaults.shared.trashLastAutoEmptyDate = .now | ||
|
||
queue.asyncAfter(deadline: .now() + .seconds(1)) { [weak self] in | ||
guard let self else { return } | ||
do { | ||
try dbStorage.perform(request: AutoEmptyTrashDbRequest(libraryId: .custom(.myLibrary)), on: queue) | ||
} catch let error { | ||
DDLogError("AutoEmptyTrashController: can't empty trash - \(error)") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Zotero/Controllers/Database/Requests/AutoEmptyTrashDbRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// AutoEmptyTrashDbRequest.swift | ||
// Zotero | ||
// | ||
// Created by Michal Rentka on 15.10.2024. | ||
// Copyright © 2024 Corporation for Digital Scholarship. All rights reserved. | ||
// | ||
|
||
import CocoaLumberjackSwift | ||
import RealmSwift | ||
|
||
struct AutoEmptyTrashDbRequest: DbRequest { | ||
let libraryId: LibraryIdentifier | ||
|
||
var needsWrite: Bool { return true } | ||
|
||
func process(in database: Realm) throws { | ||
let threshold = Defaults.shared.trashAutoEmptyThreshold | ||
var count = 0 | ||
database.objects(RItem.self).filter(.items(for: .custom(.trash), libraryId: libraryId)).filter("trashDate != nil").forEach { | ||
guard let date = $0.trashDate, shouldDelete(date: date) else { return } | ||
$0.deleted = true | ||
$0.changeType = .user | ||
count += 1 | ||
} | ||
DDLogInfo("Auto emptied \(count) items") | ||
count = 0 | ||
database.objects(RCollection.self).filter(.trashedCollections(in: .custom(.myLibrary))).filter("trashDate != nil").forEach { | ||
guard let date = $0.trashDate, shouldDelete(date: date) else { return } | ||
$0.deleted = true | ||
$0.changeType = .user | ||
count += 1 | ||
} | ||
DDLogInfo("Auto emptied \(count) collections") | ||
|
||
func shouldDelete(date: Date) -> Bool { | ||
let daysSinceTrashed = Int(Date.now.timeIntervalSince(date) / 86400) | ||
return daysSinceTrashed >= threshold | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.