Skip to content

feat(stage-tamagotchi): add always-on-top toggle IPC API#1201

Closed
JasonOA888 wants to merge 2 commits intomoeru-ai:mainfrom
JasonOA888:feat/issue-1159-always-on-top-toggle
Closed

feat(stage-tamagotchi): add always-on-top toggle IPC API#1201
JasonOA888 wants to merge 2 commits intomoeru-ai:mainfrom
JasonOA888:feat/issue-1159-always-on-top-toggle

Conversation

@JasonOA888
Copy link
Contributor

Implements #1159

Changes

Added IPC API for toggling always-on-top mode:

Main Process

  • window:set-always-on-top(enabled) - Toggle always-on-top
  • window:get-always-on-top() - Get current state

Preload

  • window.alwaysOnTop.set(enabled) - Set mode
  • window.alwaysOnTop.get() - Get mode

Default

Enabled (current behavior preserved)

Usage

// Renderer process
const enabled = await window.alwaysOnTop.get()
await window.alwaysOnTop.set(false) // Disable always-on-top

Note: UI toggle button can be added separately.

Implements moeru-ai#1159

Added IPC handlers for toggling always-on-top:
- window:set-always-on-top(enabled): Toggle always-on-top
- window:get-always-on-top(): Get current state

Default: enabled (current behavior)

Note: UI toggle to be added in separate commit
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Inter-Process Communication (IPC) API to manage the "always-on-top" feature of the application window. This enhancement provides a programmatic way for the renderer process to toggle and query the window's always-on-top status, laying the groundwork for future user interface controls without altering the current default behavior.

Highlights

  • IPC API for Main Process: Introduced window:set-always-on-top(enabled) and window:get-always-on-top() IPC handlers in the main process to control the window's always-on-top state.
  • Preload API for Renderer Process: Exposed window.alwaysOnTop.set(enabled) and window.alwaysOnTop.get() to the renderer process, allowing programmatic control from the UI.
  • Default Behavior: Maintained the default behavior of the window being always-on-top, while enabling future toggling.
Changelog
  • apps/stage-tamagotchi/src/main/windows/main/index.ts
    • Added ipcMain.handle for window:set-always-on-top to dynamically set the window's always-on-top property.
    • Added ipcMain.handle for window:get-always-on-top to retrieve the current always-on-top status.
    • Initialized alwaysOnTopEnabled state variable to true and used it for the initial setAlwaysOnTop call.
  • apps/stage-tamagotchi/src/preload/shared.ts
    • Defined alwaysOnTopAPI object containing set and get methods that invoke the new IPC channels.
    • Exposed alwaysOnTopAPI to the renderer process via contextBridge.exposeInMainWorld('alwaysOnTop', alwaysOnTopAPI).
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an IPC API to toggle the always-on-top state of the main window. The implementation is functional, and my review includes suggestions to improve robustness and maintainability. Specifically, I've recommended removing redundant state management in the main process in favor of using the BrowserWindow instance as the single source of truth, and adding explicit types to the new preload API for better type safety in the renderer process, along with defining IPC channel names as constants.

Comment on lines +146 to +158
let alwaysOnTopEnabled = true // default enabled
window.setAlwaysOnTop(alwaysOnTopEnabled, 'screen-saver', 1)

// IPC handler for toggling always-on-top
ipcMain.handle('window:set-always-on-top', (_event, enabled: boolean) => {
alwaysOnTopEnabled = enabled
window.setAlwaysOnTop(enabled, 'screen-saver', 1)
return enabled
})

ipcMain.handle('window:get-always-on-top', () => {
return alwaysOnTopEnabled
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve robustness and simplify the code, it's better to avoid maintaining a separate state variable for the 'always-on-top' status. The BrowserWindow instance should be the single source of truth. You can use window.isAlwaysOnTop() in the get handler to directly query the window's state. This eliminates the alwaysOnTopEnabled variable and prevents any potential for state desynchronization.

  // Always on top - can be toggled via IPC
  window.setAlwaysOnTop(true, 'screen-saver', 1)

  // IPC handler for toggling always-on-top
  ipcMain.handle('window:set-always-on-top', (_event, enabled: boolean) => {
    window.setAlwaysOnTop(enabled, 'screen-saver', 1)
    return enabled
  })

  ipcMain.handle('window:get-always-on-top', () => {
    return window.isAlwaysOnTop()
  })

Comment on lines +9 to +12
export const alwaysOnTopAPI = {
set: (enabled: boolean) => ipcRenderer.invoke('window:set-always-on-top', enabled),
get: () => ipcRenderer.invoke('window:get-always-on-top'),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better type safety and maintainability, it's good practice to define an explicit interface for the exposed API. This helps consumers in the renderer process understand the method signatures and return types, enabling better autocompletion and compile-time checks.

Additionally, the IPC channel names are hardcoded as strings. It is recommended to define them as constants in a shared location to prevent typos and ease future maintenance.

export interface AlwaysOnTopAPI {
  set: (enabled: boolean) => Promise<boolean>;
  get: () => Promise<boolean>;
}

export const alwaysOnTopAPI: AlwaysOnTopAPI = {
  set: (enabled: boolean) => ipcRenderer.invoke('window:set-always-on-top', enabled),
  get: () => ipcRenderer.invoke('window:get-always-on-top'),
}

- Use window.isAlwaysOnTop() as single source of truth (no state variable)
- Add AlwaysOnTopAPI interface for type safety
- Remove redundant alwaysOnTopEnabled variable

Thanks @gemini-code-assist for the review!
@nekomeowww
Copy link
Member

#1183 already implemented.

@nekomeowww nekomeowww closed this Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants