Skip to content
Merged
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
62 changes: 62 additions & 0 deletions docs/native-desktop-audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Native desktop audit

Audited on October 13, 2026. Showcode uses Electron 41 with a shared Nuxt renderer in the `showcode` submodule. The best opportunities are the boundaries between the editor and the operating system. Replacing the code editor or preview controls would require separate native implementations on each platform.

## Patched

| Surface | Previous behavior | Desktop behavior |
| ------------------------------ | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Application menus | File only closed the window; app actions lived in HTML menus | Native File, Window, and Help actions for projects, the saved library, templates, exports, preferences, help, and changelog |
| Keyboard shortcuts | Browser listeners handled Save and New Project | Native menu accelerators handle Save, Save As, New/Close/Reopen Tab, tab switching, import, export, copy image, and preferences |
| Recent projects | Only the in-app dropdown listed recent saved projects | The native File menu also lists recent saved projects, with live enablement based on the active tab |
| Toolbar File button | HTML dropdown | Removed on macOS; File actions live in the native menu bar. Other desktop platforms open the native File menu from the button. |
| macOS tabs | A separate toolbar beneath the title bar | Tabs share a 44px title bar with native traffic lights. A bounded scrolling tab strip, fixed New Project button, and reserved Showcode drag area keep crowded windows usable. |
| Tab context menu | HTML context menu | Native menu with Save, Save As, Rename, Duplicate, Close, close-neighbor actions, and Reopen |
| Image export menu | HTML dropdown | Native PNG, JPEG, and SVG menu |
| Image and JSON exports | Browser downloads | Native save dialog with format filters, directory selection, and overwrite handling; Electron writes the chosen file |
| Project and background imports | Browser file input | Native open dialog; Electron reads only the selected file |
| Image clipboard | Browser ClipboardItem permissions and compatibility checks | Electron decodes the generated image and writes it to the system clipboard |
| Delete/reset confirmations | Browser confirm dialogs | Native modal dialogs attached to the app window, with Cancel as the default |
| Modified-tab closing | HTML save/discard dialog | Native Save Project / Cancel / Discard dialog |
| Template renaming | Browser prompt | Existing app rename dialog; Electron has no built-in native text-entry prompt |
| External links | Could open another Electron window or navigate away from the editor | HTTP, HTTPS, and mail links open in the user's default browser or mail app |
| Windows window controls | Hand-drawn HTML minimize/maximize/close buttons | Native titlebar overlay and system caption controls, with colors matching the app |
| macOS window behavior | Closing hid the whole app; Dock activation did not explicitly restore an existing hidden window | Closing hides the window; Dock activation shows and focuses it; titlebar double-click respects the system preference |
| Emoji picker | Global shortcuts registered even when another app was active | App-local Edit → Emoji & Symbols action, enabled only when supported |
| Text editing menus | No general native text-field context menu | Native Undo, Redo, Cut, Copy, Paste, and Select All for editable fields; Monaco retains its own editor menu |
| Native document state | Only the HTML title showed a modified marker | macOS also receives the active project's document-edited state |

The browser version keeps its existing file downloads, clipboard, dialogs, and menus. Save and Save As continue to save to Showcode's project library; Export Configuration is the action that writes a portable JSON file.

## Boundary fixes

- Native menus are created after Electron is ready.
- Window IPC handlers register once, and window-state events bind once per window. Reloading or recreating a window does not accumulate handlers.
- The preload keeps an explicit channel allowlist, strips privileged IPC event objects, and supports listener cleanup by channel. Menu command callbacks do not return Vue stores across the context bridge.
- Filesystem operations stay in the main process. The renderer passes file contents and suggested filenames, and cannot provide an arbitrary read/write path.
- Invalid JSON and API request files are rejected before creating an imported project tab.
- Existing updater work remains in place.

## Further native opportunities

| Opportunity | Recommendation |
| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Project library, templates, settings, and session storage | Move these from localStorage to versioned files under Electron's userData directory. Treat this as a persistence change with migration, backup/recovery, and interrupted-write handling. Existing IndexedDB-to-localStorage migration makes an incidental storage replacement risky. |
| Document files and Finder/Explorer integration | Introduce a dedicated `.showcode` format before adding file associations, open-file/second-instance handling, OS recent documents, represented filenames, and Save directly to an existing file. Associating all `.json` files with Showcode would be too broad. |
| Quit-time persistence | Add a main/renderer handshake to flush debounced editor state before quit or update installation. This should accompany an explicit decision about restoring unsaved tabs versus prompting for each document. |
| Native image sharing and dragging | A macOS Share menu and dragging a rendered image into another app are useful additions. Both need temporary exported files, cleanup, and platform-specific fallbacks. |
| Preferences window | A separate Electron preferences window could remain backed by the same Vue form. It needs synchronized preference state and ownership across windows. |
| Native notifications | Reserve these for background work that finishes while Showcode is inactive. In-app save/copy feedback is better served by the existing toast/button feedback. |
| Code editor, preview, cropping, theme/background pickers, and rename forms | Keep these in Vue/Monaco. Electron does not supply equivalent native components. A full native conversion would be a separate macOS/Windows/Linux UI project. |

