diff --git a/src/components/ConfigDataLoader.tsx b/src/components/ConfigDataLoader.tsx
index 45e8c2b..1aead8a 100644
--- a/src/components/ConfigDataLoader.tsx
+++ b/src/components/ConfigDataLoader.tsx
@@ -53,6 +53,10 @@ const ConfigDataLoader: React.FC = () => {
"usingStrictMode",
"false",
]);
+ await db.execute(`INSERT INTO config (key, value) VALUES (?, ?);`, [
+ "showPauseButton",
+ "false",
+ ]);
console.log("Database initialized with default configuration.");
} else {
console.log("Database already exists. No action needed.");
diff --git a/src/components/StrictModeToggle.tsx b/src/components/FunctionalitySwitchToggle.tsx
similarity index 74%
rename from src/components/StrictModeToggle.tsx
rename to src/components/FunctionalitySwitchToggle.tsx
index 443220e..62018eb 100644
--- a/src/components/StrictModeToggle.tsx
+++ b/src/components/FunctionalitySwitchToggle.tsx
@@ -6,9 +6,15 @@ import Database from "@tauri-apps/plugin-sql";
interface ConfigRow {
value: string;
}
+interface TogglePropsType {
+ functionalityButton: string;
+ title: string;
+ description: string;
+}
-const StrictModeToggle = () => {
+const FunctionalitySwitchToggle = (props: TogglePropsType) => {
const [isStrictModeEnabled, setIsStrictModeEnabled] = useState(false);
+ const { functionalityButton, title, description } = props;
useEffect(() => {
const initializeStrictMode = async () => {
@@ -18,7 +24,7 @@ const StrictModeToggle = () => {
// Retrieve the 'usingStrictMode' value from the config table
const result: ConfigRow[] = await db.select(
- "SELECT value FROM config WHERE key = 'usingStrictMode';"
+ `SELECT value FROM config WHERE key = '${functionalityButton}';`
);
if (result.length > 0) {
@@ -38,7 +44,7 @@ const StrictModeToggle = () => {
// Use an `INSERT OR REPLACE` or `UPDATE` query
await db.execute(
`
- INSERT INTO config (key, value) VALUES ('usingStrictMode', ?)
+ INSERT INTO config (key, value) VALUES ('${functionalityButton}', ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value;
`,
[checked ? "true" : "false"]
@@ -54,17 +60,15 @@ const StrictModeToggle = () => {
-
- This will hide the 'Skip this time' button to force follow the break.
-
+
{description}
@@ -72,4 +76,4 @@ const StrictModeToggle = () => {
);
};
-export default StrictModeToggle;
+export default FunctionalitySwitchToggle;
diff --git a/src/components/LicenseValidationComponent.tsx b/src/components/LicenseValidationComponent.tsx
index 9646d1b..e8e58b1 100644
--- a/src/components/LicenseValidationComponent.tsx
+++ b/src/components/LicenseValidationComponent.tsx
@@ -3,13 +3,10 @@ import Database from "@tauri-apps/plugin-sql";
import toast from "react-hot-toast";
import { fetch as tauriFetch } from "@tauri-apps/plugin-http";
import { useLicenseKey } from "../hooks/useLicenseKey";
-import { useTrigger } from "../contexts/TriggerReRender";
const LicenseValidationComponent: React.FC = () => {
- const [licenseKey, setLicenseKey] = useState
("");
const [isDataLoaded, setIsDataLoaded] = useState(false); // Track loading status
const { licenseData, refreshLicenseData } = useLicenseKey();
- const { triggerUpdate } = useTrigger();
// Function to check if a date is today
const isNotToday = (dateString: string): boolean => {
@@ -24,7 +21,6 @@ const LicenseValidationComponent: React.FC = () => {
useEffect(() => {
const validateLicense = async () => {
- console.log("Running License Validator");
await refreshLicenseData(); // Ensure data is refreshed
setIsDataLoaded(true); // Mark data as loaded
};
@@ -32,17 +28,14 @@ const LicenseValidationComponent: React.FC = () => {
}, []);
useEffect(() => {
- console.log(isNotToday("2024-11-27"), "is not Today");
if (
isDataLoaded &&
licenseData &&
isNotToday(licenseData.last_validated) // Add the new condition
) {
console.log(licenseData);
- setLicenseKey(licenseData.license_key);
handleLicenseValidation(
licenseData.last_validated,
- licenseData.status,
licenseData.license_key
);
}
@@ -51,7 +44,6 @@ const LicenseValidationComponent: React.FC = () => {
// Function to handle license validation and activation status
const handleLicenseValidation = async (
lastValidated: string,
- status: string,
licenseKey: string
) => {
if (!licenseKey) {
@@ -76,41 +68,25 @@ const LicenseValidationComponent: React.FC = () => {
const data = await response.json();
console.log(data);
-
// Proceed only if store_id matches and data is valid
if (
(data.meta?.store_id === 134128 || data.meta?.store_id === 132851) &&
data.valid
) {
- // If the license is valid and last validated is different from today
- if (lastValidated !== today) {
- await updateLicenseStatus(data.license_key.status);
- await updateLastValidatedDate(today);
- } else if (status !== data.license_key.status) {
- // Update the status if it has changed
- await updateLicenseStatus(data.license_key.status);
- }
+ await updateLicenseStatus(data.license_key.status);
+ await updateLastValidatedDate(today);
} else if (
(data.meta?.store_id === 134128 || data.meta?.store_id === 132851) &&
!data.valid
) {
- // If the license is invalid but store_id matches, update status
- if (lastValidated !== today) {
- // If the response is not ok, check the number of days since last validation
- const diffInDays = getDateDiffInDays(lastValidated, today);
- if (diffInDays > 7) {
- // If more than 7 days, update status to what was received in the response
- await updateLicenseStatus("disabled");
- triggerUpdate();
- } else {
- // If less than 7 days, update status
- await updateLicenseStatus(data.license_key.status);
- }
- return;
- } else if (status !== data.license_key.status) {
- // Update the status if it has changed
+ const diffInDays = getDateDiffInDays(lastValidated, today);
+ if (diffInDays > 7) {
+ // If more than 7 days, update status to what was received in the response
await updateLicenseStatus(data.license_key.status);
+ } else {
+ return;
}
+ return;
} else {
console.log(
"Store ID does not match required values. Validation skipped."
@@ -127,7 +103,8 @@ const LicenseValidationComponent: React.FC = () => {
return;
}
} catch (error) {
- toast.error("Failed to validate license. Please try again.");
+ return error;
+ // toast.error("Failed to validate license. Please try again.");
}
};
@@ -135,14 +112,20 @@ const LicenseValidationComponent: React.FC = () => {
const updateLicenseStatus = async (status: string) => {
const db = await Database.load("sqlite:blink_eye_license.db"); // Use the same db connection
if (db) {
- await db.execute(
- `
+ try {
+ // Update the status for the first row (where id = 1)
+ await db.execute(
+ `
UPDATE licenses
SET status = $1
- WHERE license_key = $2`,
- [status, licenseKey] // Update the status in the database
- );
- toast.success(`License status updated to ${status}`);
+ WHERE id = 1`,
+ [status] // Only update the status field
+ );
+ // toast.success(`License status updated to ${status}`);
+ } catch (error) {
+ console.error("Failed to update status:", error);
+ toast.error("Failed to update license status.");
+ }
}
};
@@ -150,14 +133,18 @@ const LicenseValidationComponent: React.FC = () => {
const updateLastValidatedDate = async (today: string) => {
const db = await Database.load("sqlite:blink_eye_license.db"); // Use the same db connection
if (db) {
- await db.execute(
- `
+ try {
+ await db.execute(
+ `
UPDATE licenses
SET last_validated = $1
- WHERE license_key = $2`,
- [today, licenseKey] // Update the last validated date in the database
- );
- toast.success("License last validated date updated");
+ WHERE id = 1`,
+ [today]
+ );
+ } catch (error) {
+ console.error("Failed to update last validated date:", error);
+ toast.error("Failed to update license last validated date.");
+ }
}
};
diff --git a/src/components/LoadingSpinner.tsx b/src/components/LoadingSpinner.tsx
index 5e9e9f3..25aaef2 100644
--- a/src/components/LoadingSpinner.tsx
+++ b/src/components/LoadingSpinner.tsx
@@ -1,11 +1,10 @@
-import { Loader2 } from "lucide-react";
+import { Loader } from "lucide-react";
export function LoadingSpinner() {
return (
-
-
Initializing application...
+
);
diff --git a/src/components/window/AllSettings.tsx b/src/components/window/AllSettings.tsx
index dcaa6f5..87d3f3e 100644
--- a/src/components/window/AllSettings.tsx
+++ b/src/components/window/AllSettings.tsx
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import AutoStartToggle from "../AutoStartToggle";
-import StrictModeToggle from "../StrictModeToggle";
+import FunctionalitySwitchToggle from "../FunctionalitySwitchToggle";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { Label } from "../ui/label";
@@ -72,7 +72,16 @@ const AllSettings = () => {
-
+
+
{/* Input and Button Section */}
diff --git a/src/components/window/Reminder.tsx b/src/components/window/Reminder.tsx
index 5477246..50d25dd 100644
--- a/src/components/window/Reminder.tsx
+++ b/src/components/window/Reminder.tsx
@@ -4,7 +4,7 @@ import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { load } from "@tauri-apps/plugin-store";
import CurrentTime from "../CurrentTime";
import ScreenOnTime from "../ScreenOnTime";
-import { CloudDownload } from "lucide-react";
+import { CloudDownload, PauseIcon, Play } from "lucide-react";
import { Progress } from "../ui/progress";
import * as path from "@tauri-apps/api/path";
import { convertFileSrc } from "@tauri-apps/api/core";
@@ -39,6 +39,9 @@ const Reminder: React.FC = () => {
const [reminderDuration, setReminderDuration] = useState
(20);
const [reminderText, setStoredReminderText] = useState("");
const [isUsingStictMode, setIsUsingStrictMode] = useState(false);
+ const [isShowingPauseButton, setIsShowingPauseButton] =
+ useState(false);
+ const [isPaused, setIsPaused] = useState(false);
useEffect(() => {
const fetchReminderScreenInfo = async () => {
@@ -90,6 +93,13 @@ const Reminder: React.FC = () => {
if (strictModeResult.length > 0) {
setIsUsingStrictMode(strictModeResult[0].value === "true");
}
+ const pauseModeResult: ConfigRow[] = await db.select(
+ "SELECT value FROM config WHERE key = 'showPauseButton';"
+ );
+
+ if (pauseModeResult.length > 0) {
+ setIsShowingPauseButton(pauseModeResult[0].value === "true");
+ }
};
fetchReminderScreenInfo();
@@ -107,7 +117,7 @@ const Reminder: React.FC = () => {
};
useEffect(() => {
- if (timeLeft <= 1) {
+ if (timeLeft <= 1 && canAccessPremiumFeatures) {
handlePlayAudio();
}
if (timeLeft <= 0) {
@@ -115,12 +125,14 @@ const Reminder: React.FC = () => {
return;
}
- const timer = setInterval(() => {
- setTimeLeft((prevTime) => prevTime - 1);
- }, 1000);
+ if (!isPaused) {
+ const timer = setInterval(() => {
+ setTimeLeft((prevTime) => prevTime - 1);
+ }, 1000);
- return () => clearInterval(timer);
- }, [timeLeft]);
+ return () => clearInterval(timer);
+ }
+ }, [timeLeft, isPaused]);
const renderBackground = () => {
switch (backgroundStyle) {
@@ -168,22 +180,36 @@ const Reminder: React.FC = () => {
{reminderText || "Look 20 feet far away to protect your eyes."}
- {!isUsingStictMode && (
-
- )}
+ {isPaused ? (
+
+ ) : (
+
+ )}
+
+ )}
+
diff --git a/src/components/window/Settings.tsx b/src/components/window/Settings.tsx
index 60e1f96..91c1e7f 100644
--- a/src/components/window/Settings.tsx
+++ b/src/components/window/Settings.tsx
@@ -8,7 +8,7 @@ import toast from "react-hot-toast";
import { useTrigger } from "../../contexts/TriggerReRender";
const Settings = () => {
- const { triggerUpdate } = useTrigger(); // Access triggerUpdate from the context
+ const { triggerUpdate } = useTrigger();
const [interval, setInterval] = useState(20);
const [duration, setDuration] = useState(20);
const [reminderText, setReminderText] = useState("");
diff --git a/src/main.tsx b/src/main.tsx
index 5bb5c1f..b49382f 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -10,6 +10,12 @@ import ConfigDataLoader from "./components/ConfigDataLoader";
import ReminderHandler from "./components/ReminderHandler";
import { TriggerProvider } from "./contexts/TriggerReRender";
+if (!import.meta.env.DEV) {
+ document.oncontextmenu = (event) => {
+ event.preventDefault();
+ };
+}
+
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
@@ -17,8 +23,8 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
+
-