Windows Shell Integration

Context menu, Send To, and single-instance IPC for seamless Windows desktop experience.

Overview

Gravity integrates deeply with the Windows shell to provide frictionless access from anywhere in the filesystem.

Context Menu ("Open with Gravity")

Automatically registers HKCU registry entries under:

  • Software\Classes\*\shell\Gravity - for files
  • Software\Classes\Directory\shell\Gravity - for folders

This enables instant right-click file & folder opening in Gravity.

// Registry registration (runs on first launch / installer)
using Microsoft.Win32;

var key = Registry.CurrentUser.CreateSubKey(@"Software\\Classes\\*\\shell\\Gravity\\command");
key.SetValue("", $"\\\"{Assembly.GetExecutingAssembly().Location}\\\" \\\"%1\\\"");

var dirKey = Registry.CurrentUser.CreateSubKey(@"Software\\Classes\\Directory\\shell\\Gravity\\command");
dirKey.SetValue("", $"\\\"{Assembly.GetExecutingAssembly().Location}\\\" \\\"%1\\\"");

Send To Menu

Creates a shortcut in %APPDATA%\Microsoft\Windows\SendTo\Gravity.lnk so users can right-click → Send to → Gravity.

Single-Instance IPC

Uses a named Mutex + named pipe to ensure only one instance runs. Subsequent launches forward their command-line arguments to the running instance via IPC.

// Program.cs - Single instance pattern
static Mutex _mutex = new(true, "Global\\GravityAppSingleInstance", out bool createdNew);

if (!createdNew)
{
    // Send args to existing instance via named pipe
    using var client = new NamedPipeClientStream(".", "GravityIPC", PipeDirection.Out);
    client.Connect(1000);
    using var writer = new StreamWriter(client);
    writer.WriteLine(string.Join(" ", args));
    return 0;
}

// ... run app
// Named pipe server listens for incoming args
Task.Run(() => ListenForIpc());