Skip to content

Commit 585f6eb

Browse files
committed
Log welcome message on devtools ready
1 parent d61d757 commit 585f6eb

2 files changed

Lines changed: 47 additions & 21 deletions

File tree

app/setup.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ if (config.fontFamily) {
1313
);
1414
}
1515

16-
console.warn(
17-
'[RNDebugger] Welcome! Before use this app, ' +
18-
'you need to ensure you are using the correct version of ' +
19-
'React Native Debugger and react-native:',
20-
);
21-
console.table({
22-
'React Native <= 0.61': { 'React Native Debugger Version': 'v0.10' },
23-
'React Native >= 0.62': { 'React Native Debugger Version': 'v0.11' },
24-
});
16+
window.logWelcomeMessage = () => {
17+
console.warn(
18+
'[RNDebugger] Welcome! Before use this app, ' +
19+
'you need to ensure you are using the correct version of ' +
20+
'React Native Debugger and react-native:',
21+
);
22+
console.table({
23+
'React Native <= 0.61': { 'React Native Debugger Version': 'v0.10' },
24+
'React Native >= 0.62': { 'React Native Debugger Version': 'v0.11' },
25+
});
26+
};

electron/window.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import { readConfig, filePath as configFile } from './config';
88

99
const store = new Store();
1010

11-
const executeJavaScript = (win, script) => win.webContents.executeJavaScript(script);
11+
const executeJavaScript = (win, script) =>
12+
win.webContents.executeJavaScript(script);
1213

13-
export const checkWindowInfo = win => executeJavaScript(win, 'window.checkWindowInfo()');
14+
export const checkWindowInfo = win =>
15+
executeJavaScript(win, 'window.checkWindowInfo()');
1416

15-
const checkIsOpenInEditorEnabled = win => executeJavaScript(win, 'window.isOpenInEditorEnabled()');
17+
const checkIsOpenInEditorEnabled = win =>
18+
executeJavaScript(win, 'window.isOpenInEditorEnabled()');
1619

1720
const changeMenuItems = menus => {
1821
const rootMenuItems = Menu.getApplicationMenu().items;
@@ -21,7 +24,9 @@ const changeMenuItems = menus => {
2124
if (!rootMenuItem || !rootMenuItem.submenu) return;
2225

2326
Object.entries(subMenu).forEach(([subKey, menuSet]) => {
24-
const menuItem = rootMenuItem.submenu.items.find(({ label }) => label === subKey);
27+
const menuItem = rootMenuItem.submenu.items.find(
28+
({ label }) => label === subKey,
29+
);
2530
if (!menuItem) return;
2631

2732
Object.assign(menuItem, menuSet);
@@ -30,16 +35,24 @@ const changeMenuItems = menus => {
3035
};
3136

3237
const invokeDevMethod = (win, name) =>
33-
executeJavaScript(win, `window.invokeDevMethod && window.invokeDevMethod('${name}')`);
38+
executeJavaScript(
39+
win,
40+
`window.invokeDevMethod && window.invokeDevMethod('${name}')`,
41+
);
3442

3543
const registerKeyboradShortcut = win => {
3644
const prefix = process.platform === 'darwin' ? 'Command' : 'Ctrl';
3745
// If another window focused, register a new shortcut
38-
if (globalShortcut.isRegistered(`${prefix}+R`) || globalShortcut.isRegistered(`${prefix}+I`)) {
46+
if (
47+
globalShortcut.isRegistered(`${prefix}+R`) ||
48+
globalShortcut.isRegistered(`${prefix}+I`)
49+
) {
3950
globalShortcut.unregisterAll();
4051
}
4152
globalShortcut.register(`${prefix}+R`, () => invokeDevMethod(win, 'reload'));
42-
globalShortcut.register(`${prefix}+I`, () => invokeDevMethod(win, 'toggleElementInspector'));
53+
globalShortcut.register(`${prefix}+I`, () =>
54+
invokeDevMethod(win, 'toggleElementInspector'),
55+
);
4356
};
4457

4558
const unregisterKeyboradShortcut = () => globalShortcut.unregisterAll();
@@ -68,7 +81,7 @@ export const createWindow = ({ iconPath, isPortSettingRequired, port }) => {
6881
`Parse root config failed, please checkout \`${configFile}\`, the error trace:\n\n` +
6982
`${error}\n\n` +
7083
'RNDebugger will load default config instead. ' +
71-
'You can click `Debugger` -> `Open Config File` in application menu.'
84+
'You can click `Debugger` -> `Open Config File` in application menu.',
7285
);
7386
}
7487

@@ -83,9 +96,9 @@ export const createWindow = ({ iconPath, isPortSettingRequired, port }) => {
8396
minHeight: minSize,
8497
...(increasePosition && winBounds && winBounds.x && winBounds.y
8598
? {
86-
x: winBounds.x + increasePosition,
87-
y: winBounds.y + increasePosition,
88-
}
99+
x: winBounds.x + increasePosition,
100+
y: winBounds.y + increasePosition,
101+
}
89102
: {}),
90103
backgroundColor: '#272c37',
91104
tabbingIdentifier: 'rndebugger',
@@ -127,6 +140,14 @@ export const createWindow = ({ iconPath, isPortSettingRequired, port }) => {
127140
removeUnecessaryTabs(win);
128141
}
129142
selectRNDebuggerWorkerContext(win);
143+
setTimeout(
144+
() =>
145+
executeJavaScript(
146+
win,
147+
'window.logWelcomeMessage && window.logWelcomeMessage()',
148+
),
149+
1e3,
150+
);
130151
});
131152
win.on('show', () => {
132153
if (!win.isFocused()) return;
@@ -141,7 +162,10 @@ export const createWindow = ({ iconPath, isPortSettingRequired, port }) => {
141162
unregisterKeyboradShortcut();
142163
store.set('winBounds', win.getBounds());
143164
store.set('zoomLevel', win.webContents.zoomLevel);
144-
await executeJavaScript(win, 'window.beforeWindowClose && window.beforeWindowClose()');
165+
await executeJavaScript(
166+
win,
167+
'window.beforeWindowClose && window.beforeWindowClose()',
168+
);
145169
win.destroy();
146170
};
147171
win.on('close', event => {

0 commit comments

Comments
 (0)