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
function ensureImagesFolder(imageDirectory) { | |
if (!fs.existsSync(imageDirectory)) { | |
console.log("Creating folder for image storage ..."); | |
fs.mkdirSync(imageDirectory); | |
} | |
} |
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
function cleanupImages(imageDirectory, imageDirectoryCapacity) { | |
const images = fs.readdirSync(imageDirectory); | |
if (images.length >= imageDirectoryCapacity) { | |
console.log("Cleaning up space ..."); | |
fs.unlinkSync(imageDirectory + "/" + images.pop()); | |
} | |
} |
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
async function updateBackground(imageResolution, imageCategories, imageDirectory) { | |
console.log("Starting wallpaper change procedure ..."); | |
try { | |
const imageResponse = await fetch(`https://source.unsplash.com/featured/${imageResolution}?${imageCategories}`); | |
const image = await download.image({ url: imageResponse.url, dest: imageDirectory }); | |
await wallpaper.set(image.filename); | |
console.log("Wallpaper changed successfully!"); | |
} catch (e) { |
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
"use strict"; | |
const fetch = require("node-fetch"); | |
const download = require("image-downloader"); | |
const wallpaper = require("wallpaper"); | |
const schedule = require("node-schedule"); | |
const fs = require("fs"); | |
const imageDirectory = "./images"; | |
const imageDirectoryCapacity = 10; |
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
schedule.scheduleJob("0 * * * *", async () => { | |
await ensureImagesFolder(imageDirectory); | |
await cleanupImages(imageDirectory, imageDirectoryCapacity); | |
await updateBackground(imageResolution, imageCategories, imageDirectory); | |
}); |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.dg.osgi</groupId> | |
<artifactId>calculator-provider</artifactId> | |
<version>1.0.0-SNAPSHOT</version> |
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
public interface Calculator { | |
int add(int a, int b); | |
int multiply(int a, int b); | |
} |
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
import com.dg.osgi.calculator.provider.api.Calculator; | |
import org.osgi.service.component.annotations.Component; | |
@Component | |
public class CalculatorImpl implements Calculator { | |
public int add(int a, int b) { | |
return a + b; | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.dg.osgi</groupId> | |
<artifactId>calculator-consumer</artifactId> | |
<version>1.0.0-SNAPSHOT</version> |
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
import com.dg.osgi.calculator.provider.api.Calculator; | |
import org.osgi.service.component.annotations.Activate; | |
import org.osgi.service.component.annotations.Component; | |
import org.osgi.service.component.annotations.Reference; | |
@Component | |
public class CalculatorConsumer { | |
@Reference | |
private Calculator calculator; |
OlderNewer