{/* Header */}
diff --git a/src/ui/store/index.tsx b/src/ui/store/index.tsx
new file mode 100644
index 0000000..4b7745d
--- /dev/null
+++ b/src/ui/store/index.tsx
@@ -0,0 +1,12 @@
+// src/store/index.ts
+import { configureStore } from "@reduxjs/toolkit";
+import windowReducer from "./windowSlice";
+
+export const store = configureStore({
+ reducer: {
+ window: windowReducer,
+ },
+});
+
+export type RootState = ReturnType;
+export type AppDispatch = typeof store.dispatch;
diff --git a/src/ui/store/windowSlice.tsx b/src/ui/store/windowSlice.tsx
new file mode 100644
index 0000000..6b8d57f
--- /dev/null
+++ b/src/ui/store/windowSlice.tsx
@@ -0,0 +1,128 @@
+// src/store/windowSlice.ts
+import { createSlice, PayloadAction } from "@reduxjs/toolkit";
+
+export interface OwnerInfo {
+ processId: number;
+ path: string;
+ name: string;
+}
+
+export interface WindowInfo {
+ platform: string;
+ id: number;
+ title: string;
+ owner: OwnerInfo;
+ bounds: Record;
+ contentBounds: Record;
+ memoryUsage: number;
+ timestamp: string;
+}
+
+export interface ProjectWindowLog {
+ projectId: string;
+ projectName: string;
+ appName: string;
+ windowTitle: string;
+ platform: string;
+ duration: number; // in seconds
+ startTime: string;
+ endTime: string;
+ memoryUsage: number;
+}
+
+interface WindowState {
+ activeWindow: WindowInfo | null;
+ activeSince: number | null;
+ activeProjectId: string | null;
+ activeProjectName: string | null;
+ windowLogs: ProjectWindowLog[];
+}
+
+const initialState: WindowState = {
+ activeWindow: null,
+ activeSince: null,
+ activeProjectId: null,
+ activeProjectName: null,
+ windowLogs: [],
+};
+
+interface SetActiveWindowPayload {
+ window: WindowInfo;
+ projectId: string;
+ projectName: string;
+}
+
+const windowSlice = createSlice({
+ name: "window",
+ initialState,
+ reducers: {
+ // โ
Start tracking window for a project
+ setActiveWindow: (state, action: PayloadAction) => {
+ const { window, projectId, projectName } = action.payload;
+ const now = Date.now();
+
+ // ๐ Log previous window before switching
+ if (state.activeWindow && state.activeSince && state.activeProjectId) {
+ const duration = Math.floor((now - state.activeSince) / 1000);
+
+ const logEntry: ProjectWindowLog = {
+ projectId: state.activeProjectId,
+ projectName: state.activeProjectName || "Untitled",
+ appName: state.activeWindow.owner.name,
+ windowTitle: state.activeWindow.title,
+ platform: state.activeWindow.platform,
+ duration,
+ startTime: new Date(state.activeSince).toISOString(),
+ endTime: new Date(now).toISOString(),
+ memoryUsage: state.activeWindow.memoryUsage,
+ };
+
+ state.windowLogs.push(logEntry);
+ console.log("๐งพ Log saved:", logEntry);
+ }
+
+ // ๐ Update new active window + project context
+ state.activeWindow = window;
+ state.activeSince = now;
+ state.activeProjectId = projectId;
+ state.activeProjectName = projectName;
+ },
+
+ // โ
Stop tracking (finalize)
+ finalizeActiveWindow: (state) => {
+ if (state.activeWindow && state.activeSince && state.activeProjectId) {
+ const now = Date.now();
+ const duration = Math.floor((now - state.activeSince) / 1000);
+
+ const logEntry: ProjectWindowLog = {
+ projectId: state.activeProjectId,
+ projectName: state.activeProjectName || "Untitled",
+ appName: state.activeWindow.owner.name,
+ windowTitle: state.activeWindow.title,
+ platform: state.activeWindow.platform,
+ duration,
+ startTime: new Date(state.activeSince).toISOString(),
+ endTime: new Date(now).toISOString(),
+ memoryUsage: state.activeWindow.memoryUsage,
+ };
+
+ state.windowLogs.push(logEntry);
+ console.log("โ
Final log saved:", logEntry);
+ }
+
+ state.activeWindow = null;
+ state.activeSince = null;
+ state.activeProjectId = null;
+ state.activeProjectName = null;
+ },
+
+ clearWindowLogs: (state) => {
+ state.windowLogs = [];
+ },
+ },
+});
+
+export const { setActiveWindow, finalizeActiveWindow, clearWindowLogs } =
+ windowSlice.actions;
+
+export default windowSlice.reducer;
diff --git a/types.d.ts b/types.d.ts
index 7a027ad..60eef43 100644
--- a/types.d.ts
+++ b/types.d.ts
@@ -32,7 +32,7 @@ interface Window {
getActiveAppDetails: () => {};
toggleCloseBtn: (shouldEnable: boolean) => {},
resizeWindow: (width: number, height: number) => {},
- getRunningApps: () => Promise<{name: string, pid:string}[]>,
+ onWindowUpdate: (callback: (data: any) => void) => void;
};
}