Skip to content

Commit e0d0353

Browse files
committed
Create README.MD
1 parent 643c1a7 commit e0d0353

1 file changed

Lines changed: 143 additions & 0 deletions

File tree

README.MD

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# PlatformTools
2+
3+
**PlatformTools** is a lightweight Java library designed to provide deep integration with operating system features (macOS and Windows) that are not available in the standard JDK. It utilizes JNA (Java Native Access) to bridge the gap between Java and native OS APIs.
4+
5+
## ✨ Features
6+
7+
* **[Finder Favorites (macOS)](#1-finder-favorites-macos):** Programmatically pin, unpin, and check the status of folders in the macOS Finder Sidebar.
8+
* *Note: Support for Windows Quick Access is planned for future releases.*
9+
* **[System Accent Color (Windows & macOS)](#2-system-accent-color):** Retrieve the user's system accent color and subscribe to real-time changes (via Windows DWM hooks or macOS `NSDistributedNotificationCenter`).
10+
* **[File Origin Metadata (Windows & macOS)](#3-file-origin--referrer):** Retrieve the source URL of downloaded files.
11+
* **macOS:** Reads `kMDItemWhereFroms` metadata.
12+
* **Windows:** Reads **Alternate Data Streams (ADS)**, specifically `Zone.Identifier`.
13+
* **Java 8 Compatible:** Built on Java 17 but distributed with a Java 8 compatible version (Multi-Release JAR).
14+
15+
## 📦 Installation
16+
The library is hosted on the Redlance repository.
17+
18+
### Gradle (Groovy)
19+
```groovy
20+
repositories {
21+
mavenCentral()
22+
maven { url = uri("https://repo.redlance.org/public") }
23+
}
24+
25+
dependencies {
26+
// For Java 17+ (Standard version)
27+
implementation "org.redlance:platformtools:3.1.3"
28+
29+
// For Java 8 (Downgraded version)
30+
implementation("org.redlance:platformtools:3.1.3:java8")
31+
}
32+
```
33+
34+
### Maven
35+
```xml
36+
<repositories>
37+
<repository>
38+
<id>redlance-public</id>
39+
<url>https://repo.redlance.org/public</url>
40+
</repository>
41+
</repositories>
42+
43+
<dependency>
44+
<groupId>org.redlance</groupId>
45+
<artifactId>platformtools</artifactId>
46+
<version>3.1.3</version>
47+
</dependency>
48+
```
49+
50+
## 🚀 Usage
51+
52+
### 1. Finder Favorites (macOS)
53+
Manage the "Favorites" section in the macOS Finder Sidebar.
54+
55+
> **Note:** Windows "Quick Access" support is currently in development. On Windows, these methods will currently return `false` or perform no action.
56+
57+
```java
58+
import org.redlance.platformtools.PlatformFinderFavorites;
59+
60+
public class FavoritesExample {
61+
public void toggleFavorite(String path) {
62+
// Check if the folder is already pinned
63+
if (PlatformFinderFavorites.INSTANCE.isPinned(path)) {
64+
System.out.println("Folder is pinned. Unpinning...");
65+
PlatformFinderFavorites.INSTANCE.unpin(path);
66+
} else {
67+
System.out.println("Pinning folder to the sidebar...");
68+
PlatformFinderFavorites.INSTANCE.pin(
69+
path,
70+
true, // isDirectory
71+
PlatformFinderFavorites.Position.LAST // or Position.FIRST
72+
);
73+
}
74+
}
75+
}
76+
```
77+
78+
### 2. System Accent Color
79+
Get the system's personalization color and listen for changes in real-time.
80+
81+
```java
82+
import org.redlance.platformtools.PlatformAccent;
83+
import java.awt.Color;
84+
85+
public class AccentExample {
86+
public void init() {
87+
// 1. Get current color (with a fallback)
88+
Color accent = PlatformAccent.INSTANCE.getAccent();
89+
updateUI(accent);
90+
91+
// 2. Subscribe to OS events (efficient lazy subscription)
92+
PlatformAccent.INSTANCE.subscribeToChanges(newColor -> {
93+
System.out.println("System accent color changed to: " + newColor);
94+
updateUI(newColor);
95+
});
96+
}
97+
98+
// Call this if your window is recreated (specifically for Windows hooks)
99+
public void onWindowRecreated() {
100+
PlatformAccent.INSTANCE.resubscribe();
101+
}
102+
}
103+
```
104+
105+
### 3. File Origin / Referrer
106+
Retrieve the source URLs for downloaded files. This works on both macOS (Metadata) and Windows (ADS).
107+
108+
```java
109+
import org.redlance.platformtools.PlatformFileReferer;
110+
import java.io.File;
111+
import java.util.Set;
112+
113+
public class ReferrerExample {
114+
public void printOrigin(File file) {
115+
try {
116+
Set<String> referrers = PlatformFileReferer.INSTANCE.getFileReferer(file);
117+
118+
if (!referrers.isEmpty()) {
119+
System.out.println("File downloaded from:");
120+
referrers.forEach(System.out::println);
121+
} else {
122+
System.out.println("No origin metadata found (or file is local).");
123+
}
124+
} catch (Exception e) {
125+
e.printStackTrace();
126+
}
127+
}
128+
}
129+
```
130+
131+
## 🛠 System Requirements
132+
* **Java:** 8 or higher.
133+
* **Operating Systems:**
134+
* **macOS:** 10.13 (High Sierra) or newer (x86_64 / arm64).
135+
* **Windows:** Windows 10 or Windows 11 (x64).
136+
137+
138+
* **Native Dependencies:**
139+
* This library bundles the necessary JNA bindings.
140+
* On macOS, it requires `java-objc-bridge` (included in dependencies).
141+
142+
## 📄 License
143+
This project is licensed under the **MIT License**.

0 commit comments

Comments
 (0)