Skip to content

Commit

Permalink
Add devtools listener setting
Browse files Browse the repository at this point in the history
  • Loading branch information
zerebos committed Jan 26, 2022
1 parent 1d1fbc4 commit 8365730
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
6 changes: 5 additions & 1 deletion assets/locales/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@
},
"developer": {
"name": "Developer Settings",
"devTools": {
"name": "DevTools",
"note": "Enables toggling DevTools with ctrl+shift+i"
},
"debuggerHotkey": {
"name": "Debugger Hotkey",
"note": "Allows activating debugger when pressing F8"
"note": "Allows activating debugger when pressing F8 with DevTools open"
},
"reactDevTools": {
"name": "React Developer Tools",
Expand Down
1 change: 1 addition & 0 deletions common/constants/ipcevents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const RUN_SCRIPT = "bd-run-script";
export const NAVIGATE = "bd-did-navigate-in-page";
export const OPEN_DEVTOOLS = "bd-open-devtools";
export const CLOSE_DEVTOOLS = "bd-close-devtools";
export const TOGGLE_DEVTOOLS = "bd-toggle-devtools";
export const OPEN_WINDOW = "bd-open-window";
export const INSPECT_ELEMENT = "bd-inspect-element";
export const MINIMUM_SIZE = "bd-minimum-size";
Expand Down
5 changes: 5 additions & 0 deletions injector/src/modules/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const runScript = async (event, script) => {

const openDevTools = event => event.sender.openDevTools();
const closeDevTools = event => event.sender.closeDevTools();
const toggleDevTools = event => {
if (!event.sender.isDevToolsOpened()) openDevTools(event);
else closeDevTools(event);
};

const createBrowserWindow = (event, url, {windowOptions, closeOnUrl} = {}) => {
return new Promise(resolve => {
Expand Down Expand Up @@ -128,6 +132,7 @@ export default class IPCMain {
ipc.on(IPCEvents.RELAUNCH, relaunch);
ipc.on(IPCEvents.OPEN_DEVTOOLS, openDevTools);
ipc.on(IPCEvents.CLOSE_DEVTOOLS, closeDevTools);
ipc.on(IPCEvents.TOGGLE_DEVTOOLS, toggleDevTools);
ipc.on(IPCEvents.INSPECT_ELEMENT, inspectElement);
ipc.on(IPCEvents.MINIMUM_SIZE, setMinimumSize);
ipc.on(IPCEvents.DEVTOOLS_WARNING, stopDevtoolsWarning);
Expand Down
1 change: 1 addition & 0 deletions renderer/src/builtins/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {default as EmoteModule} from "./emotes/emotes";
export {default as EmoteMenu} from "./emotes/emotemenu";
// export {default as EmoteAutocaps} from "./emotes/emoteautocaps";

export {default as DevToolsListener} from "./developer/devtools";
export {default as Debugger} from "./developer/debugger";
export {default as ReactDevTools} from "./developer/reactdevtools";
export {default as InspectElement} from "./developer/inspectelement";
Expand Down
22 changes: 22 additions & 0 deletions renderer/src/builtins/developer/devtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Builtin from "../../structs/builtin";
import IPC from "../../modules/ipc";

export default new class DevToolsListener extends Builtin {
get name() {return "DevTools";}
get category() {return "developer";}
get id() {return "devTools";}

initialize() {
super.initialize(...arguments);
this.toggleDevTools = this.toggleDevTools.bind(this);
document.addEventListener("keydown", this.toggleDevTools);
}

toggleDevTools(e) {
if (e.ctrlKey && e.shiftKey && e.which === 73) { // Ctrl + Shift + I
e.stopPropagation();
e.preventDefault();
if (this.get(this.collection, this.category, this.id)) IPC.toggleDevTools();
}
}
};
11 changes: 6 additions & 5 deletions renderer/src/data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ export default [
collapsible: true,
shown: false,
settings: [
{type: "switch", id: "debuggerHotkey", value: false},
{type: "switch", id: "reactDevTools", value: false},
{type: "switch", id: "inspectElement", value: false},
{type: "switch", id: "devToolsWarning", value: false},
{type: "switch", id: "debugLogs", value: false}
{type: "switch", id: "debugLogs", value: false},
{type: "switch", id: "devTools", value: false},
{type: "switch", id: "debuggerHotkey", value: false, enableWith: "devTools"},
{type: "switch", id: "reactDevTools", value: false, enableWith: "devTools"},
{type: "switch", id: "inspectElement", value: false, enableWith: "devTools"},
{type: "switch", id: "devToolsWarning", value: false, enableWith: "devTools"},
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions renderer/src/modules/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default new class IPCRenderer {
return ipc.send(IPCEvents.CLOSE_DEVTOOLS);
}

toggleDevTools() {
return ipc.send(IPCEvents.TOGGLE_DEVTOOLS);
}

relaunch() {
return ipc.send(IPCEvents.RELAUNCH);
}
Expand Down
6 changes: 6 additions & 0 deletions renderer/src/styles/ui/switch.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.bd-switch {
position: relative;
transition: 250ms cubic-bezier(0, 0.3, 0.7, 1) filter, 250ms cubic-bezier(0, 0.3, 0.7, 1) opacity;
}

.bd-switch-body {
Expand Down Expand Up @@ -101,4 +102,9 @@

.bd-switch input:checked:active + .bd-switch-body .bd-switch-handle {
x: 0;
}

.bd-switch-disabled {
opacity: 0.5;
filter: grayscale(1);
}

0 comments on commit 8365730

Please sign in to comment.