Skip to content

Commit

Permalink
Implement centered wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Nov 16, 2018
1 parent a42560c commit 211fb90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
12 changes: 5 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"electron-is-dev": "^0.3.0",
"electron-squirrel-startup": "^1.0.0",
"wallpaper": "^2.6.0"
"wallpaper": "4.1.0"
},
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.22",
Expand Down
26 changes: 13 additions & 13 deletions src/electron-injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ window.systemSetAsWallpaperCentered = function(c){
var fs = require("fs");
var wallpaper = require("wallpaper");

// This currently doesn't necessarily set as centered; it can set as stretched on Windows 10.
// TODO: implement centered similar to tiled (drawing to a larger canvas)
// altho doing that would mean it wouldn't respect the system background color
// so maybe on macOS it should still use the canvas directly, and use the scale option center
// https://www.npmjs.com/package/wallpaper
// ...actually, if we generate a transparent image, it might work with the system background color
// TODO: implement centered option for Windows and Linux in https://www.npmjs.com/package/wallpaper
// currently it's only supported on macOS
if(process.platform === "darwin"){
var wallpaperCanvas = c;
}else{
var wallpaperCanvas = new Canvas(screen.width, screen.height);
var x = (screen.width - c.width) / 2;
var y = (screen.height - c.height) / 2;
wallpaperCanvas.ctx.drawImage(c, ~~x, ~~y);
}

// var wp = new Canvas(screen.width, screen.height);
// var x = (screen.width - c.width) / 2;
// var y = (screen.height - c.height) / 2;
// wp.ctx.drawImage(c, ~~x, ~~y);

get_array_buffer_from_canvas(c).then(function(array_buffer){
get_array_buffer_from_canvas(wallpaperCanvas).then(function(array_buffer){
var buffer = new Buffer(array_buffer);
fs.writeFile(imgPath, buffer, function(err){
if(err){
return show_error_message("Failed to set as desktop background: couldn't write temporary image file.", err);
}
wallpaper.set(imgPath, function(err){
// {scale: "center"} only supported on macOS; see above workaround
wallpaper.set(imgPath, {scale: "center"}, function(err){
if(err){
show_error_message("Failed to set as desktop background!", err);
}
Expand Down

0 comments on commit 211fb90

Please sign in to comment.