Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better iCloud sync integration #424

Open
Tracked by #520
ACTCD opened this issue Feb 20, 2023 · 16 comments
Open
Tracked by #520

Better iCloud sync integration #424

ACTCD opened this issue Feb 20, 2023 · 16 comments
Labels
enhancement Feature work help wanted Extra attention is needed

Comments

@ACTCD
Copy link
Collaborator

ACTCD commented Feb 20, 2023

Currently, we tell users in the README:

Tip: for optimal cross platform experience it's a good idea to use an iCloud folder for syncing between macOS and iOS

But the current iCloud sync has some doubts for users:

  • We don't really support iCloud in the app, so it won't appear in the list of Apps using iCloud.
  • Not out of the box, users need to manually set and select the same path in iCloud Drive in different devices.
  • The folder is not indicated as belonging to the App in iCloud (there is a folder icon containing the App Icon)
  • Syncing process of script files is delayed, uncertain and uncontrolled
  • For devices with limited space, local files may be evictioned due to iCloud optimization
    • Could be resolved by the Keep Downloaded feature introduced in macOS 15 / iOS 18
  • May be briefly inaccessible due to synching, downloading, etc.; remove bookmark and restore default path

We may need to officially support iCloud features, and the synchronization mechanism and process will be managed by the App.

References:
https://developer.apple.com/library/archive/documentation/DataManagement/Conceptual/CloudKitQuickStart/Introduction/Introduction.html
https://developer.apple.com/documentation/cloudkit/
https://developer.apple.com/documentation/technotes/tn3162-understanding-cloudkit-throttles

@ACTCD ACTCD added swift enhancement Feature work labels Feb 20, 2023
@quoid quoid removed feature labels May 1, 2023
@biuuu
Copy link

biuuu commented Jun 1, 2023

Will the data saved with GM.setValue also be synced to iCloud?

@ACTCD
Copy link
Collaborator Author

ACTCD commented Jun 2, 2023

@biuuu No, not at the moment.

@ACTCD ACTCD changed the title Better iCloud sync feature Better iCloud sync integration Jul 29, 2023
@keycommander

This comment was marked as off-topic.

@ACTCD

This comment was marked as outdated.

@keycommander

This comment was marked as off-topic.

@ACTCD

This comment was marked as outdated.

@2xsaiko
Copy link

2xsaiko commented Feb 22, 2024

For devices with limited space, local files may be evictioned due to iCloud optimization

I just hit this and was confused as to why my scripts suddenly weren't working anymore. Seems like Userscripts doesn't pick up the files when they get evicted until manually downloaded again through Finder. Is this known?

@ACTCD
Copy link
Collaborator Author

ACTCD commented Feb 22, 2024

@2xsaiko As I wrote. Since the extension does not currently use the iCloud related APIs, we won't know when the system decides to evict a file, and we won't be able to read it again. Thanks for your feedback.

@2xsaiko
Copy link

2xsaiko commented Feb 22, 2024

Sure, but usually, files will download on access, and non-downloaded files are visible in directories. You can see this by opening iCloud Drive in your terminal and e.g. running ls, cat or cp on a couple files. Everything is there, just accessing it might block a few seconds while it downloads, and these commands don't use the iCloud API either. Userscripts doesn't even pick the files up however.

@ACTCD
Copy link
Collaborator Author

ACTCD commented Feb 22, 2024

@2xsaiko Check out our code, this is how it currently works, if you'd like to debug it, or know of a simple way to improve it, please let us know or submit a PR and we'll be happy to improve the experience.

// get all file urls within save location
guard let urls = try? fm.contentsOfDirectory(at: saveLocation, includingPropertiesForKeys: []) else {
logger?.error("\(#function, privacy: .public) - failed at (2)")
return nil
}
for url in urls {
var fileData = [String: Any]()
// only read contents for css & js files
let filename = url.lastPathComponent
if (!filename.hasSuffix(".css") && !filename.hasSuffix(".js")) {
continue
}
// file will be skipped if metablock is missing
guard
let content = try? String(contentsOf: url, encoding: .utf8),
let dateMod = try? fm.attributesOfItem(atPath: url.path)[.modificationDate] as? Date,
let parsed = parse(content),
let metadata = parsed["metadata"] as? [String: [String]],
let type = filename.split(separator: ".").last
else {
logger?.info("\(#function, privacy: .public) - ignoring \(filename, privacy: .public), file missing or metadata missing from file contents")
continue
}

@2xsaiko
Copy link

2xsaiko commented Feb 23, 2024

Ah, that's the NSFileManager API. That might behave differently than the POSIX readdir, not sure. I'm not familiar with native macOS development at all apart from writing a handful lines of Objective-C. Might mess around with it.

@ACTCD
Copy link
Collaborator Author

ACTCD commented Feb 24, 2024

@2xsaiko The same is true for us, learning native/swift from scratch, building and refactoring the extension.

I personally do not currently use icloud sync, and there's a lot more main refactoring to do. Therefore, this issue is not currently on the foreseeable task list, unless someone is willing to investigate and contribute. I will add a label to this issue.

@ACTCD ACTCD added the help wanted Extra attention is needed label Feb 24, 2024
@2xsaiko
Copy link

2xsaiko commented Feb 24, 2024

Well, a simple test program lists the files and automatically downloads the contents, so something else is going on here.

How do you get started with this? I tried just opening the project and running the "Mac" configuration in Xcode (not even sure if that would work for a Safari extension) but it said "No such file or directory" for Resources/_locales, /dist and /images.

@ACTCD
Copy link
Collaborator Author

ACTCD commented Feb 24, 2024

@2xsaiko Please check: https://github.com/quoid/userscripts/blob/main/docs/dev.md

Those missing parts need to be built by executing the npm command.

@2xsaiko
Copy link

2xsaiko commented Feb 27, 2024

There we go: #629

@ACTCD
Copy link
Collaborator Author

ACTCD commented Jul 1, 2024

Interestingly, one issue should be officially resolved in the upcoming macOS 15 / iOS 18, with an additional menu item "Keep Downloaded" in the iCloud Drive of the new version of the system, which allows you to mark a specific folder not to be automatically evicted by the system.

We would like to thank our users (@JOJOforshaun) for providing us with the above information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature work help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants
@2xsaiko @quoid @biuuu @keycommander @ACTCD and others