## Validation

- Main process and preload: `npm test` — 15 passing tests.
- Shared renderer: `cd showcode && npm test -- --run` — 121 passing tests.
- Desktop renderer: `npm run generate` — passed.
- macOS Electron smoke tests use an isolated temporary user profile. File dialogs are stubbed to choose temporary paths; generated images are decoded by Electron, and clipboard writes are intercepted to preserve the user's clipboard.
- The final smoke run passed native New/Save/Recent actions, JSON import/export, PNG export and clipboard conversion, invalid-import handling, tab/export popup cancellation, preferences/help/changelog actions, close cancellation/discard/reopen, external browser routing, reload, Dock reopening, and window recreation. No renderer errors were reported.
- Windows caption controls and Linux native dialogs require checks on those operating systems. No signed installer or update installation was exercised.
- Crowded titlebar checks covered 25 tabs, a 620px window, the fixed New Project button and drag area, automatic active-tab scrolling, and light/dark styling. Physical window dragging still needs a manual check: native automation did not move either the custom titlebar or a standard macOS titlebar control window.

The native APIs are documented in Electron's [dialog](https://www.electronjs.org/docs/latest/api/dialog), [BrowserWindow](https://www.electronjs.org/docs/latest/api/browser-window), [webContents](https://www.electronjs.org/docs/latest/api/web-contents), and [MenuItem](https://www.electronjs.org/docs/latest/api/menu-item) references.
66 changes: 36 additions & 30 deletions main/BrowserWindowHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import log from "electron-log";
import SystemFontsModule from "system-font-families";
import {__DARWIN__} from "./platform.js";
import WindowStateHandler from "./WindowStateHandler.js";
import integrateWindow, {doubleClickTitleBar} from "./windowIntegrations.js";
import {windowForEvent} from "./desktop.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -32,7 +34,12 @@ export default class BrowserWinHandler {
this.options = options;
this.quitting = false;

this.bindIpc();
this.createInstance();

app.on("before-quit", () => {
this.quitting = true;
});
}

createInstance() {
Expand Down Expand Up @@ -81,38 +88,16 @@ export default class BrowserWinHandler {
disableBlinkFeatures: "Auxclick", // Disable auxclick event. See: https://developers.google.com/web/updates/2016/10/auxclick
webSecurity: !devServerUrl, // Disable on dev to allow loading local resources
preload: path.join(__dirname, "preload.cjs"),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
spellcheck: false,
},
});

mainWindowState.manage(this.browserWindow);

app.on("before-quit", () => {
this.quitting = true;
});

ipcMain.on("will-quit", (event) => {
this.quitting = true;
event.returnValue = true;
});

ipcMain.on("close", () => this.browserWindow.close());
ipcMain.on("maximize", () => this.browserWindow.maximize());
ipcMain.on("minimize", () => this.browserWindow.minimize());
ipcMain.on("unmaximize", () => this.browserWindow.unmaximize());

ipcMain.on("double-click-title-bar", () => {
this.browserWindow.isMaximized()
? this.browserWindow.unmaximize()
: this.browserWindow.maximize();
});

ipcMain.handle("get-window-state", async () => {
return new WindowStateHandler(this.browserWindow).get();
});

ipcMain.handle("get-system-fonts", async () => {
return await systemFonts.getFonts();
});
integrateWindow(this.browserWindow);
new WindowStateHandler(this.browserWindow).bind();

this.browserWindow.on("close", (e) => {
// On macOS, when the user closes the window we really
Expand All @@ -123,9 +108,9 @@ export default class BrowserWinHandler {

if (this.browserWindow.isFullScreen()) {
this.browserWindow.setFullScreen(false);
this.browserWindow.once("leave-full-screen", () => app.hide());
this.browserWindow.once("leave-full-screen", () => this.browserWindow.hide());
} else {
app.hide();
this.browserWindow.hide();
}

return;
Expand All @@ -143,7 +128,28 @@ export default class BrowserWinHandler {
recreate() {
if (this.browserWindow === null) {
this.create();
} else {
this.browserWindow.show();
this.browserWindow.focus();
}
}

bindIpc() {
for (const action of ["close", "maximize", "minimize", "unmaximize"]) {
ipcMain.on(action, (event) => windowForEvent(event)[action]());
}

ipcMain.on("double-click-title-bar", (event) => doubleClickTitleBar(windowForEvent(event)));

ipcMain.handle("get-window-state", (event) => {
return new WindowStateHandler(windowForEvent(event)).get();
});

ipcMain.handle("get-system-fonts", (event) => {
windowForEvent(event);

return systemFonts.getFonts();
});
}

/**
Expand Down
Loading