Skip to content

Commit

Permalink
Modify the way to refresh the wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeLulin committed Mar 28, 2022
1 parent 782de6c commit ab15fa2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions EarthLiveX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
CODE_SIGN_ENTITLEMENTS = EarthLiveX/EarthLiveX.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 101;
CURRENT_PROJECT_VERSION = 102;
DEVELOPMENT_ASSET_PATHS = "\"EarthLiveX/Preview Content\"";
DEVELOPMENT_TEAM = PPC69QRUTZ;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -475,7 +475,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = cn.lulin.EarthLiveX;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -491,7 +491,7 @@
CODE_SIGN_ENTITLEMENTS = EarthLiveX/EarthLiveX.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 101;
CURRENT_PROJECT_VERSION = 102;
DEVELOPMENT_ASSET_PATHS = "\"EarthLiveX/Preview Content\"";
DEVELOPMENT_TEAM = PPC69QRUTZ;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -504,7 +504,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = cn.lulin.EarthLiveX;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Binary file not shown.
9 changes: 8 additions & 1 deletion EarthLiveX/WallPaperTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,17 @@ func compressedImageDataWithImg(image: NSImage, rate: CGFloat) -> NSData? {

func setWallpaper(path: String){
let imgUrl = URL(fileURLWithPath: path, isDirectory: false)
var options = [NSWorkspace.DesktopImageOptionKey: Any]()
options[.imageScaling] = NSImageScaling.scaleProportionallyUpOrDown.rawValue
options[.allowClipping] = true
for screen in NSScreen.screens {
do {
print("refresh wallpaper")
try NSWorkspace.shared.setDesktopImageURL(URL(fileURLWithPath: ""), for: screen, options: [:])
Thread.sleep(forTimeInterval: 0.4)
print("set wallpaper to \(screen.localizedName)")
try NSWorkspace.shared.setDesktopImageURL(imgUrl, for: screen, options: NSWorkspace.shared.desktopImageOptions(for: NSScreen.main!)!)
try NSWorkspace.shared.setDesktopImageURL(imgUrl, for: screen, options: options)
Thread.sleep(forTimeInterval: 0.4)
} catch let error {
print("set wallpeper error: \(error)")
}
Expand Down

0 comments on commit ab15fa2

Please sign in to comment.