Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions src/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IpcRendererEvent } from 'electron';
import * as MonacoType from 'monaco-editor';

import {
Expand Down Expand Up @@ -192,6 +193,14 @@ declare global {
themePath: string;
uncacheTypes(ver: RunnableVersion): Promise<void>;
unwatchElectronTypes(): Promise<void>;
addIpcRenderListener: (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

我想还是保持原来的做法可能更合适

channel: string,
cb: (channel: string) => void,
) => void;
removeIpcRenderListener: (
channel: string,
cb: (channel: string) => void,
) => void;
};
}
}
8 changes: 7 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IpcMainEvent,
app,
nativeTheme,
powerMonitor,
systemPreferences,
} from 'electron';

Expand Down Expand Up @@ -69,11 +70,16 @@ export async function onReady() {
// Do this after setting everything up to ensure that
// any IPC listeners are set up before they're used
mainIsReady();
await getOrCreateMainWindow();
const mainWindow = await getOrCreateMainWindow();

new TachybaseEngine();

processCommandLine(argv);

powerMonitor.on('lock-screen', () => {
mainWindow.webContents.send('lock-screen');
});
return mainWindow;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ export async function setupFiddleGlobal() {
async unwatchElectronTypes() {
await ipcRenderer.invoke(IpcEvents.UNWATCH_ELECTRON_TYPES);
},
addIpcRenderListener: (
channel: string,
callback: (channel: string) => void,
) => {
ipcRenderer.on(channel, () => {
callback(channel);
});
},
removeIpcRenderListener: (
channel: string,
callback: (channel: string) => void,
) => {
ipcRenderer.off(channel, () => {
callback(channel);
});
},
});
}

Expand Down
27 changes: 25 additions & 2 deletions src/renderer/components/main-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Spinner } from '@blueprintjs/core';
import { observer } from 'mobx-react-lite';

import { AppState } from '../state';

export const MainViewer = observer(({ appState }: { appState: AppState }) => {
useEffect(() => {
const lockScreenChannel = 'lock-screen';
const handler = (channel: string) => {
const webview = document.getElementById(
'mainView',
) as Electron.WebviewTag;
if (webview) {
webview.executeJavaScript(`
window.postMessage('${channel}', '*');
`);
} else {
console.warn('⚠️ webview not found!');
}
};
window.ElectronFiddle?.addIpcRenderListener(lockScreenChannel, handler);
return () => {
window.ElectronFiddle?.removeIpcRenderListener(
lockScreenChannel,
handler,
);
};
}, []);

console.log('🚀 ~ MainViewer ~ appState:', appState.enginePort);
if (
(appState.engineStatus === 'ready' || appState.engineStatus === 'remote') &&
Expand All @@ -14,7 +37,7 @@ export const MainViewer = observer(({ appState }: { appState: AppState }) => {
return (
<webview
id="mainView"
src={appState.enginePort}
src={`${appState.enginePort}/signin`}
Comment thread
wildworker marked this conversation as resolved.
Outdated
style={{ width: '100%', height: '100%' }}
/>
);
Expand Down
Loading