Skip to content

dedicated interactivity/click-through toggle #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ All it takes is modest JavaScript/TypeScript knowledge and understanding of the
The application uses unidentifiable global keyboard shortcuts that won't be detected by browsers or other applications:

- Toggle Window Visibility: [Control or Cmd + B]
- Toggle Window Interactivity: [Control or Cmd + U]
- Move Window: [Control or Cmd + Arrow keys]
- Take Screenshot: [Control or Cmd + H]
- Delete Last Screenshot: [Control or Cmd + L]
Expand Down Expand Up @@ -145,6 +146,7 @@ chmod +x stealth-run.sh
```

**IMPORTANT**: The application window will be invisible by default! Use Ctrl+B (or Cmd+B on Mac) to toggle visibility.
The application window will be non-interactive by default! Use Ctrl+U (or Cmd+U on Mac) to toggle interactivity.

### Building Distributable Packages

Expand Down Expand Up @@ -244,6 +246,7 @@ The packaged applications will be available in the `release` directory.
5. **Window Management**
- Move window using [Control or Cmd + Arrow keys]
- Toggle visibility with [Control or Cmd + B]
- Toggle interactivity with [Control or Cmd + U]
- Adjust opacity with [Control or Cmd + [] and [Control or Cmd + ]]
- Window remains invisible to specified screen sharing applications
- Start a new problem using [Control or Cmd + R]
Expand Down
37 changes: 36 additions & 1 deletion electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// Window management properties
mainWindow: null as BrowserWindow | null,
isWindowVisible: false,
isWindowClickThrough: true,
windowPosition: null as { x: number; y: number } | null,
windowSize: null as { width: number; height: number } | null,
screenWidth: 0,
Expand Down Expand Up @@ -81,6 +82,7 @@
setView: (view: "queue" | "solutions" | "debug") => void
isVisible: () => boolean
toggleMainWindow: () => void
toggleClickThrough: () =>void
moveWindowLeft: () => void
moveWindowRight: () => void
moveWindowUp: () => void
Expand All @@ -101,6 +103,7 @@
takeScreenshot: () => Promise<string>
getView: () => "queue" | "solutions" | "debug"
toggleMainWindow: () => void
toggleClickThrough: () => void
clearQueues: () => void
setView: (view: "queue" | "solutions" | "debug") => void
moveWindowLeft: () => void
Expand Down Expand Up @@ -138,6 +141,7 @@
setView,
isVisible: () => state.isWindowVisible,
toggleMainWindow,
toggleClickThrough,
moveWindowLeft: () =>
moveWindowHorizontal((x) =>
Math.max(-(state.windowSize?.width || 0) / 2, x - state.step)
Expand Down Expand Up @@ -239,6 +243,7 @@
}

state.mainWindow = new BrowserWindow(windowSettings)
state.mainWindow.setIgnoreMouseEvents(true, { forward: true });

// Add more detailed logging for window events
state.mainWindow.webContents.on("did-finish-load", () => {
Expand Down Expand Up @@ -269,7 +274,7 @@
const indexPath = path.join(__dirname, "../dist/index.html")
console.log("Falling back to:", indexPath)
if (fs.existsSync(indexPath)) {
state.mainWindow.loadFile(indexPath)

Check failure on line 277 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 277 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
} else {
console.error("Could not find index.html in dist folder")
}
Expand Down Expand Up @@ -390,11 +395,11 @@
// Window visibility functions
function hideMainWindow(): void {
if (!state.mainWindow?.isDestroyed()) {
const bounds = state.mainWindow.getBounds();

Check failure on line 398 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 398 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
state.windowPosition = { x: bounds.x, y: bounds.y };
state.windowSize = { width: bounds.width, height: bounds.height };
state.mainWindow.setIgnoreMouseEvents(true, { forward: true });

Check failure on line 401 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 401 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
state.mainWindow.setOpacity(0);

Check failure on line 402 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 402 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
state.isWindowVisible = false;
console.log('Window hidden, opacity set to 0');
}
Expand All @@ -403,18 +408,18 @@
function showMainWindow(): void {
if (!state.mainWindow?.isDestroyed()) {
if (state.windowPosition && state.windowSize) {
state.mainWindow.setBounds({

Check failure on line 411 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 411 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
...state.windowPosition,
...state.windowSize
});
}
state.mainWindow.setIgnoreMouseEvents(false);
//state.mainWindow.setIgnoreMouseEvents(false);
state.mainWindow.setAlwaysOnTop(true, "screen-saver", 1);

Check failure on line 417 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 417 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
state.mainWindow.setVisibleOnAllWorkspaces(true, {

Check failure on line 418 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 418 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
visibleOnFullScreen: true
});
state.mainWindow.setContentProtection(true);

Check failure on line 421 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 421 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
state.mainWindow.setOpacity(0); // Set opacity to 0 before showing

Check failure on line 422 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'state.mainWindow' is possibly 'null'.

Check failure on line 422 in electron/main.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'state.mainWindow' is possibly 'null'.
state.mainWindow.showInactive(); // Use showInactive instead of show+focus
state.mainWindow.setOpacity(1); // Then set opacity to 1 after showing
state.isWindowVisible = true;
Expand All @@ -431,6 +436,34 @@
}
}


function enableClickThrough(): void {
if (!state.mainWindow?.isDestroyed()) {
state.mainWindow.setIgnoreMouseEvents(true, { forward: true });
state.isWindowClickThrough=true;
console.log('Window is click-through');
}
}

function disableClickThrough(): void {
if (!state.mainWindow?.isDestroyed()) {
state.mainWindow.setIgnoreMouseEvents(false);
state.isWindowClickThrough=false;
console.log('Window is not click-through');
}
}

//dedicated toggle for interactivity with main-window
//so that the mouse interactions with the main-window can be turned off and pointer will stay as it is
function toggleClickThrough(): void {
console.log(`Toggling window. Current state: ${state.isWindowClickThrough ? 'click-through' : 'not click-through'}`);
if (state.isWindowClickThrough) {
disableClickThrough();
} else {
enableClickThrough();
}
}

// Window movement functions
function moveWindowHorizontal(updateFn: (x: number) => number): void {
if (!state.mainWindow) return
Expand Down Expand Up @@ -543,6 +576,7 @@
takeScreenshot,
getView,
toggleMainWindow,
toggleClickThrough,
clearQueues,
setView,
moveWindowLeft: () =>
Expand Down Expand Up @@ -692,6 +726,7 @@
hideMainWindow,
showMainWindow,
toggleMainWindow,
toggleClickThrough,
setWindowDimensions,
moveWindowHorizontal,
moveWindowVertical,
Expand Down
8 changes: 8 additions & 0 deletions electron/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ export class ShortcutsHelper {
mainWindow.webContents.setZoomLevel(currentZoom + 0.5)
}
})

globalShortcut.register("CommandOrControl+U", () => {
console.log("Command/Ctrl + U pressed. Click-through enabled.")
const mainWindow = this.deps.getMainWindow()
if (mainWindow) {
this.deps.toggleClickThrough()
}
})

// Delete last screenshot shortcut
globalShortcut.register("CommandOrControl+L", () => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Settings/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ export function SettingsDialog({ open: externalOpen, onOpenChange }: SettingsDia
<div className="grid grid-cols-2 gap-y-2 text-xs">
<div className="text-white/70">Toggle Visibility</div>
<div className="text-white/90 font-mono">Ctrl+B / Cmd+B</div>

<div className="text-white/70">Toggle Interactivity</div>
<div className="text-white/90 font-mono">Ctrl+U / Cmd+U</div>

<div className="text-white/70">Take Screenshot</div>
<div className="text-white/90 font-mono">Ctrl+H / Cmd+H</div>
Expand Down
Loading