Skip to content

Commit

Permalink
improve: rename API to plutoDesktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Illusion47586 committed Jun 26, 2022
1 parent 9f25ca6 commit 67cccec
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/preload.ts
Expand Up @@ -2,7 +2,7 @@ import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';

export type Channels = 'ipc-example';

contextBridge.exposeInMainWorld('electron', {
contextBridge.exposeInMainWorld('plutoDesktop', {
ipcRenderer: {
sendMessage(channel: Channels, args: unknown[]) {
ipcRenderer.send(channel, args);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Loading.tsx
Expand Up @@ -6,7 +6,7 @@ const Loading = () => {
const [message, setMessage] = useState('');

useElectron((window) => {
window.electron.ipcRenderer.on('pluto-url', (m) => {
window.plutoDesktop.ipcRenderer.on('pluto-url', (m) => {
setMessage(String(m));
console.log(m);
});
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/index.tsx
Expand Up @@ -7,8 +7,8 @@ const root = createRoot(container);
root.render(<Loading />);

// calling IPC exposed from preload script
window.electron.ipcRenderer.once('ipc-example', (arg) => {
window.plutoDesktop.ipcRenderer.once('ipc-example', (arg) => {
// eslint-disable-next-line no-console
console.log(arg);
});
window.electron.ipcRenderer.sendMessage('ipc-example', ['ping']);
window.plutoDesktop.ipcRenderer.sendMessage('ipc-example', ['ping']);
2 changes: 1 addition & 1 deletion src/renderer/preload.d.ts
Expand Up @@ -2,7 +2,7 @@ import { Channels } from 'main/preload';

declare global {
interface Window {
electron: {
plutoDesktop: {
ipcRenderer: {
sendMessage(channel: Channels, args: unknown[]): void;
on(
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/useElectron.tsx
@@ -1,20 +1,20 @@
import { useEffect, useState } from 'react';

/**
* A hook to check whether pluto is running inside Electron,
* A hook to check whether pluto is running inside Desktop,
* and execute a callback if that is the case.
* @param callback A function that takes in a window (having electron as a property)
* as its argument, if electron is not found, it is not called.
* @returns A boolean denoting whether pluto is running inside Electron or not.
* @param callback A function that takes in a window (having `plutoDesktop` as a property)
* as its argument, if `plutoDesktop` is not found, it is not called.
* @returns A boolean denoting whether pluto is running inside Desktop or not.
*/
const useElectron = (callback?: (window: Window) => void) => {
const [isDesktop, setIsDesktop] = useState(false);

useEffect(() => {
if (window.electron) {
if (window.plutoDesktop) {
// console.log(
// 'Running in Electron Environment! Found following properties/methods:',
// window.electron
// 'Running in Desktop Environment! Found following properties/methods:',
// window.plutoDesktop
// );
setIsDesktop(true);
if (callback) callback(window);
Expand Down

0 comments on commit 67cccec

Please sign in to comment.