Fix minor formatting issues
parent
55e9592726
commit
c05cfde5c6
18
README.md
18
README.md
|
@ -469,7 +469,7 @@ You can define two functions to set the wallpaper, which will be used by **File
|
||||||
|
|
||||||
If you define only [`systemHooks.setWallpaperCentered`][], JS Paint will attempt to guess your screen's dimensions and tile the image, applying it by calling your [`systemHooks.setWallpaperCentered`][] function.
|
If you define only [`systemHooks.setWallpaperCentered`][], JS Paint will attempt to guess your screen's dimensions and tile the image, applying it by calling your [`systemHooks.setWallpaperCentered`][] function.
|
||||||
|
|
||||||
If you don't specify [`systemHooks.setWallpaperCentered`][], JS Paint will default to saving a file (`<original file name> wallpaper.png"`) using [`systemHooks.showSaveFileDialog`][] and [`systemHooks.writeBlobToHandle`][].
|
If you don't specify [`systemHooks.setWallpaperCentered`][], JS Paint will default to saving a file (`<original file name> wallpaper.png`) using [`systemHooks.showSaveFileDialog`][] and [`systemHooks.writeBlobToHandle`][].
|
||||||
|
|
||||||
Here's a full example supporting a persistent custom wallpaper as a background on the containing page:
|
Here's a full example supporting a persistent custom wallpaper as a background on the containing page:
|
||||||
|
|
||||||
|
@ -480,12 +480,12 @@ jspaint.systemHooks.setWallpaperCentered = (canvas) => {
|
||||||
canvas.toBlob((blob) => {
|
canvas.toBlob((blob) => {
|
||||||
setDesktopWallpaper(blob, "no-repeat", true);
|
setDesktopWallpaper(blob, "no-repeat", true);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
jspaint.systemHooks.setWallpaperTiled = (canvas) => {
|
jspaint.systemHooks.setWallpaperTiled = (canvas) => {
|
||||||
canvas.toBlob((blob) => {
|
canvas.toBlob((blob) => {
|
||||||
setDesktopWallpaper(blob, "repeat", true);
|
setDesktopWallpaper(blob, "repeat", true);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
function setDesktopWallpaper(file, repeat, saveToLocalStorage) {
|
function setDesktopWallpaper(file, repeat, saveToLocalStorage) {
|
||||||
const blob_url = URL.createObjectURL(file);
|
const blob_url = URL.createObjectURL(file);
|
||||||
|
@ -494,17 +494,19 @@ function setDesktopWallpaper(file, repeat, saveToLocalStorage) {
|
||||||
wallpaper.style.backgroundPosition = "center";
|
wallpaper.style.backgroundPosition = "center";
|
||||||
wallpaper.style.backgroundSize = "auto";
|
wallpaper.style.backgroundSize = "auto";
|
||||||
if (saveToLocalStorage) {
|
if (saveToLocalStorage) {
|
||||||
const fr = new FileReader();
|
const fileReader = new FileReader();
|
||||||
fr.onload = () => {
|
fileReader.onload = () => {
|
||||||
localStorage.setItem("wallpaper-data-url", fr.result);
|
localStorage.setItem("wallpaper-data-url", fileReader.result);
|
||||||
localStorage.setItem("wallpaper-repeat", repeat);
|
localStorage.setItem("wallpaper-repeat", repeat);
|
||||||
};
|
};
|
||||||
fr.onerror = () => {
|
fileReader.onerror = () => {
|
||||||
console.error("Error reading file (for setting wallpaper)", file);
|
console.error("Error reading file (for setting wallpaper)", file);
|
||||||
};
|
};
|
||||||
fr.readAsDataURL(file);
|
fileReader.readAsDataURL(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the wallpaper from localStorage, if it exists
|
||||||
try {
|
try {
|
||||||
const wallpaper_data_url = localStorage.getItem("wallpaper-data-url");
|
const wallpaper_data_url = localStorage.getItem("wallpaper-data-url");
|
||||||
const wallpaper_repeat = localStorage.getItem("wallpaper-repeat");
|
const wallpaper_repeat = localStorage.getItem("wallpaper-repeat");
|
||||||
|
|
Loading…
Reference in New Issue