-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
20 changed files
with
193 additions
and
921 deletions.
There are no files selected for viewing
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 @@ | ||
patreon: chishui |
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,21 @@ | ||
prefix ?= /usr/local | ||
bindir = $(prefix)/bin | ||
libdir = $(prefix)/lib | ||
|
||
build: | ||
swift build -c release --disable-sandbox | ||
|
||
install: build | ||
install -d "$(bindir)" "$(libdir)" | ||
install ".build/release/one-wallpaper" "$(bindir)" | ||
install_name_tool -change \ | ||
".build/x86_64-apple-macosx10.10/release/libSwiftSyntax.dylib" \ | ||
"$(bindir)/one-wallpaper" | ||
|
||
uninstall: | ||
rm -rf "$(bindir)/one-wallpaper" | ||
|
||
clean: | ||
rm -rf .build | ||
|
||
.PHONY: build install uninstall clean |
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,34 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "SQLite.swift", | ||
"repositoryURL": "https://github.com/stephencelis/SQLite.swift", | ||
"state": { | ||
"branch": null, | ||
"revision": "9af51e2edf491c0ea632e369a6566e09b65aa333", | ||
"version": "0.13.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-argument-parser", | ||
"repositoryURL": "https://github.com/apple/swift-argument-parser", | ||
"state": { | ||
"branch": null, | ||
"revision": "d2930e8fcf9c33162b9fcc1d522bc975e2d4179b", | ||
"version": "1.0.1" | ||
} | ||
}, | ||
{ | ||
"package": "Wallpaper", | ||
"repositoryURL": "https://github.com/chishui/Wallpaper", | ||
"state": { | ||
"branch": "main", | ||
"revision": "ab18d7162cdfedf77f0eb19b22467cb5c91fdbfe", | ||
"version": null | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
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,33 @@ | ||
// swift-tools-version:5.3 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "OneWallpaper", | ||
platforms: [ | ||
.macOS(.v10_14) | ||
], | ||
products: [ | ||
.library( | ||
name: "OneWallpaper", | ||
targets: ["OneWallpaper"]), | ||
.executable(name: "one-wallpaper", | ||
targets: ["OneWallpaper"]) | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), | ||
.package(url: "https://github.com/stephencelis/SQLite.swift", from: "0.13.0"), | ||
.package(url: "https://github.com/chishui/Wallpaper", .branch("main")) | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "OneWallpaper", | ||
dependencies: [ | ||
.product(name: "Wallpaper", package: "Wallpaper"), | ||
.product(name: "ArgumentParser", package: "swift-argument-parser") | ||
] | ||
) | ||
] | ||
) |
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,9 @@ | ||
OneWallpaper | ||
============================== | ||
OneWallpaper can help you set up a continous wallpaper across your multiple monitors with single wallpaper with smooth transition. | ||
|
||
# Install | ||
```bash | ||
$ brew tap chishui/OneWallpaper | ||
$ brew install one-wallpaper | ||
``` |
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,28 @@ | ||
// | ||
// PathHelper.swift | ||
// OneWallpaper | ||
// | ||
// Created by Liyun Xiu on 10/17/20. | ||
// | ||
|
||
import Foundation | ||
|
||
class PathHelper { | ||
let fileManager = FileManager.default | ||
let extensions = ["jpg", "jpeg", "png"] | ||
|
||
func getRandomImage(from folder: String) throws -> String { | ||
let folderUrl = URL(string: folder) | ||
var images: [URL] = [] | ||
let items = try fileManager.contentsOfDirectory(atPath: folder) | ||
for item in items { | ||
guard let file = folderUrl?.appendingPathComponent(item) else {continue} | ||
if extensions.contains(file.pathExtension) { | ||
images.append(file) | ||
} | ||
} | ||
|
||
let index = Int.random(in: 0..<images.count) | ||
return images[index].absoluteString | ||
} | ||
} |
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,67 @@ | ||
// | ||
// main.swift | ||
// OneWallpaper | ||
// | ||
// Created by Liyun Xiu on 10/4/20. | ||
// | ||
|
||
import Foundation | ||
import Wallpaper | ||
import ArgumentParser | ||
|
||
struct OneWallpaper: ParsableCommand { | ||
// Customize your command's help and subcommands by implementing the | ||
// `configuration` property. | ||
static var configuration = CommandConfiguration( | ||
// Optional abstracts and discussions are used for help output. | ||
abstract: "A tool to split your wallpaper and setup them across multiple monitors", | ||
|
||
// Commands can define a version for automatic '--version' support. | ||
version: "1.0.0" | ||
) | ||
|
||
@Argument(help: "Set image path or directory path to set random image from directory") | ||
var wallpaper: String | ||
|
||
@Flag(help: "true to set the same wallpaper in each monitor, otherwise set wallpaper across monitors to they look like one image") | ||
var duplicate = false | ||
|
||
mutating func run() { | ||
let wp = Wallpaper() | ||
var isDir : ObjCBool = false | ||
guard FileManager.default.fileExists(atPath: wallpaper, isDirectory: &isDir) else { | ||
print("File: \(wallpaper) does not exist!") | ||
return | ||
} | ||
|
||
if isDir.boolValue { | ||
let ph = PathHelper() | ||
do { | ||
wallpaper = try ph.getRandomImage(from: wallpaper) | ||
} catch { | ||
print(error) | ||
return | ||
} | ||
} | ||
|
||
let method = duplicate ? SetWallpaperMethod.duplicate : SetWallpaperMethod.across | ||
let result = wp.setWallpaper(with: wallpaper, by: method) | ||
switch result { | ||
case .success: | ||
print("Done!") | ||
case .failure(let error): | ||
switch error { | ||
case .fileNotExist: | ||
print("File: \(wallpaper) does not exist!") | ||
case .saveTemporaryImageFileFail: | ||
print("Cannot save temparory file!") | ||
case .setWallpaperFail: | ||
print("Set wallpaper failed!") | ||
case .unknown: | ||
print("Unknown error happened!") | ||
} | ||
} | ||
} | ||
} | ||
|
||
OneWallpaper.main() |
Oops, something went wrong.