Add weekly wallpapers and fix bug
9
.editorconfig
Normal file
|
|
@ -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
|
||||
BIN
Assets/sc1.gif
|
Before Width: | Height: | Size: 17 MiB After Width: | Height: | Size: 21 MiB |
BIN
Assets/sc2.png
|
Before Width: | Height: | Size: 532 KiB After Width: | Height: | Size: 410 KiB |
BIN
Assets/sc3.png
|
Before Width: | Height: | Size: 840 KiB After Width: | Height: | Size: 656 KiB |
BIN
Assets/sc4.png
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 790 KiB |
|
|
@ -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",
|
||||
|
|
|
|||
4
package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
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)) {
|
||||
|
|
|
|||