Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export type BackendEvents = DefineEvents<{
totalSize: string;
caidoTotalSize: string;
}) => void;
"bytecap:project-changed": (data: {
projectName: string | null;
projectId: string | null;
}) => void;
}>;

interface FileInfo {
Expand Down Expand Up @@ -312,5 +316,19 @@ export function init(sdk: BytecapBackendSDK) {
sdk.console.log("Bytecap backend starting...");
sdk.api.register("getWorkspaceFiles", getWorkspaceFiles);
sdk.api.register("checkFileSizeThresholds", checkFileSizeThresholds);

// Listen for project changes
sdk.events.onProjectChange((sdk, project) => {
const projectName = project?.getName() ?? null;
const projectId = project?.getId() ?? null;
sdk.console.log(`Project changed to: ${projectName}`);

// Send event to frontend to refresh data
sdk.api.send("bytecap:project-changed", {
projectName,
projectId
});
});

sdk.console.log("Bytecap backend initialized successfully");
}
45 changes: 40 additions & 5 deletions packages/frontend/src/views/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,37 @@ interface DirectoryInfo {
// Retrieve the SDK instance to interact with the backend
const sdk = useSDK();

// Reactive state
const thresholdMB = ref(10);
const enableWarnings = ref(true);
const warningAt75Percent = ref(true);
const warningAt90Percent = ref(true);
// Load settings from localStorage with defaults
const loadSettings = () => {
const saved = localStorage.getItem('bytecap-settings');
if (saved) {
try {
return JSON.parse(saved);
} catch {
return {};
}
}
return {};
};

// Save settings to localStorage
const saveSettings = () => {
const settings = {
thresholdMB: thresholdMB.value,
enableWarnings: enableWarnings.value,
warningAt75Percent: warningAt75Percent.value,
warningAt90Percent: warningAt90Percent.value,
};
localStorage.setItem('bytecap-settings', JSON.stringify(settings));
};

const savedSettings = loadSettings();

// Reactive state with persisted values
const thresholdMB = ref(savedSettings.thresholdMB ?? 10);
const enableWarnings = ref(savedSettings.enableWarnings ?? true);
const warningAt75Percent = ref(savedSettings.warningAt75Percent ?? true);
const warningAt90Percent = ref(savedSettings.warningAt90Percent ?? true);
const workspaceFiles = ref<DirectoryInfo>({
files: [],
totalSize: 0,
Expand Down Expand Up @@ -127,6 +153,9 @@ const onRefreshClick = async () => {

// Apply settings and check thresholds manually
const applySettings = async () => {
// Save settings to localStorage
saveSettings();

// Clear any existing notifications first
clearAllNotifications();

Expand Down Expand Up @@ -248,6 +277,12 @@ onMounted(() => {
scanSummary.value = summary;
});

// Listen for project changes and refresh data
sdk.backend.onEvent("bytecap:project-changed", (data) => {
console.log(`Project changed to: ${data.projectName}`);
loadWorkspaceFiles();
});

loadWorkspaceFiles();
});
</script>
Expand Down
Loading