mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-05 18:20:39 -08:00
* Add watch-filesystem-adaptor plugin and worker IPC Introduces the watch-filesystem-adaptor TiddlyWiki plugin, enabling tag-based routing of tiddlers to sub-wikis by querying workspace info via worker thread IPC. Adds workerServiceCaller utility for worker-to-main service calls, updates workerAdapter and bindServiceAndProxy to support explicit service registration for workers, and documents the new IPC architecture. Updates wikiWorker and startNodeJSWiki to preload workspace ID and load the new plugin. Also updates the plugin build script to compile and copy the new plugin. * test: wiki operation steps * Add per-wiki labeled logging and console hijack Introduces labeled loggers for each wiki, writing logs to separate files. Adds a logFor method to NativeService for logging with labels, updates interfaces, and hijacks worker thread console methods to redirect logs to main process for wiki-specific logging. Refactors workspaceID usage to workspace object for improved context. * Update log handling for wiki worker and tests Enhanced logging tests to check all log files, including wiki logs. Adjusted logger to write wiki worker logs to the main log directory. Updated e2e app script comment for correct usage. * Enable worker thread access to main process services Introduces a proxy system allowing worker threads to call main process services with full type safety and observable support. Adds worker-side service proxy creation, auto-attaches proxies to global.service, and updates service registration to use IPC descriptors. Documentation is added for usage and architecture. * Update ErrorDuringStart.md * chore: upgrade ipc cat and allow clean vite cache * Refactor wiki worker initialization and service readiness Moved wiki worker implementation from wikiWorker.ts to wikiWorker/index.ts and deleted the old file. Added servicesReady.ts to manage worker service readiness and callbacks, and integrated notifyServicesReady into the worker lifecycle. Updated console hijack logic to wait for service readiness before hijacking. Improved worker management in Wiki service to support detaching workers and notifying readiness. * Refactor wiki logging to use centralized logger Removed per-wiki loggers and console hijacking in favor of a single labeled logger. All wiki logs, including errors, are now written to a unified log file. Updated worker and service code to route logs through the main logger and removed obsolete log file naming and management logic. * fix: ipc cat log error * Refactor wiki test paths and improve file save logic Updated test step to use wikiTestRootPath for directory replacements and added wikiTestRootPath to paths.ts for clarity. Improved error handling and directory logic in watch-filesystem-adaptor.ts, including saving tiddlers directly to sub-wiki folders, more informative logging, and ensuring cleanup after file writes is properly awaited. * rename * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * feat: basic watch-fs * feat: check file not exist * refactor: use exponential-backoff * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * fix: cleanup * Refactor test setup and cleanup to separate file Moved Before and After hooks from application.ts to a new cleanup.ts file for better organization and separation of concerns. Also removed unused imports and related code from application.ts. Minor type simplification in agent.ts for row parsing. * test: modify and rename * feat: enableFileSystemWatch * refactor: unused utils.ts * Update watch-filesystem-adaptor.ts * refactor: use node-sentinel-file-watcher * refactor: extract to two classes * The logFor method lacks JSDoc describing the level parameter's * Update startNodeJSWiki.ts * fix: napi build * Update electron-rebuild command in workflows Changed the electron-rebuild command in release and test GitHub Actions workflows to use a comma-separated list for native modules instead of multiple -w flags. This simplifies the rebuild step for better-sqlite3 and nsfw modules. * lint * not build nsfw, try use prebuild * Update package.json * Update workerAdapter.ts * remove subWikiPlugin.ts as we use new filesystem adaptor that supports tag based sub wiki * fix: build * fix: wrong type * lint * remove `act(...)` warnings * uninstall chokidar * refactor and test * lint * remove unused logic, as we already use ipc syncadaptor, not afriad of wiki status change * Update translation.json * test: increast timeout in CI * Update application.ts * fix: AI's wrong cleanup logic hidden by as unknown as * fix: AI's wrong as unknown as * Update agent.feature * Update wikiSearchPlugin.ts * fix: A dynamic import callback was not specified.
196 lines
7.2 KiB
TypeScript
196 lines
7.2 KiB
TypeScript
import { When } from '@cucumber/cucumber';
|
|
import type { ElectronApplication } from 'playwright';
|
|
import type { ApplicationWorld } from './application';
|
|
import { checkWindowDimension, checkWindowName } from './application';
|
|
import { WebContentsView } from 'electron';
|
|
|
|
// Helper function to get browser view info from Electron window
|
|
async function getBrowserViewInfo(
|
|
app: ElectronApplication,
|
|
dimensions: { width: number; height: number },
|
|
): Promise<{ view?: { x: number; y: number; width: number; height: number }; windowContent?: { width: number; height: number }; hasView: boolean }> {
|
|
return app.evaluate(async ({ BrowserWindow }, dimensions: { width: number; height: number }) => {
|
|
const windows = BrowserWindow.getAllWindows();
|
|
|
|
// Find the target window by dimensions
|
|
const targetWindow = windows.find(win => {
|
|
const bounds = win.getBounds();
|
|
return bounds.width === dimensions.width && bounds.height === dimensions.height;
|
|
});
|
|
|
|
if (!targetWindow) {
|
|
return { hasView: false };
|
|
}
|
|
|
|
// Get all child views (WebContentsView instances) attached to this specific window
|
|
if (targetWindow.contentView && 'children' in targetWindow.contentView) {
|
|
const views = targetWindow.contentView.children || [];
|
|
|
|
for (const view of views) {
|
|
// Type guard to check if view is a WebContentsView
|
|
if (view && view.constructor.name === 'WebContentsView') {
|
|
const webContentsView = view as WebContentsView;
|
|
const viewBounds = webContentsView.getBounds();
|
|
const windowContentBounds = targetWindow.getContentBounds();
|
|
|
|
return {
|
|
view: viewBounds,
|
|
windowContent: windowContentBounds,
|
|
hasView: true,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
return { hasView: false };
|
|
}, dimensions);
|
|
}
|
|
|
|
When('I confirm the {string} window exists', async function(this: ApplicationWorld, windowType: string) {
|
|
if (!this.app) {
|
|
throw new Error('Application is not launched');
|
|
}
|
|
|
|
const success = await this.waitForWindowCondition(
|
|
windowType,
|
|
(window) => window !== undefined && !window.isClosed(),
|
|
);
|
|
|
|
if (!success) {
|
|
throw new Error(`${windowType} window was not found or is closed`);
|
|
}
|
|
});
|
|
|
|
When('I confirm the {string} window visible', async function(this: ApplicationWorld, windowType: string) {
|
|
if (!this.app) {
|
|
throw new Error('Application is not launched');
|
|
}
|
|
|
|
const success = await this.waitForWindowCondition(
|
|
windowType,
|
|
(window, isVisible) => window !== undefined && !window.isClosed() && isVisible,
|
|
);
|
|
|
|
if (!success) {
|
|
throw new Error(`${windowType} window was not visible after multiple attempts`);
|
|
}
|
|
});
|
|
|
|
When('I confirm the {string} window not visible', async function(this: ApplicationWorld, windowType: string) {
|
|
if (!this.app) {
|
|
throw new Error('Application is not launched');
|
|
}
|
|
|
|
const success = await this.waitForWindowCondition(
|
|
windowType,
|
|
(window, isVisible) => window !== undefined && !window.isClosed() && !isVisible,
|
|
);
|
|
|
|
if (!success) {
|
|
throw new Error(`${windowType} window was visible or not found after multiple attempts`);
|
|
}
|
|
});
|
|
|
|
When('I confirm the {string} window does not exist', async function(this: ApplicationWorld, windowType: string) {
|
|
if (!this.app) {
|
|
throw new Error('Application is not launched');
|
|
}
|
|
|
|
const success = await this.waitForWindowCondition(
|
|
windowType,
|
|
(window) => window === undefined,
|
|
);
|
|
|
|
if (!success) {
|
|
throw new Error(`${windowType} window still exists after multiple attempts`);
|
|
}
|
|
});
|
|
|
|
When('I confirm the {string} window browser view is positioned within visible window bounds', async function(this: ApplicationWorld, windowType: string) {
|
|
if (!this.app) {
|
|
throw new Error('Application is not available');
|
|
}
|
|
|
|
const targetWindow = await this.findWindowByType(windowType);
|
|
if (!targetWindow || targetWindow.isClosed()) {
|
|
throw new Error(`Window "${windowType}" is not available or has been closed`);
|
|
}
|
|
|
|
// Get the window dimensions to identify it - must match a defined WindowNames
|
|
const windowName = checkWindowName(windowType);
|
|
const windowDimensions = checkWindowDimension(windowName);
|
|
|
|
// Get browser view bounds for the specific window type
|
|
const viewInfo = await getBrowserViewInfo(this.app, windowDimensions);
|
|
|
|
if (!viewInfo.hasView || !viewInfo.view || !viewInfo.windowContent) {
|
|
throw new Error(`No browser view found in "${windowType}" window`);
|
|
}
|
|
|
|
// Check if browser view is within window content bounds
|
|
// View coordinates are relative to the window, so we check if they're within the content area
|
|
const viewRight = viewInfo.view.x + viewInfo.view.width;
|
|
const viewBottom = viewInfo.view.y + viewInfo.view.height;
|
|
const contentWidth = viewInfo.windowContent.width;
|
|
const contentHeight = viewInfo.windowContent.height;
|
|
|
|
const isWithinBounds = viewInfo.view.x >= 0 &&
|
|
viewInfo.view.y >= 0 &&
|
|
viewRight <= contentWidth &&
|
|
viewBottom <= contentHeight &&
|
|
viewInfo.view.width > 0 &&
|
|
viewInfo.view.height > 0;
|
|
|
|
if (!isWithinBounds) {
|
|
throw new Error(
|
|
`Browser view is not positioned within visible window bounds.\n` +
|
|
`View: {x: ${viewInfo.view.x}, y: ${viewInfo.view.y}, width: ${viewInfo.view.width}, height: ${viewInfo.view.height}}, ` +
|
|
`Window content: {width: ${contentWidth}, height: ${contentHeight}}`,
|
|
);
|
|
}
|
|
});
|
|
|
|
When('I confirm the {string} window browser view is not positioned within visible window bounds', async function(this: ApplicationWorld, windowType: string) {
|
|
if (!this.app) {
|
|
throw new Error('Application is not available');
|
|
}
|
|
|
|
const targetWindow = await this.findWindowByType(windowType);
|
|
if (!targetWindow || targetWindow.isClosed()) {
|
|
throw new Error(`Window "${windowType}" is not available or has been closed`);
|
|
}
|
|
|
|
// Get the window dimensions to identify it - must match a defined WindowNames
|
|
const windowName = checkWindowName(windowType);
|
|
const windowDimensions = checkWindowDimension(windowName);
|
|
|
|
// Get browser view bounds for the specific window type
|
|
const viewInfo = await getBrowserViewInfo(this.app, windowDimensions);
|
|
|
|
if (!viewInfo.hasView || !viewInfo.view || !viewInfo.windowContent) {
|
|
// No view found is acceptable for this check - means it's definitely not visible
|
|
return;
|
|
}
|
|
|
|
// Check if browser view is OUTSIDE window content bounds
|
|
// View coordinates are relative to the window, so we check if they're outside the content area
|
|
const viewRight = viewInfo.view.x + viewInfo.view.width;
|
|
const viewBottom = viewInfo.view.y + viewInfo.view.height;
|
|
const contentWidth = viewInfo.windowContent.width;
|
|
const contentHeight = viewInfo.windowContent.height;
|
|
|
|
const isWithinBounds = viewInfo.view.x >= 0 &&
|
|
viewInfo.view.y >= 0 &&
|
|
viewRight <= contentWidth &&
|
|
viewBottom <= contentHeight &&
|
|
viewInfo.view.width > 0 &&
|
|
viewInfo.view.height > 0;
|
|
|
|
if (isWithinBounds) {
|
|
throw new Error(
|
|
`Browser view IS positioned within visible window bounds, but expected it to be outside.\n` +
|
|
`View: {x: ${viewInfo.view.x}, y: ${viewInfo.view.y}, width: ${viewInfo.view.width}, height: ${viewInfo.view.height}}, ` +
|
|
`Window content: {width: ${contentWidth}, height: ${contentHeight}}`,
|
|
);
|
|
}
|
|
});
|