diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a9a5a28 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab +tab_width = 2 \ No newline at end of file diff --git a/Assets/sc1.gif b/Assets/sc1.gif index ab2b739..b911035 100644 Binary files a/Assets/sc1.gif and b/Assets/sc1.gif differ diff --git a/Assets/sc2.png b/Assets/sc2.png index 7fa6f22..4dd7f58 100644 Binary files a/Assets/sc2.png and b/Assets/sc2.png differ diff --git a/Assets/sc3.png b/Assets/sc3.png index 08bfa16..cd3a3d2 100644 Binary files a/Assets/sc3.png and b/Assets/sc3.png differ diff --git a/Assets/sc4.png b/Assets/sc4.png index c852cac..c919e1e 100644 Binary files a/Assets/sc4.png and b/Assets/sc4.png differ diff --git a/manifest.json b/manifest.json index 9488038..b093a5a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "live-wallpaper", "name": "Live Background", - "version": "1.2.4", + "version": "1.2.5", "minAppVersion": "1.1.0", "author": "Rememememe :3", "authorUrl": "https://github.com/remememe", diff --git a/package-lock.json b/package-lock.json index 0671e48..32fe61b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "discordpresence", - "version": "1.2.4", + "version": "1.2.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "discordpresence", - "version": "1.2.4", + "version": "1.2.5", "license": "ISC", "devDependencies": { "@types/node": "^22.14.1", diff --git a/package.json b/package.json index ff5d188..d17c73b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discordpresence", - "version": "1.2.4", + "version": "1.2.5", "main": "main.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/src/Scheduler.ts b/src/Scheduler.ts index 13a464f..538378e 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -10,7 +10,6 @@ export default class Scheduler { if (!Wallpapers || Wallpapers.length === 0 || !options) { return null; } - if (options.dayNightMode && options.dayStartTime && options.nightStartTime) { const [dayHour, dayMinute] = options.dayStartTime.split(":").map(Number); const [nightHour, nightMinute] = options.nightStartTime.split(":").map(Number); @@ -26,7 +25,8 @@ export default class Scheduler { } if (options.weekly) { - const day = now.getDay(); + let day = now.getDay(); + day = (day + 6) % 7; if (Wallpapers[day]) return day; } @@ -41,4 +41,9 @@ export default class Scheduler { const timePattern = /^(?:[01]?\d|2[0-3])(?::[0-5]\d){1,2}$/; return timePattern.test(text); } + static Check(options: ScheduledWallpapersOptions, exceptKey?: keyof ScheduledWallpapersOptions): boolean { + return Object.entries(options).some( + ([key, value]) => key !== exceptKey && value === true + ); + } } diff --git a/src/Settings/ScheduledWallpaperSettings.ts b/src/Settings/ScheduledWallpaperSettings.ts index c606388..0404f2e 100644 --- a/src/Settings/ScheduledWallpaperSettings.ts +++ b/src/Settings/ScheduledWallpaperSettings.ts @@ -1,4 +1,4 @@ -import { App,PluginSettingTab,Setting,Notice} from "obsidian"; +import { App, PluginSettingTab, Setting, Notice } from "obsidian"; import LiveWallpaperPlugin from "../main"; import Scheduler from "../Scheduler"; export class ScheduledApp extends PluginSettingTab { @@ -21,6 +21,16 @@ export class ScheduledApp extends PluginSettingTab { this.plugin.settings.scheduledWallpapers.options.dayNightMode ) .onChange(async (value) => { + const otherEnabled = Scheduler.Check( + this.plugin.settings.scheduledWallpapers.options, + "dayNightMode" + ); + + if (value && otherEnabled) { + new Notice("Only one mode can be enabled at a time."); + toggle.setValue(false); + return; + } this.plugin.settings.scheduledWallpapers.options.dayNightMode = value; await this.plugin.saveSettings(); @@ -53,8 +63,10 @@ export class ScheduledApp extends PluginSettingTab { .setTooltip("Browse for file") .onClick(() => this.plugin.openFilePicker(1)) ); - let dayTimeValue = this.plugin.settings.scheduledWallpapers.options.dayStartTime; - let nightTimeValue = this.plugin.settings.scheduledWallpapers.options.nightStartTime; + let dayTimeValue = + this.plugin.settings.scheduledWallpapers.options.dayStartTime; + let nightTimeValue = + this.plugin.settings.scheduledWallpapers.options.nightStartTime; const Time = new Setting(containerEl) .setName("Time") @@ -63,7 +75,9 @@ export class ScheduledApp extends PluginSettingTab { Time.addText((area) => { area .setPlaceholder("HH:MM") - .setValue(this.plugin.settings.scheduledWallpapers.options.dayStartTime ?? "") + .setValue( + this.plugin.settings.scheduledWallpapers.options.dayStartTime ?? "" + ) .onChange((value) => { dayTimeValue = value; }); @@ -72,32 +86,101 @@ export class ScheduledApp extends PluginSettingTab { Time.addText((area) => { area .setPlaceholder("HH:MM") - .setValue(this.plugin.settings.scheduledWallpapers.options.nightStartTime ?? "") + .setValue( + this.plugin.settings.scheduledWallpapers.options.nightStartTime ?? + "" + ) .onChange((value) => { nightTimeValue = value; }); }); + new Setting(containerEl).addButton((btn) => + btn + .setButtonText("Apply now") + .setCta() + .onClick(async () => { + if ( + Scheduler.ValidateText(dayTimeValue) && + Scheduler.ValidateText(nightTimeValue) + ) { + this.plugin.settings.scheduledWallpapers.options.dayStartTime = + dayTimeValue; + this.plugin.settings.scheduledWallpapers.options.nightStartTime = + nightTimeValue; + await this.plugin.saveSettings(); + new Notice("Wallpaper schedule has been set."); + this.plugin.applyWallpaper(true); + } else { + new Notice( + "One or both time values are invalid. Use HH:MM format." + ); + } + }) + ); + } + new Setting(containerEl) + .setName("Weekly mode") + .setDesc("Enable different wallpapers for any day") + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.scheduledWallpapers.options.weekly) + .onChange(async (value) => { + const otherEnabled = Scheduler.Check( + this.plugin.settings.scheduledWallpapers.options, + "weekly" + ); + + if (value && otherEnabled) { + new Notice("Only one mode can be enabled at a time."); + toggle.setValue(false); + return; + } + this.plugin.settings.scheduledWallpapers.options.weekly = value; + await this.plugin.saveSettings(); + this.display(); + this.plugin.applyWallpaper(true); + }) + ); + + if (this.plugin.settings.scheduledWallpapers.options.weekly) { + const paths = this.plugin.settings.scheduledWallpapers.wallpaperPaths; + paths.forEach((path, i) => { + if (!path) paths[i] = ""; + }); + + let selectedDay = "Monday"; + const daysOfWeek = [ + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday", + ]; new Setting(containerEl) + .setName("Day Wallpaper") + .setDesc("Wallpaper to use during the day") .addButton((btn) => btn - .setButtonText("Apply now") - .setCta() - .onClick(async () => { - if ( - Scheduler.ValidateText(dayTimeValue) && - Scheduler.ValidateText(nightTimeValue) - ) { - this.plugin.settings.scheduledWallpapers.options.dayStartTime = dayTimeValue; - this.plugin.settings.scheduledWallpapers.options.nightStartTime = nightTimeValue; - await this.plugin.saveSettings(); - new Notice("Wallpaper schedule has been set."); - this.plugin.applyWallpaper(true); + .setIcon("folder-open") + .setTooltip("Browse for file") + .onClick(() => { + const index = daysOfWeek.indexOf(selectedDay); + if (index !== -1) { + this.plugin.openFilePicker(index); } else { - new Notice("One or both time values are invalid. Use HH:MM format."); + console.warn("Invalid day selected"); } }) - ); + ) + .addDropdown((dropdown) => { + daysOfWeek.forEach((day) => { + dropdown.addOption(day, day); + }); + dropdown.setValue(selectedDay); + }); } } -} +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 5ffc4af..0d0260b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -178,7 +178,10 @@ export default class LiveWallpaperPlugin extends Plugin { if (newPath !== this.lastPath || newType !== this.lastType) { const newMedia = await this.createMediaElement(); if (newMedia) { - container.replaceChild(newMedia, media); + if (media && media.parentElement) { + media.remove(); + } + container.appendChild(newMedia); media = newMedia; this.lastPath = newPath; this.lastType = newType; @@ -277,7 +280,6 @@ export default class LiveWallpaperPlugin extends Plugin { height: '100%', objectFit: 'cover' }); - if (isVideo) { (media as HTMLVideoElement).autoplay = true; (media as HTMLVideoElement).loop = true; @@ -289,7 +291,7 @@ export default class LiveWallpaperPlugin extends Plugin { async openFilePicker(slotIndex?: number) { const fileInput = document.createElement('input'); fileInput.type = 'file'; - fileInput.accept = '.jpg,.jpeg,.png,.gif,.mp4,.webm'; + fileInput.accept = '.jpg,.jpeg,.png,.gif,.mp4,.webm,.avif'; fileInput.multiple = false; fileInput.addEventListener('change', async (event) => { @@ -297,7 +299,7 @@ export default class LiveWallpaperPlugin extends Plugin { if (!target.files || target.files.length === 0) return; const file = target.files[0]; - const allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'mp4', 'webm']; + const allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'mp4', 'webm','avif']; const extension = file.name.split('.').pop()?.toLowerCase(); if (!extension || !allowedExtensions.includes(extension)) {