Refactor window management and global shortcuts handling

This commit is contained in:
Илья Глазунов 2026-02-15 00:34:37 +03:00
parent 494e692738
commit 4cf48ee0af
7 changed files with 5415 additions and 4431 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,45 @@
const profilePrompts = { const responseModeFormats = {
interview: { brief: `**RESPONSE FORMAT REQUIREMENTS:**
intro: `You are an AI-powered interview assistant, designed to act as a discreet on-screen teleprompter. Your mission is to help the user excel in their job interview by providing concise, impactful, and ready-to-speak answers or key talking points. Analyze the ongoing interview dialogue and, crucially, the 'User-provided context' below.`,
formatRequirements: `**RESPONSE FORMAT REQUIREMENTS:**
- Keep responses SHORT and CONCISE (1-3 sentences max) - Keep responses SHORT and CONCISE (1-3 sentences max)
- Use **markdown formatting** for better readability - Use **markdown formatting** for better readability
- Use **bold** for key points and emphasis - Use **bold** for key points and emphasis
- Use bullet points (-) for lists when appropriate - Use bullet points (-) for lists when appropriate
- Focus on the most essential information only`, - Focus on the most essential information only
- EXCEPTION: If a coding/algorithm task is detected, ALWAYS provide the complete working code (see CODING TASKS below)`,
searchUsage: `**SEARCH TOOL USAGE:** detailed: `**RESPONSE FORMAT REQUIREMENTS:**
- Provide a THOROUGH and COMPREHENSIVE response with full explanations
- Use **markdown formatting** for better readability
- Use **bold** for key points and emphasis
- Use headers (##) to organize sections when appropriate
- Use bullet points (-) for lists when appropriate
- Include relevant context, edge cases, and reasoning
- For technical topics, explain the "why" behind each point
- No length restriction be as detailed as needed to fully answer the question`,
};
const codingAwareness = `**CODING TASKS — CRITICAL INSTRUCTION:**
When the interviewer/questioner asks to solve a coding problem, implement an algorithm, debug code, do a live coding exercise, open an IDE and write code, or any task that requires a code solution:
- You MUST provide the ACTUAL COMPLETE WORKING CODE SOLUTION
- NEVER respond with meta-advice like "now you should write code" or "prepare to implement" or "think about the approach"
- NEVER say "open your IDE" or "start coding" instead, GIVE THE CODE
- In brief mode: provide 2-3 bullet approach points, then the FULL working code with comments
- In detailed mode: explain approach, time/space complexity, edge cases, then the FULL working code with comments
- Include the programming language name in the code fence (e.g. \`\`\`python, \`\`\`javascript)
- If the language is not specified, default to Python
- The code must be complete, runnable, and correct`;
const profilePrompts = {
interview: {
intro: `You are an AI-powered interview assistant, designed to act as a discreet on-screen teleprompter. Your mission is to help the user excel in their job interview by providing concise, impactful, and ready-to-speak answers or key talking points. Analyze the ongoing interview dialogue and, crucially, the 'User-provided context' below.`,
searchUsage: `**SEARCH TOOL USAGE:**
- If the interviewer mentions **recent events, news, or current trends** (anything from the last 6 months), **ALWAYS use Google search** to get up-to-date information - If the interviewer mentions **recent events, news, or current trends** (anything from the last 6 months), **ALWAYS use Google search** to get up-to-date information
- If they ask about **company-specific information, recent acquisitions, funding, or leadership changes**, use Google search first - If they ask about **company-specific information, recent acquisitions, funding, or leadership changes**, use Google search first
- If they mention **new technologies, frameworks, or industry developments**, search for the latest information - If they mention **new technologies, frameworks, or industry developments**, search for the latest information
- After searching, provide a **concise, informed response** based on the real-time data`, - After searching, provide a **concise, informed response** based on the real-time data`,
content: `Focus on delivering the most essential information the user needs. Your suggestions should be direct and immediately usable. content: `Focus on delivering the most essential information the user needs. Your suggestions should be direct and immediately usable.
To help the user 'crack' the interview in their specific field: To help the user 'crack' the interview in their specific field:
1. Heavily rely on the 'User-provided context' (e.g., details about their industry, the job description, their resume, key skills, and achievements). 1. Heavily rely on the 'User-provided context' (e.g., details about their industry, the job description, their resume, key skills, and achievements).
@ -32,27 +56,20 @@ You: "I've been working with React for 4 years, building everything from simple
Interviewer: "Why do you want to work here?" Interviewer: "Why do you want to work here?"
You: "I'm excited about this role because your company is solving real problems in the fintech space, which aligns with my interest in building products that impact people's daily lives. I've researched your tech stack and I'm particularly interested in contributing to your microservices architecture. Your focus on innovation and the opportunity to work with a talented team really appeals to me."`, You: "I'm excited about this role because your company is solving real problems in the fintech space, which aligns with my interest in building products that impact people's daily lives. I've researched your tech stack and I'm particularly interested in contributing to your microservices architecture. Your focus on innovation and the opportunity to work with a talented team really appeals to me."`,
outputInstructions: `**OUTPUT INSTRUCTIONS:** outputInstructions: `**OUTPUT INSTRUCTIONS:**
Provide only the exact words to say in **markdown format**. No coaching, no "you should" statements, no explanations - just the direct response the candidate can speak immediately. Keep it **short and impactful**.`, Provide only the exact words to say in **markdown format**. No coaching, no "you should" statements, no explanations - just the direct response the candidate can speak immediately. Keep it **short and impactful**.`,
}, },
sales: { sales: {
intro: `You are a sales call assistant. Your job is to provide the exact words the salesperson should say to prospects during sales calls. Give direct, ready-to-speak responses that are persuasive and professional.`, intro: `You are a sales call assistant. Your job is to provide the exact words the salesperson should say to prospects during sales calls. Give direct, ready-to-speak responses that are persuasive and professional.`,
formatRequirements: `**RESPONSE FORMAT REQUIREMENTS:** searchUsage: `**SEARCH TOOL USAGE:**
- Keep responses SHORT and CONCISE (1-3 sentences max)
- Use **markdown formatting** for better readability
- Use **bold** for key points and emphasis
- Use bullet points (-) for lists when appropriate
- Focus on the most essential information only`,
searchUsage: `**SEARCH TOOL USAGE:**
- If the prospect mentions **recent industry trends, market changes, or current events**, **ALWAYS use Google search** to get up-to-date information - If the prospect mentions **recent industry trends, market changes, or current events**, **ALWAYS use Google search** to get up-to-date information
- If they reference **competitor information, recent funding news, or market data**, search for the latest information first - If they reference **competitor information, recent funding news, or market data**, search for the latest information first
- If they ask about **new regulations, industry reports, or recent developments**, use search to provide accurate data - If they ask about **new regulations, industry reports, or recent developments**, use search to provide accurate data
- After searching, provide a **concise, informed response** that demonstrates current market knowledge`, - After searching, provide a **concise, informed response** that demonstrates current market knowledge`,
content: `Examples: content: `Examples:
Prospect: "Tell me about your product" Prospect: "Tell me about your product"
You: "Our platform helps companies like yours reduce operational costs by 30% while improving efficiency. We've worked with over 500 businesses in your industry, and they typically see ROI within the first 90 days. What specific operational challenges are you facing right now?" You: "Our platform helps companies like yours reduce operational costs by 30% while improving efficiency. We've worked with over 500 businesses in your industry, and they typically see ROI within the first 90 days. What specific operational challenges are you facing right now?"
@ -63,27 +80,20 @@ You: "Three key differentiators set us apart: First, our implementation takes ju
Prospect: "I need to think about it" Prospect: "I need to think about it"
You: "I completely understand this is an important decision. What specific concerns can I address for you today? Is it about implementation timeline, cost, or integration with your existing systems? I'd rather help you make an informed decision now than leave you with unanswered questions."`, You: "I completely understand this is an important decision. What specific concerns can I address for you today? Is it about implementation timeline, cost, or integration with your existing systems? I'd rather help you make an informed decision now than leave you with unanswered questions."`,
outputInstructions: `**OUTPUT INSTRUCTIONS:** outputInstructions: `**OUTPUT INSTRUCTIONS:**
Provide only the exact words to say in **markdown format**. Be persuasive but not pushy. Focus on value and addressing objections directly. Keep responses **short and impactful**.`, Provide only the exact words to say in **markdown format**. Be persuasive but not pushy. Focus on value and addressing objections directly. Keep responses **short and impactful**.`,
}, },
meeting: { meeting: {
intro: `You are a meeting assistant. Your job is to provide the exact words to say during professional meetings, presentations, and discussions. Give direct, ready-to-speak responses that are clear and professional.`, intro: `You are a meeting assistant. Your job is to provide the exact words to say during professional meetings, presentations, and discussions. Give direct, ready-to-speak responses that are clear and professional.`,
formatRequirements: `**RESPONSE FORMAT REQUIREMENTS:** searchUsage: `**SEARCH TOOL USAGE:**
- Keep responses SHORT and CONCISE (1-3 sentences max)
- Use **markdown formatting** for better readability
- Use **bold** for key points and emphasis
- Use bullet points (-) for lists when appropriate
- Focus on the most essential information only`,
searchUsage: `**SEARCH TOOL USAGE:**
- If participants mention **recent industry news, regulatory changes, or market updates**, **ALWAYS use Google search** for current information - If participants mention **recent industry news, regulatory changes, or market updates**, **ALWAYS use Google search** for current information
- If they reference **competitor activities, recent reports, or current statistics**, search for the latest data first - If they reference **competitor activities, recent reports, or current statistics**, search for the latest data first
- If they discuss **new technologies, tools, or industry developments**, use search to provide accurate insights - If they discuss **new technologies, tools, or industry developments**, use search to provide accurate insights
- After searching, provide a **concise, informed response** that adds value to the discussion`, - After searching, provide a **concise, informed response** that adds value to the discussion`,
content: `Examples: content: `Examples:
Participant: "What's the status on the project?" Participant: "What's the status on the project?"
You: "We're currently on track to meet our deadline. We've completed 75% of the deliverables, with the remaining items scheduled for completion by Friday. The main challenge we're facing is the integration testing, but we have a plan in place to address it." You: "We're currently on track to meet our deadline. We've completed 75% of the deliverables, with the remaining items scheduled for completion by Friday. The main challenge we're facing is the integration testing, but we have a plan in place to address it."
@ -94,27 +104,20 @@ You: "Absolutely. We're currently at 80% of our allocated budget with 20% of the
Participant: "What are the next steps?" Participant: "What are the next steps?"
You: "Moving forward, I'll need approval on the revised timeline by end of day today. Sarah will handle the client communication, and Mike will coordinate with the technical team. We'll have our next checkpoint on Thursday to ensure everything stays on track."`, You: "Moving forward, I'll need approval on the revised timeline by end of day today. Sarah will handle the client communication, and Mike will coordinate with the technical team. We'll have our next checkpoint on Thursday to ensure everything stays on track."`,
outputInstructions: `**OUTPUT INSTRUCTIONS:** outputInstructions: `**OUTPUT INSTRUCTIONS:**
Provide only the exact words to say in **markdown format**. Be clear, concise, and action-oriented in your responses. Keep it **short and impactful**.`, Provide only the exact words to say in **markdown format**. Be clear, concise, and action-oriented in your responses. Keep it **short and impactful**.`,
}, },
presentation: { presentation: {
intro: `You are a presentation coach. Your job is to provide the exact words the presenter should say during presentations, pitches, and public speaking events. Give direct, ready-to-speak responses that are engaging and confident.`, intro: `You are a presentation coach. Your job is to provide the exact words the presenter should say during presentations, pitches, and public speaking events. Give direct, ready-to-speak responses that are engaging and confident.`,
formatRequirements: `**RESPONSE FORMAT REQUIREMENTS:** searchUsage: `**SEARCH TOOL USAGE:**
- Keep responses SHORT and CONCISE (1-3 sentences max)
- Use **markdown formatting** for better readability
- Use **bold** for key points and emphasis
- Use bullet points (-) for lists when appropriate
- Focus on the most essential information only`,
searchUsage: `**SEARCH TOOL USAGE:**
- If the audience asks about **recent market trends, current statistics, or latest industry data**, **ALWAYS use Google search** for up-to-date information - If the audience asks about **recent market trends, current statistics, or latest industry data**, **ALWAYS use Google search** for up-to-date information
- If they reference **recent events, new competitors, or current market conditions**, search for the latest information first - If they reference **recent events, new competitors, or current market conditions**, search for the latest information first
- If they inquire about **recent studies, reports, or breaking news** in your field, use search to provide accurate data - If they inquire about **recent studies, reports, or breaking news** in your field, use search to provide accurate data
- After searching, provide a **concise, credible response** with current facts and figures`, - After searching, provide a **concise, credible response** with current facts and figures`,
content: `Examples: content: `Examples:
Audience: "Can you explain that slide again?" Audience: "Can you explain that slide again?"
You: "Of course. This slide shows our three-year growth trajectory. The blue line represents revenue, which has grown 150% year over year. The orange bars show our customer acquisition, doubling each year. The key insight here is that our customer lifetime value has increased by 40% while acquisition costs have remained flat." You: "Of course. This slide shows our three-year growth trajectory. The blue line represents revenue, which has grown 150% year over year. The orange bars show our customer acquisition, doubling each year. The key insight here is that our customer lifetime value has increased by 40% while acquisition costs have remained flat."
@ -125,27 +128,20 @@ You: "Great question. Our competitive advantage comes down to three core strengt
Audience: "How do you plan to scale?" Audience: "How do you plan to scale?"
You: "Our scaling strategy focuses on three pillars. First, we're expanding our engineering team by 200% to accelerate product development. Second, we're entering three new markets next quarter. Third, we're building strategic partnerships that will give us access to 10 million additional potential customers."`, You: "Our scaling strategy focuses on three pillars. First, we're expanding our engineering team by 200% to accelerate product development. Second, we're entering three new markets next quarter. Third, we're building strategic partnerships that will give us access to 10 million additional potential customers."`,
outputInstructions: `**OUTPUT INSTRUCTIONS:** outputInstructions: `**OUTPUT INSTRUCTIONS:**
Provide only the exact words to say in **markdown format**. Be confident, engaging, and back up claims with specific numbers or facts when possible. Keep responses **short and impactful**.`, Provide only the exact words to say in **markdown format**. Be confident, engaging, and back up claims with specific numbers or facts when possible. Keep responses **short and impactful**.`,
}, },
negotiation: { negotiation: {
intro: `You are a negotiation assistant. Your job is to provide the exact words to say during business negotiations, contract discussions, and deal-making conversations. Give direct, ready-to-speak responses that are strategic and professional.`, intro: `You are a negotiation assistant. Your job is to provide the exact words to say during business negotiations, contract discussions, and deal-making conversations. Give direct, ready-to-speak responses that are strategic and professional.`,
formatRequirements: `**RESPONSE FORMAT REQUIREMENTS:** searchUsage: `**SEARCH TOOL USAGE:**
- Keep responses SHORT and CONCISE (1-3 sentences max)
- Use **markdown formatting** for better readability
- Use **bold** for key points and emphasis
- Use bullet points (-) for lists when appropriate
- Focus on the most essential information only`,
searchUsage: `**SEARCH TOOL USAGE:**
- If they mention **recent market pricing, current industry standards, or competitor offers**, **ALWAYS use Google search** for current benchmarks - If they mention **recent market pricing, current industry standards, or competitor offers**, **ALWAYS use Google search** for current benchmarks
- If they reference **recent legal changes, new regulations, or market conditions**, search for the latest information first - If they reference **recent legal changes, new regulations, or market conditions**, search for the latest information first
- If they discuss **recent company news, financial performance, or industry developments**, use search to provide informed responses - If they discuss **recent company news, financial performance, or industry developments**, use search to provide informed responses
- After searching, provide a **strategic, well-informed response** that leverages current market intelligence`, - After searching, provide a **strategic, well-informed response** that leverages current market intelligence`,
content: `Examples: content: `Examples:
Other party: "That price is too high" Other party: "That price is too high"
You: "I understand your concern about the investment. Let's look at the value you're getting: this solution will save you $200K annually in operational costs, which means you'll break even in just 6 months. Would it help if we structured the payment terms differently, perhaps spreading it over 12 months instead of upfront?" You: "I understand your concern about the investment. Let's look at the value you're getting: this solution will save you $200K annually in operational costs, which means you'll break even in just 6 months. Would it help if we structured the payment terms differently, perhaps spreading it over 12 months instead of upfront?"
@ -156,27 +152,20 @@ You: "I appreciate your directness. We want this to work for both parties. Our c
Other party: "We're considering other options" Other party: "We're considering other options"
You: "That's smart business practice. While you're evaluating alternatives, I want to ensure you have all the information. Our solution offers three unique benefits that others don't: 24/7 dedicated support, guaranteed 48-hour implementation, and a money-back guarantee if you don't see results in 90 days. How important are these factors in your decision?"`, You: "That's smart business practice. While you're evaluating alternatives, I want to ensure you have all the information. Our solution offers three unique benefits that others don't: 24/7 dedicated support, guaranteed 48-hour implementation, and a money-back guarantee if you don't see results in 90 days. How important are these factors in your decision?"`,
outputInstructions: `**OUTPUT INSTRUCTIONS:** outputInstructions: `**OUTPUT INSTRUCTIONS:**
Provide only the exact words to say in **markdown format**. Focus on finding win-win solutions and addressing underlying concerns. Keep responses **short and impactful**.`, Provide only the exact words to say in **markdown format**. Focus on finding win-win solutions and addressing underlying concerns. Keep responses **short and impactful**.`,
}, },
exam: { exam: {
intro: `You are an exam assistant designed to help students pass tests efficiently. Your role is to provide direct, accurate answers to exam questions with minimal explanation - just enough to confirm the answer is correct.`, intro: `You are an exam assistant designed to help students pass tests efficiently. Your role is to provide direct, accurate answers to exam questions with minimal explanation - just enough to confirm the answer is correct.`,
formatRequirements: `**RESPONSE FORMAT REQUIREMENTS:** searchUsage: `**SEARCH TOOL USAGE:**
- Keep responses SHORT and CONCISE (1-2 sentences max)
- Use **markdown formatting** for better readability
- Use **bold** for the answer choice/result
- Focus on the most essential information only
- Provide only brief justification for correctness`,
searchUsage: `**SEARCH TOOL USAGE:**
- If the question involves **recent information, current events, or updated facts**, **ALWAYS use Google search** for the latest data - If the question involves **recent information, current events, or updated facts**, **ALWAYS use Google search** for the latest data
- If they reference **specific dates, statistics, or factual information** that might be outdated, search for current information - If they reference **specific dates, statistics, or factual information** that might be outdated, search for current information
- If they ask about **recent research, new theories, or updated methodologies**, search for the latest information - If they ask about **recent research, new theories, or updated methodologies**, search for the latest information
- After searching, provide **direct, accurate answers** with minimal explanation`, - After searching, provide **direct, accurate answers** with minimal explanation`,
content: `Focus on providing efficient exam assistance that helps students pass tests quickly. content: `Focus on providing efficient exam assistance that helps students pass tests quickly.
**Key Principles:** **Key Principles:**
1. **Answer the question directly** - no unnecessary explanations 1. **Answer the question directly** - no unnecessary explanations
@ -196,30 +185,62 @@ You: "**Question**: Which of the following is a primary color? A) Green B) Red C
Question: "Solve for x: 2x + 5 = 13" Question: "Solve for x: 2x + 5 = 13"
You: "**Question**: Solve for x: 2x + 5 = 13 **Answer**: x = 4 **Why**: Subtract 5 from both sides: 2x = 8, then divide by 2: x = 4."`, You: "**Question**: Solve for x: 2x + 5 = 13 **Answer**: x = 4 **Why**: Subtract 5 from both sides: 2x = 8, then divide by 2: x = 4."`,
outputInstructions: `**OUTPUT INSTRUCTIONS:** outputInstructions: `**OUTPUT INSTRUCTIONS:**
Provide direct exam answers in **markdown format**. Include the question text, the correct answer choice, and a brief justification. Focus on efficiency and accuracy. Keep responses **short and to the point**.`, Provide direct exam answers in **markdown format**. Include the question text, the correct answer choice, and a brief justification. Focus on efficiency and accuracy. Keep responses **short and to the point**.`,
}, },
}; };
function buildSystemPrompt(promptParts, customPrompt = '', googleSearchEnabled = true) { function buildSystemPrompt(
const sections = [promptParts.intro, '\n\n', promptParts.formatRequirements]; promptParts,
customPrompt = "",
googleSearchEnabled = true,
responseMode = "brief",
) {
const formatReqs =
responseModeFormats[responseMode] || responseModeFormats.brief;
const sections = [
promptParts.intro,
"\n\n",
formatReqs,
"\n\n",
codingAwareness,
];
// Only add search usage section if Google Search is enabled // Only add search usage section if Google Search is enabled
if (googleSearchEnabled) { if (googleSearchEnabled) {
sections.push('\n\n', promptParts.searchUsage); sections.push("\n\n", promptParts.searchUsage);
} }
sections.push('\n\n', promptParts.content, '\n\nUser-provided context\n-----\n', customPrompt, '\n-----\n\n', promptParts.outputInstructions); sections.push(
"\n\n",
promptParts.content,
"\n\nUser-provided context\n-----\n",
customPrompt,
"\n-----\n\n",
promptParts.outputInstructions,
);
return sections.join(''); return sections.join("");
} }
function getSystemPrompt(profile, customPrompt = '', googleSearchEnabled = true) { function getSystemPrompt(
const promptParts = profilePrompts[profile] || profilePrompts.interview; profile,
return buildSystemPrompt(promptParts, customPrompt, googleSearchEnabled); customPrompt = "",
googleSearchEnabled = true,
responseMode = "brief",
) {
const promptParts = profilePrompts[profile] || profilePrompts.interview;
return buildSystemPrompt(
promptParts,
customPrompt,
googleSearchEnabled,
responseMode,
);
} }
module.exports = { module.exports = {
profilePrompts, profilePrompts,
getSystemPrompt, responseModeFormats,
codingAwareness,
getSystemPrompt,
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,368 +1,429 @@
const { BrowserWindow, globalShortcut, ipcMain, screen } = require('electron'); const { BrowserWindow, globalShortcut, ipcMain, screen } = require("electron");
const path = require('node:path'); const path = require("node:path");
const storage = require('../storage'); const storage = require("../storage");
let mouseEventsIgnored = false; let mouseEventsIgnored = false;
function createWindow(sendToRenderer, geminiSessionRef) { function createWindow(sendToRenderer, geminiSessionRef) {
// Get layout preference (default to 'normal') // Get layout preference (default to 'normal')
let windowWidth = 1100; let windowWidth = 1100;
let windowHeight = 800; let windowHeight = 800;
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: windowWidth, width: windowWidth,
height: windowHeight, height: windowHeight,
frame: false, frame: false,
transparent: true, transparent: true,
hasShadow: false, hasShadow: false,
alwaysOnTop: true, alwaysOnTop: true,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false, // TODO: change to true contextIsolation: false, // TODO: change to true
backgroundThrottling: false, backgroundThrottling: false,
enableBlinkFeatures: 'GetDisplayMedia', enableBlinkFeatures: "GetDisplayMedia",
webSecurity: true, webSecurity: true,
allowRunningInsecureContent: false, allowRunningInsecureContent: false,
}, },
backgroundColor: '#00000000', backgroundColor: "#00000000",
}); });
const { session, desktopCapturer } = require('electron'); const { session, desktopCapturer } = require("electron");
session.defaultSession.setDisplayMediaRequestHandler( session.defaultSession.setDisplayMediaRequestHandler(
(request, callback) => { (request, callback) => {
desktopCapturer.getSources({ types: ['screen'] }).then(sources => { desktopCapturer.getSources({ types: ["screen"] }).then((sources) => {
callback({ video: sources[0], audio: 'loopback' }); callback({ video: sources[0], audio: "loopback" });
}); });
}, },
{ useSystemPicker: true } { useSystemPicker: true },
); );
mainWindow.setResizable(false); mainWindow.setResizable(false);
mainWindow.setContentProtection(true); mainWindow.setContentProtection(true);
mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }); mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
// Hide from Windows taskbar // Hide from Windows taskbar
if (process.platform === 'win32') { if (process.platform === "win32") {
try { try {
mainWindow.setSkipTaskbar(true); mainWindow.setSkipTaskbar(true);
} catch (error) { } catch (error) {
console.warn('Could not hide from taskbar:', error.message); console.warn("Could not hide from taskbar:", error.message);
}
} }
}
// Hide from Mission Control on macOS // Hide from Mission Control on macOS
if (process.platform === 'darwin') { if (process.platform === "darwin") {
try { try {
mainWindow.setHiddenInMissionControl(true); mainWindow.setHiddenInMissionControl(true);
} catch (error) { } catch (error) {
console.warn('Could not hide from Mission Control:', error.message); console.warn("Could not hide from Mission Control:", error.message);
}
} }
}
// Center window at the top of the screen // Center window at the top of the screen
const primaryDisplay = screen.getPrimaryDisplay(); const primaryDisplay = screen.getPrimaryDisplay();
const { width: screenWidth } = primaryDisplay.workAreaSize; const { width: screenWidth } = primaryDisplay.workAreaSize;
const x = Math.floor((screenWidth - windowWidth) / 2); const x = Math.floor((screenWidth - windowWidth) / 2);
const y = 0; const y = 0;
mainWindow.setPosition(x, y); mainWindow.setPosition(x, y);
if (process.platform === 'win32') { if (process.platform === "win32") {
mainWindow.setAlwaysOnTop(true, 'screen-saver', 1); mainWindow.setAlwaysOnTop(true, "screen-saver", 1);
} }
mainWindow.loadFile(path.join(__dirname, '../index.html')); mainWindow.loadFile(path.join(__dirname, "../index.html"));
// After window is created, initialize keybinds // After window is created, initialize keybinds
mainWindow.webContents.once('dom-ready', () => { mainWindow.webContents.once("dom-ready", () => {
setTimeout(() => { setTimeout(() => {
const defaultKeybinds = getDefaultKeybinds(); const defaultKeybinds = getDefaultKeybinds();
let keybinds = defaultKeybinds; let keybinds = defaultKeybinds;
// Load keybinds from storage // Load keybinds from storage
const savedKeybinds = storage.getKeybinds(); const savedKeybinds = storage.getKeybinds();
if (savedKeybinds) { if (savedKeybinds) {
keybinds = { ...defaultKeybinds, ...savedKeybinds }; keybinds = { ...defaultKeybinds, ...savedKeybinds };
} }
updateGlobalShortcuts(keybinds, mainWindow, sendToRenderer, geminiSessionRef); updateGlobalShortcuts(
}, 150); keybinds,
}); mainWindow,
sendToRenderer,
geminiSessionRef,
);
}, 150);
});
setupWindowIpcHandlers(mainWindow, sendToRenderer, geminiSessionRef); setupWindowIpcHandlers(mainWindow, sendToRenderer, geminiSessionRef);
return mainWindow; return mainWindow;
} }
function getDefaultKeybinds() { function getDefaultKeybinds() {
const isMac = process.platform === 'darwin'; const isMac = process.platform === "darwin";
return { return {
moveUp: isMac ? 'Alt+Up' : 'Ctrl+Up', moveUp: isMac ? "Alt+Up" : "Ctrl+Up",
moveDown: isMac ? 'Alt+Down' : 'Ctrl+Down', moveDown: isMac ? "Alt+Down" : "Ctrl+Down",
moveLeft: isMac ? 'Alt+Left' : 'Ctrl+Left', moveLeft: isMac ? "Alt+Left" : "Ctrl+Left",
moveRight: isMac ? 'Alt+Right' : 'Ctrl+Right', moveRight: isMac ? "Alt+Right" : "Ctrl+Right",
toggleVisibility: isMac ? 'Cmd+\\' : 'Ctrl+\\', toggleVisibility: isMac ? "Cmd+\\" : "Ctrl+\\",
toggleClickThrough: isMac ? 'Cmd+M' : 'Ctrl+M', toggleClickThrough: isMac ? "Cmd+M" : "Ctrl+M",
nextStep: isMac ? 'Cmd+Enter' : 'Ctrl+Enter', nextStep: isMac ? "Cmd+Enter" : "Ctrl+Enter",
previousResponse: isMac ? 'Cmd+[' : 'Ctrl+[', previousResponse: isMac ? "Cmd+[" : "Ctrl+[",
nextResponse: isMac ? 'Cmd+]' : 'Ctrl+]', nextResponse: isMac ? "Cmd+]" : "Ctrl+]",
scrollUp: isMac ? 'Cmd+Shift+Up' : 'Ctrl+Shift+Up', scrollUp: isMac ? "Cmd+Shift+Up" : "Ctrl+Shift+Up",
scrollDown: isMac ? 'Cmd+Shift+Down' : 'Ctrl+Shift+Down', scrollDown: isMac ? "Cmd+Shift+Down" : "Ctrl+Shift+Down",
emergencyErase: isMac ? 'Cmd+Shift+E' : 'Ctrl+Shift+E', expandResponse: isMac ? "Cmd+E" : "Ctrl+E",
}; emergencyErase: isMac ? "Cmd+Shift+E" : "Ctrl+Shift+E",
};
} }
function updateGlobalShortcuts(keybinds, mainWindow, sendToRenderer, geminiSessionRef) { function updateGlobalShortcuts(
console.log('Updating global shortcuts with:', keybinds); keybinds,
mainWindow,
sendToRenderer,
geminiSessionRef,
) {
console.log("Updating global shortcuts with:", keybinds);
// Unregister all existing shortcuts // Unregister all existing shortcuts
globalShortcut.unregisterAll(); globalShortcut.unregisterAll();
const primaryDisplay = screen.getPrimaryDisplay(); const primaryDisplay = screen.getPrimaryDisplay();
const { width, height } = primaryDisplay.workAreaSize; const { width, height } = primaryDisplay.workAreaSize;
const moveIncrement = Math.floor(Math.min(width, height) * 0.1); const moveIncrement = Math.floor(Math.min(width, height) * 0.1);
// Register window movement shortcuts // Register window movement shortcuts
const movementActions = { const movementActions = {
moveUp: () => { moveUp: () => {
if (!mainWindow.isVisible()) return; if (!mainWindow.isVisible()) return;
const [currentX, currentY] = mainWindow.getPosition(); const [currentX, currentY] = mainWindow.getPosition();
mainWindow.setPosition(currentX, currentY - moveIncrement); mainWindow.setPosition(currentX, currentY - moveIncrement);
}, },
moveDown: () => { moveDown: () => {
if (!mainWindow.isVisible()) return; if (!mainWindow.isVisible()) return;
const [currentX, currentY] = mainWindow.getPosition(); const [currentX, currentY] = mainWindow.getPosition();
mainWindow.setPosition(currentX, currentY + moveIncrement); mainWindow.setPosition(currentX, currentY + moveIncrement);
}, },
moveLeft: () => { moveLeft: () => {
if (!mainWindow.isVisible()) return; if (!mainWindow.isVisible()) return;
const [currentX, currentY] = mainWindow.getPosition(); const [currentX, currentY] = mainWindow.getPosition();
mainWindow.setPosition(currentX - moveIncrement, currentY); mainWindow.setPosition(currentX - moveIncrement, currentY);
}, },
moveRight: () => { moveRight: () => {
if (!mainWindow.isVisible()) return; if (!mainWindow.isVisible()) return;
const [currentX, currentY] = mainWindow.getPosition(); const [currentX, currentY] = mainWindow.getPosition();
mainWindow.setPosition(currentX + moveIncrement, currentY); mainWindow.setPosition(currentX + moveIncrement, currentY);
}, },
}; };
// Register each movement shortcut // Register each movement shortcut
Object.keys(movementActions).forEach(action => { Object.keys(movementActions).forEach((action) => {
const keybind = keybinds[action]; const keybind = keybinds[action];
if (keybind) { if (keybind) {
try { try {
globalShortcut.register(keybind, movementActions[action]); globalShortcut.register(keybind, movementActions[action]);
console.log(`Registered ${action}: ${keybind}`); console.log(`Registered ${action}: ${keybind}`);
} catch (error) { } catch (error) {
console.error(`Failed to register ${action} (${keybind}):`, error); console.error(`Failed to register ${action} (${keybind}):`, error);
} }
}
});
// Register toggle visibility shortcut
if (keybinds.toggleVisibility) {
try {
globalShortcut.register(keybinds.toggleVisibility, () => {
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.showInactive();
}
});
console.log(`Registered toggleVisibility: ${keybinds.toggleVisibility}`);
} catch (error) {
console.error(`Failed to register toggleVisibility (${keybinds.toggleVisibility}):`, error);
}
} }
});
// Register toggle click-through shortcut // Register toggle visibility shortcut
if (keybinds.toggleClickThrough) { if (keybinds.toggleVisibility) {
try { try {
globalShortcut.register(keybinds.toggleClickThrough, () => { globalShortcut.register(keybinds.toggleVisibility, () => {
mouseEventsIgnored = !mouseEventsIgnored; if (mainWindow.isVisible()) {
if (mouseEventsIgnored) { mainWindow.hide();
mainWindow.setIgnoreMouseEvents(true, { forward: true }); } else {
console.log('Mouse events ignored'); mainWindow.showInactive();
} else {
mainWindow.setIgnoreMouseEvents(false);
console.log('Mouse events enabled');
}
mainWindow.webContents.send('click-through-toggled', mouseEventsIgnored);
});
console.log(`Registered toggleClickThrough: ${keybinds.toggleClickThrough}`);
} catch (error) {
console.error(`Failed to register toggleClickThrough (${keybinds.toggleClickThrough}):`, error);
} }
});
console.log(`Registered toggleVisibility: ${keybinds.toggleVisibility}`);
} catch (error) {
console.error(
`Failed to register toggleVisibility (${keybinds.toggleVisibility}):`,
error,
);
} }
}
// Register next step shortcut (either starts session or takes screenshot based on view) // Register toggle click-through shortcut
if (keybinds.nextStep) { if (keybinds.toggleClickThrough) {
try {
globalShortcut.register(keybinds.toggleClickThrough, () => {
mouseEventsIgnored = !mouseEventsIgnored;
if (mouseEventsIgnored) {
mainWindow.setIgnoreMouseEvents(true, { forward: true });
console.log("Mouse events ignored");
} else {
mainWindow.setIgnoreMouseEvents(false);
console.log("Mouse events enabled");
}
mainWindow.webContents.send(
"click-through-toggled",
mouseEventsIgnored,
);
});
console.log(
`Registered toggleClickThrough: ${keybinds.toggleClickThrough}`,
);
} catch (error) {
console.error(
`Failed to register toggleClickThrough (${keybinds.toggleClickThrough}):`,
error,
);
}
}
// Register next step shortcut (either starts session or takes screenshot based on view)
if (keybinds.nextStep) {
try {
globalShortcut.register(keybinds.nextStep, async () => {
console.log("Next step shortcut triggered");
try { try {
globalShortcut.register(keybinds.nextStep, async () => { // Determine the shortcut key format
console.log('Next step shortcut triggered'); const isMac = process.platform === "darwin";
try { const shortcutKey = isMac ? "cmd+enter" : "ctrl+enter";
// Determine the shortcut key format
const isMac = process.platform === 'darwin';
const shortcutKey = isMac ? 'cmd+enter' : 'ctrl+enter';
// Use the new handleShortcut function // Use the new handleShortcut function
mainWindow.webContents.executeJavaScript(` mainWindow.webContents.executeJavaScript(`
cheatingDaddy.handleShortcut('${shortcutKey}'); cheatingDaddy.handleShortcut('${shortcutKey}');
`); `);
} catch (error) {
console.error('Error handling next step shortcut:', error);
}
});
console.log(`Registered nextStep: ${keybinds.nextStep}`);
} catch (error) { } catch (error) {
console.error(`Failed to register nextStep (${keybinds.nextStep}):`, error); console.error("Error handling next step shortcut:", error);
} }
});
console.log(`Registered nextStep: ${keybinds.nextStep}`);
} catch (error) {
console.error(
`Failed to register nextStep (${keybinds.nextStep}):`,
error,
);
} }
}
// Register previous response shortcut // Register previous response shortcut
if (keybinds.previousResponse) { if (keybinds.previousResponse) {
try { try {
globalShortcut.register(keybinds.previousResponse, () => { globalShortcut.register(keybinds.previousResponse, () => {
console.log('Previous response shortcut triggered'); console.log("Previous response shortcut triggered");
sendToRenderer('navigate-previous-response'); sendToRenderer("navigate-previous-response");
}); });
console.log(`Registered previousResponse: ${keybinds.previousResponse}`); console.log(`Registered previousResponse: ${keybinds.previousResponse}`);
} catch (error) { } catch (error) {
console.error(`Failed to register previousResponse (${keybinds.previousResponse}):`, error); console.error(
} `Failed to register previousResponse (${keybinds.previousResponse}):`,
} error,
);
// Register next response shortcut }
if (keybinds.nextResponse) { }
try {
globalShortcut.register(keybinds.nextResponse, () => { // Register next response shortcut
console.log('Next response shortcut triggered'); if (keybinds.nextResponse) {
sendToRenderer('navigate-next-response'); try {
}); globalShortcut.register(keybinds.nextResponse, () => {
console.log(`Registered nextResponse: ${keybinds.nextResponse}`); console.log("Next response shortcut triggered");
} catch (error) { sendToRenderer("navigate-next-response");
console.error(`Failed to register nextResponse (${keybinds.nextResponse}):`, error); });
} console.log(`Registered nextResponse: ${keybinds.nextResponse}`);
} } catch (error) {
console.error(
// Register scroll up shortcut `Failed to register nextResponse (${keybinds.nextResponse}):`,
if (keybinds.scrollUp) { error,
try { );
globalShortcut.register(keybinds.scrollUp, () => { }
console.log('Scroll up shortcut triggered'); }
sendToRenderer('scroll-response-up');
}); // Register scroll up shortcut
console.log(`Registered scrollUp: ${keybinds.scrollUp}`); if (keybinds.scrollUp) {
} catch (error) { try {
console.error(`Failed to register scrollUp (${keybinds.scrollUp}):`, error); globalShortcut.register(keybinds.scrollUp, () => {
} console.log("Scroll up shortcut triggered");
} sendToRenderer("scroll-response-up");
});
// Register scroll down shortcut console.log(`Registered scrollUp: ${keybinds.scrollUp}`);
if (keybinds.scrollDown) { } catch (error) {
try { console.error(
globalShortcut.register(keybinds.scrollDown, () => { `Failed to register scrollUp (${keybinds.scrollUp}):`,
console.log('Scroll down shortcut triggered'); error,
sendToRenderer('scroll-response-down'); );
}); }
console.log(`Registered scrollDown: ${keybinds.scrollDown}`); }
} catch (error) {
console.error(`Failed to register scrollDown (${keybinds.scrollDown}):`, error); // Register scroll down shortcut
} if (keybinds.scrollDown) {
} try {
globalShortcut.register(keybinds.scrollDown, () => {
// Register emergency erase shortcut console.log("Scroll down shortcut triggered");
if (keybinds.emergencyErase) { sendToRenderer("scroll-response-down");
try { });
globalShortcut.register(keybinds.emergencyErase, () => { console.log(`Registered scrollDown: ${keybinds.scrollDown}`);
console.log('Emergency Erase triggered!'); } catch (error) {
if (mainWindow && !mainWindow.isDestroyed()) { console.error(
mainWindow.hide(); `Failed to register scrollDown (${keybinds.scrollDown}):`,
error,
if (geminiSessionRef.current) { );
geminiSessionRef.current.close(); }
geminiSessionRef.current = null; }
}
// Register expand response shortcut
sendToRenderer('clear-sensitive-data'); if (keybinds.expandResponse) {
try {
setTimeout(() => { globalShortcut.register(keybinds.expandResponse, () => {
const { app } = require('electron'); console.log("Expand response shortcut triggered");
app.quit(); sendToRenderer("expand-response");
}, 300); });
} console.log(`Registered expandResponse: ${keybinds.expandResponse}`);
}); } catch (error) {
console.log(`Registered emergencyErase: ${keybinds.emergencyErase}`); console.error(
} catch (error) { `Failed to register expandResponse (${keybinds.expandResponse}):`,
console.error(`Failed to register emergencyErase (${keybinds.emergencyErase}):`, error); error,
);
}
}
// Register emergency erase shortcut
if (keybinds.emergencyErase) {
try {
globalShortcut.register(keybinds.emergencyErase, () => {
console.log("Emergency Erase triggered!");
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.hide();
if (geminiSessionRef.current) {
geminiSessionRef.current.close();
geminiSessionRef.current = null;
}
sendToRenderer("clear-sensitive-data");
setTimeout(() => {
const { app } = require("electron");
app.quit();
}, 300);
} }
});
console.log(`Registered emergencyErase: ${keybinds.emergencyErase}`);
} catch (error) {
console.error(
`Failed to register emergencyErase (${keybinds.emergencyErase}):`,
error,
);
} }
}
} }
function setupWindowIpcHandlers(mainWindow, sendToRenderer, geminiSessionRef) { function setupWindowIpcHandlers(mainWindow, sendToRenderer, geminiSessionRef) {
ipcMain.on('view-changed', (event, view) => { ipcMain.on("view-changed", (event, view) => {
if (!mainWindow.isDestroyed()) { if (!mainWindow.isDestroyed()) {
const primaryDisplay = screen.getPrimaryDisplay(); const primaryDisplay = screen.getPrimaryDisplay();
const { width: screenWidth } = primaryDisplay.workAreaSize; const { width: screenWidth } = primaryDisplay.workAreaSize;
if (view === 'assistant') { if (view === "assistant") {
// Shrink window for live view // Shrink window for live view
const liveWidth = 850; const liveWidth = 850;
const liveHeight = 400; const liveHeight = 400;
const x = Math.floor((screenWidth - liveWidth) / 2); const x = Math.floor((screenWidth - liveWidth) / 2);
mainWindow.setSize(liveWidth, liveHeight); mainWindow.setSize(liveWidth, liveHeight);
mainWindow.setPosition(x, 0); mainWindow.setPosition(x, 0);
} else { } else {
// Restore full size // Restore full size
const fullWidth = 1100; const fullWidth = 1100;
const fullHeight = 800; const fullHeight = 800;
const x = Math.floor((screenWidth - fullWidth) / 2); const x = Math.floor((screenWidth - fullWidth) / 2);
mainWindow.setSize(fullWidth, fullHeight); mainWindow.setSize(fullWidth, fullHeight);
mainWindow.setPosition(x, 0); mainWindow.setPosition(x, 0);
mainWindow.setIgnoreMouseEvents(false); mainWindow.setIgnoreMouseEvents(false);
} }
} }
}); });
ipcMain.handle('window-minimize', () => { ipcMain.handle("window-minimize", () => {
if (!mainWindow.isDestroyed()) { if (!mainWindow.isDestroyed()) {
mainWindow.minimize(); mainWindow.minimize();
} }
}); });
ipcMain.on('update-keybinds', (event, newKeybinds) => { ipcMain.on("update-keybinds", (event, newKeybinds) => {
if (!mainWindow.isDestroyed()) { if (!mainWindow.isDestroyed()) {
updateGlobalShortcuts(newKeybinds, mainWindow, sendToRenderer, geminiSessionRef); updateGlobalShortcuts(
} newKeybinds,
}); mainWindow,
sendToRenderer,
geminiSessionRef,
);
}
});
ipcMain.handle('toggle-window-visibility', async event => { ipcMain.handle("toggle-window-visibility", async (event) => {
try { try {
if (mainWindow.isDestroyed()) { if (mainWindow.isDestroyed()) {
return { success: false, error: 'Window has been destroyed' }; return { success: false, error: "Window has been destroyed" };
} }
if (mainWindow.isVisible()) { if (mainWindow.isVisible()) {
mainWindow.hide(); mainWindow.hide();
} else { } else {
mainWindow.showInactive(); mainWindow.showInactive();
} }
return { success: true }; return { success: true };
} catch (error) { } catch (error) {
console.error('Error toggling window visibility:', error); console.error("Error toggling window visibility:", error);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
}); });
ipcMain.handle('update-sizes', async event => { ipcMain.handle("update-sizes", async (event) => {
// With the sidebar layout, the window size is user-controlled. // With the sidebar layout, the window size is user-controlled.
// This handler is kept for compatibility but is a no-op now. // This handler is kept for compatibility but is a no-op now.
return { success: true }; return { success: true };
}); });
} }
module.exports = { module.exports = {
createWindow, createWindow,
getDefaultKeybinds, getDefaultKeybinds,
updateGlobalShortcuts, updateGlobalShortcuts,
setupWindowIpcHandlers, setupWindowIpcHandlers,
}; };