wallchpaper
Version:
Change wallpaper after an adjustable time
40 lines • 1.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const array_1 = require("./utils/array");
const supportedExtensions = ['.png', '.jpg', '.jpeg'];
class WallpaperManager {
constructor(config) {
this.wallpaperPaths = [];
this.config = config;
this.loadFromFolders();
}
loadFilePathsFromFolders() {
return array_1.flatArray(this.config.folders.map(folderPath => {
const files = fs_1.default.readdirSync(folderPath);
return files
.filter(file => supportedExtensions.includes(path_1.default.extname(file)))
.map(file => this.parsePath(folderPath, file));
}));
}
loadFromFolders() {
const filePaths = this.loadFilePathsFromFolders();
this.wallpaperPaths.push(...array_1.shuffleArray(filePaths));
}
reaload() {
const filePaths = this.loadFilePathsFromFolders();
this.wallpaperPaths = filePaths;
}
next() {
return this.wallpaperPaths.shift();
}
parsePath(folder, filePath) {
return `file://${path_1.default.join(folder, filePath)}`;
}
}
exports.WallpaperManager = WallpaperManager;
//# sourceMappingURL=wallpaper.manager.js.map