"use strict";

// src-electron/preload/index.ts
var import_electron = require("electron");

// src-electron/common/build-channel.ts
var DEFAULT_BUILD_CHANNEL = "stable";
var envChannel = "stable"?.toLowerCase();
var BUILD_CHANNEL = envChannel === "canary" ? "canary" : DEFAULT_BUILD_CHANNEL;

// src-electron/preload/index.ts
var WS_PROXY_PORT = BUILD_CHANNEL === "canary" ? 21866 : 21865;
var API_PROXY_PORT = BUILD_CHANNEL === "canary" ? 21862 : 21861;
var MEDIA_PROXY_PORT = BUILD_CHANNEL === "canary" ? 21868 : 21867;
var MEDIA_PROXY_TOKEN = (() => {
  try {
    const response = import_electron.ipcRenderer.sendSync("get-media-proxy-token");
    if (typeof response === "string" && response) {
      return response;
    }
  } catch {
  }
  return null;
})();
var buildMediaProxyUrl = () => {
  try {
    const url = new URL(`http://127.0.0.1:${MEDIA_PROXY_PORT}/media`);
    if (MEDIA_PROXY_TOKEN) {
      url.searchParams.set("token", MEDIA_PROXY_TOKEN);
    }
    return url.toString();
  } catch {
    return null;
  }
};
var AP_PROXY_BASE_URL = `http://127.0.0.1:${API_PROXY_PORT}/proxy`;
var MEDIA_PROXY_URL = buildMediaProxyUrl();
var api = {
  platform: process.platform,
  getDesktopInfo: () => import_electron.ipcRenderer.invoke("get-desktop-info"),
  getWsProxyUrl: () => `ws://127.0.0.1:${WS_PROXY_PORT}`,
  getApiProxyUrl: () => AP_PROXY_BASE_URL,
  getMediaProxyUrl: () => MEDIA_PROXY_URL,
  onUpdaterEvent: (callback) => {
    const handler = (_event, data) => callback(data);
    import_electron.ipcRenderer.on("updater-event", handler);
    return () => import_electron.ipcRenderer.removeListener("updater-event", handler);
  },
  updaterCheck: (context) => import_electron.ipcRenderer.invoke("updater-check", context),
  updaterInstall: () => import_electron.ipcRenderer.invoke("updater-install"),
  windowMinimize: () => {
    import_electron.ipcRenderer.send("window-minimize");
  },
  windowMaximize: () => {
    import_electron.ipcRenderer.send("window-maximize");
  },
  windowClose: () => {
    import_electron.ipcRenderer.send("window-close");
  },
  windowIsMaximized: () => import_electron.ipcRenderer.invoke("window-is-maximized"),
  onWindowMaximizeChange: (callback) => {
    const handler = (_event, maximized) => {
      callback(maximized);
    };
    import_electron.ipcRenderer.on("window-maximize-change", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("window-maximize-change", handler);
    };
  },
  openExternal: (url) => import_electron.ipcRenderer.invoke("open-external", url),
  clipboardWriteText: (text) => import_electron.ipcRenderer.invoke("clipboard-write-text", text),
  clipboardReadText: () => import_electron.ipcRenderer.invoke("clipboard-read-text"),
  onDeepLink: (callback) => {
    const handler = (_event, url) => {
      callback(url);
    };
    import_electron.ipcRenderer.on("deep-link", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("deep-link", handler);
    };
  },
  getInitialDeepLink: () => import_electron.ipcRenderer.invoke("get-initial-deep-link"),
  onRpcNavigate: (callback) => {
    const handler = (_event, path) => {
      callback(path);
    };
    import_electron.ipcRenderer.on("rpc-navigate", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("rpc-navigate", handler);
    };
  },
  registerGlobalShortcut: (accelerator, id) => import_electron.ipcRenderer.invoke("register-global-shortcut", { accelerator, id }),
  unregisterGlobalShortcut: (accelerator) => import_electron.ipcRenderer.invoke("unregister-global-shortcut", accelerator),
  unregisterAllGlobalShortcuts: () => import_electron.ipcRenderer.invoke("unregister-all-global-shortcuts"),
  onGlobalShortcut: (callback) => {
    const handler = (_event, id) => {
      callback(id);
    };
    import_electron.ipcRenderer.on("global-shortcut-triggered", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("global-shortcut-triggered", handler);
    };
  },
  autostartEnable: () => import_electron.ipcRenderer.invoke("autostart-enable"),
  autostartDisable: () => import_electron.ipcRenderer.invoke("autostart-disable"),
  autostartIsEnabled: () => import_electron.ipcRenderer.invoke("autostart-is-enabled"),
  autostartIsInitialized: () => import_electron.ipcRenderer.invoke("autostart-is-initialized"),
  autostartMarkInitialized: () => import_electron.ipcRenderer.invoke("autostart-mark-initialized"),
  checkMediaAccess: (type) => import_electron.ipcRenderer.invoke("check-media-access", type),
  requestMediaAccess: (type) => import_electron.ipcRenderer.invoke("request-media-access", type),
  openMediaAccessSettings: (type) => import_electron.ipcRenderer.invoke("open-media-access-settings", type),
  checkAccessibility: (prompt) => import_electron.ipcRenderer.invoke("check-accessibility", prompt),
  openAccessibilitySettings: () => import_electron.ipcRenderer.invoke("open-accessibility-settings"),
  openInputMonitoringSettings: () => import_electron.ipcRenderer.invoke("open-input-monitoring-settings"),
  downloadFile: (url, defaultPath) => import_electron.ipcRenderer.invoke("download-file", { url, defaultPath }),
  passkeyIsSupported: () => import_electron.ipcRenderer.invoke("passkey-is-supported"),
  passkeyAuthenticate: (options) => import_electron.ipcRenderer.invoke("passkey-authenticate", options),
  passkeyRegister: (options) => import_electron.ipcRenderer.invoke("passkey-register", options),
  toggleDevTools: () => {
    import_electron.ipcRenderer.send("toggle-devtools");
  },
  getDesktopSources: (types) => import_electron.ipcRenderer.invoke("get-desktop-sources", types),
  onDisplayMediaRequested: (callback) => {
    const handler = (_event, requestId, info) => {
      callback(requestId, info);
    };
    import_electron.ipcRenderer.on("display-media-requested", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("display-media-requested", handler);
    };
  },
  selectDisplayMediaSource: (requestId, sourceId, withAudio) => {
    import_electron.ipcRenderer.send("select-display-media-source", requestId, sourceId, withAudio);
  },
  showNotification: (options) => import_electron.ipcRenderer.invoke("show-notification", options),
  closeNotification: (id) => {
    import_electron.ipcRenderer.send("close-notification", id);
  },
  closeNotifications: (ids) => {
    import_electron.ipcRenderer.send("close-notifications", ids);
  },
  onNotificationClick: (callback) => {
    const handler = (_event, id, url) => {
      callback(id, url);
    };
    import_electron.ipcRenderer.on("notification-click", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("notification-click", handler);
    };
  },
  setBadgeCount: (count) => {
    import_electron.ipcRenderer.send("set-badge-count", count);
  },
  getBadgeCount: () => import_electron.ipcRenderer.invoke("get-badge-count"),
  bounceDock: (type) => {
    return import_electron.ipcRenderer.sendSync("bounce-dock", type ?? "informational");
  },
  cancelBounceDock: (id) => {
    import_electron.ipcRenderer.send("cancel-bounce-dock", id);
  },
  setZoomFactor: (factor) => {
    import_electron.ipcRenderer.send("set-zoom-factor", factor);
  },
  getZoomFactor: () => import_electron.ipcRenderer.invoke("get-zoom-factor"),
  onZoomIn: (callback) => {
    const handler = () => callback();
    import_electron.ipcRenderer.on("zoom-in", handler);
    return () => import_electron.ipcRenderer.removeListener("zoom-in", handler);
  },
  onZoomOut: (callback) => {
    const handler = () => callback();
    import_electron.ipcRenderer.on("zoom-out", handler);
    return () => import_electron.ipcRenderer.removeListener("zoom-out", handler);
  },
  onZoomReset: (callback) => {
    const handler = () => callback();
    import_electron.ipcRenderer.on("zoom-reset", handler);
    return () => import_electron.ipcRenderer.removeListener("zoom-reset", handler);
  },
  onOpenSettings: (callback) => {
    const handler = () => callback();
    import_electron.ipcRenderer.on("open-settings", handler);
    return () => import_electron.ipcRenderer.removeListener("open-settings", handler);
  },
  globalKeyHookStart: () => import_electron.ipcRenderer.invoke("global-key-hook-start"),
  globalKeyHookStop: () => import_electron.ipcRenderer.invoke("global-key-hook-stop"),
  globalKeyHookIsRunning: () => import_electron.ipcRenderer.invoke("global-key-hook-is-running"),
  checkInputMonitoringAccess: () => import_electron.ipcRenderer.invoke("check-input-monitoring-access"),
  globalKeyHookRegister: (options) => import_electron.ipcRenderer.invoke("global-key-hook-register", options),
  globalKeyHookUnregister: (id) => import_electron.ipcRenderer.invoke("global-key-hook-unregister", id),
  globalKeyHookUnregisterAll: () => import_electron.ipcRenderer.invoke("global-key-hook-unregister-all"),
  onGlobalKeyEvent: (callback) => {
    const handler = (_event, data) => {
      callback(data);
    };
    import_electron.ipcRenderer.on("global-key-event", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("global-key-event", handler);
    };
  },
  onGlobalMouseEvent: (callback) => {
    const handler = (_event, data) => {
      callback(data);
    };
    import_electron.ipcRenderer.on("global-mouse-event", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("global-mouse-event", handler);
    };
  },
  onGlobalKeybindTriggered: (callback) => {
    const handler = (_event, data) => {
      callback(data);
    };
    import_electron.ipcRenderer.on("global-keybind-triggered", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("global-keybind-triggered", handler);
    };
  },
  spellcheckGetState: () => import_electron.ipcRenderer.invoke("spellcheck-get-state"),
  spellcheckSetState: (state) => import_electron.ipcRenderer.invoke("spellcheck-set-state", state),
  spellcheckGetAvailableLanguages: () => import_electron.ipcRenderer.invoke("spellcheck-get-available-languages"),
  spellcheckOpenLanguageSettings: () => import_electron.ipcRenderer.invoke("spellcheck-open-language-settings"),
  onSpellcheckStateChanged: (callback) => {
    const handler = (_event, data) => callback(data);
    import_electron.ipcRenderer.on("spellcheck-state-changed", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("spellcheck-state-changed", handler);
    };
  },
  onTextareaContextMenu: (callback) => {
    const handler = (_event, data) => callback(data);
    import_electron.ipcRenderer.on("textarea-context-menu", handler);
    return () => {
      import_electron.ipcRenderer.removeListener("textarea-context-menu", handler);
    };
  },
  spellcheckReplaceMisspelling: (replacement) => import_electron.ipcRenderer.invoke("spellcheck-replace-misspelling", replacement),
  spellcheckAddWordToDictionary: (word) => import_electron.ipcRenderer.invoke("spellcheck-add-word-to-dictionary", word)
};
window.addEventListener(
  "contextmenu",
  (event) => {
    const target = event.target;
    const isTextarea = Boolean(target?.closest?.("textarea"));
    import_electron.ipcRenderer.send("spellcheck-context-target", { isTextarea });
  },
  true
);
import_electron.contextBridge.exposeInMainWorld("electron", api);
//# sourceMappingURL=index.js.map
