From 7fbc09b2b8d2f8acbeb1ff7e8a2df9aecce2f622 Mon Sep 17 00:00:00 2001 From: emincangencer <33095924+emincangencer@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:04:50 +0300 Subject: [PATCH] setDelay: add x seconds y miliseconds logic add style semicolon --- src/settings/setDelay.ts | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/settings/setDelay.ts b/src/settings/setDelay.ts index f9a2fa4..015c10a 100644 --- a/src/settings/setDelay.ts +++ b/src/settings/setDelay.ts @@ -3,20 +3,34 @@ import FileHider from "../main"; export class SetDelaySetting { - public static create(plugin: FileHider, container: HTMLElement) { - return new Setting(container) - .setName(`Set Delay`) - .setDesc(`Set the delay for hiding after explorer loads.`) - .addText(text => { - text - .setValue(plugin.settings.delay.toString()) - .onChange(value => { - const delay = parseInt(value, 10); - if (!isNaN(delay)) { - plugin.settings.delay = delay; - plugin.saveSettings(); - } - }); - }); - }; -}; \ No newline at end of file + public static create(plugin: FileHider, container: HTMLElement) { + return new Setting(container) + .setName(`Set Delay`) + .setDesc(`Set the delay for hiding after the explorer loads. "X seconds Y milliseconds". Default: "0s 500ms".`) + .addText(text => { + // Convert milliseconds to seconds and milliseconds + const seconds = Math.floor(plugin.settings.delay / 1000); + const milliseconds = plugin.settings.delay % 1000; + + text + .setValue(`${seconds}s ${milliseconds}ms`) + .onChange(value => { + // Regular expression to match the input format "Xs Yms" + const match = value.match(/(?:(\d+)s)?\s*(\d*)ms?/); + if (match) { + const seconds = parseInt(match[1] || "0", 10); + const milliseconds = parseInt(match[2] || "0", 10); + const delay = (seconds * 1000) + milliseconds; + + if (!isNaN(delay)) { + plugin.settings.delay = delay; + plugin.saveSettings(); + }; + } else { + // Handle invalid format input + text.setValue(`${Math.floor(plugin.settings.delay / 1000)}s ${plugin.settings.delay % 1000}ms`); + }; + }); + }); + }; +};