Skip to content

Commit

Permalink
Split simple-bar & yabai context in order to optimize rerenders + add…
Browse files Browse the repository at this point in the history
… memo on spaces & process widgets
  • Loading branch information
Jean-Tinland committed Dec 25, 2023
1 parent 6207637 commit 89b36bd
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 61 deletions.
22 changes: 13 additions & 9 deletions index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UserWidgets from "./lib/components/data/user-widgets.jsx";
import * as Error from "./lib/components/error.jsx";
import ContextProvider from "./lib/components/context.jsx";
import SimpleBarContextProvider from "./lib/components/simple-bar-context.jsx";
import * as Spaces from "./lib/components/spaces/spaces.jsx";
import * as Process from "./lib/components/spaces/process.jsx";
import * as Variables from "./lib/styles/core/variables";
Expand Down Expand Up @@ -29,6 +29,7 @@ import * as DataWidgetLoader from "./lib/components/data/data-widget-loader.jsx"
import * as DataWidget from "./lib/components/data/data-widget.jsx";
import * as Utils from "./lib/utils";
import * as Settings from "./lib/settings";
import YabaiContextProvider from "./lib/components/yabai-context.jsx";

const refreshFrequency = false;

Expand Down Expand Up @@ -109,17 +110,20 @@ const render = ({ output, error }) => {
Utils.handleBarFocus();

return (
<ContextProvider
<SimpleBarContextProvider
initialSettings={settings}
SIPDisabled={SIPDisabled}
displays={displays}
spaces={spaces}
windows={windows}
skhdMode={skhdMode}
SIPDisabled={SIPDisabled}
>
<div className={classes}>
<Spaces.Component />
<Process.Component />
<YabaiContextProvider
spaces={spaces}
windows={windows}
skhdMode={skhdMode}
>
<Spaces.Component />
<Process.Component />
</YabaiContextProvider>
<Settings.Wrapper />
<div className="simple-bar__data">
<UserWidgets />
Expand All @@ -143,7 +147,7 @@ const render = ({ output, error }) => {
<Time.Widget />
</div>
</div>
</ContextProvider>
</SimpleBarContextProvider>
);
};

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/battery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { batteryStyles as styles } from "../../styles/components/data/battery";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/browser-track.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { browserTrackStyles as styles } from "../../styles/components/data/browser-track";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/cpu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Graph from "./graph.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { cpuStyles as styles } from "../../styles/components/data/cpu";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/crypto.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { cryptoStyles as styles } from "../../styles/components/data/crypto";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/date-display.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Icons from "../icons.jsx";
import * as Utils from "../../utils";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";

export { dateStyles as styles } from "../../styles/components/data/date-display";

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/keyboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { keyboardStyles as styles } from "../../styles/components/data/keyboard";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/mic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import * as Utils from "../../utils";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";

const { React } = Uebersicht;

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/mpd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { mpdStyles as styles } from "../../styles/components/data/mpd";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/music.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { musicStyles as styles } from "../../styles/components/data/music";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/netstats.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import Graph from "./graph.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh.js";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Icons from "../icons.jsx";
import * as Utils from "../../utils.js";

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/sound.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { soundStyles as styles } from "../../styles/components/data/sound";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/spotify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as DataWidget from "./data-widget.jsx";
import * as DataWidgetLoader from "./data-widget-loader.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Icons from "../icons.jsx";
import * as Utils from "../../utils";

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/stock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { stockStyles as styles } from "../../styles/components/data/stock";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/time.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { timeStyles as styles } from "../../styles/components/data/time";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/user-widgets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Settings from "../../settings";
import * as Utils from "../../utils";

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/viscosity-vpn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { viscosityVPNStyles as styles } from "../../styles/components/data/viscosity-vpn";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/weather.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Icons from "../icons.jsx";
import * as Utils from "../../utils";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";

export { weatherStyles as styles } from "../../styles/components/data/weather";

Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/wifi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { wifiStyles as styles } from "../../styles/components/data/wifi";
Expand Down
2 changes: 1 addition & 1 deletion lib/components/data/zoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataWidgetLoader from "./data-widget-loader.jsx";
import * as Icons from "../icons.jsx";
import useWidgetRefresh from "../../hooks/use-widget-refresh";
import useServerSocket from "../../hooks/use-server-socket";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

export { zoomStyles as styles } from "../../styles/components/data/zoom";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ const SimpleBarContext = React.createContext({

export const useSimpleBarContext = () => React.useContext(SimpleBarContext);

export default React.memo(ContextProvider);

function ContextProvider({
export default function SimpleBarContextProvider({
initialSettings,
spaces,
windows,
displays,
SIPDisabled,
skhdMode,
children,
}) {
const [settings, setSettings] = React.useState(initialSettings);
Expand All @@ -35,10 +30,6 @@ function ContextProvider({
SIPDisabled,
settings,
setSettings,
spaces,
windows,
displays,
skhdMode,
}}
>
{children}
Expand Down
6 changes: 2 additions & 4 deletions lib/components/spaces/opened-apps.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AppIcons from "../../app-icons";
import * as Utils from "../../utils";

const OpenedApps = ({ apps }) => {
export default function OpenedApps({ apps }) {
if (!apps.length) return null;
return Utils.sortWindows(apps).map((app, i) => {
const {
Expand Down Expand Up @@ -29,6 +29,4 @@ const OpenedApps = ({ apps }) => {

return <Icon className={classes} key={i} />;
});
};

export default OpenedApps;
}
16 changes: 11 additions & 5 deletions lib/components/spaces/process.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as Uebersicht from "uebersicht";
import Window from "./window.jsx";
import * as Utils from "../../utils";
import { useSimpleBarContext } from "../context.jsx";
import { useYabaiContext } from "../yabai-context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";

export { processStyles as styles } from "../../styles/components/process";

export const Component = () => {
const { displayIndex, spaces, windows, skhdMode, settings } =
useSimpleBarContext();
const { React } = Uebersicht;

export const Component = React.memo(() => {
const { spaces, windows, skhdMode } = useYabaiContext();
const { displayIndex, settings } = useSimpleBarContext();
const { process, spacesDisplay, widgets } = settings;
const { processWidget } = widgets;
const { exclusionsAsRegex } = spacesDisplay;
Expand Down Expand Up @@ -78,4 +82,6 @@ export const Component = () => {
</div>
</div>
);
};
});

Component.displayName = "Process";
2 changes: 1 addition & 1 deletion lib/components/spaces/space-options.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Icons from "../icons.jsx";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";
import * as Yabai from "../../yabai";

Expand Down
17 changes: 11 additions & 6 deletions lib/components/spaces/space.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import * as Uebersicht from "uebersicht";
import OpenedApps from "./opened-apps.jsx";
import SpaceOptions from "./space-options.jsx";
import { useSimpleBarContext } from "../context.jsx";
import { useYabaiContext } from "../yabai-context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";
import * as Yabai from "../../yabai";

const { React } = Uebersicht;

const Space = ({ space, display, currentSpaceIndex, lastOfSpace }) => {
const { SIPDisabled, windows, settings } = useSimpleBarContext();
export default function Space({
space,
display,
currentSpaceIndex,
lastOfSpace,
}) {
const { windows } = useYabaiContext();
const { SIPDisabled, settings } = useSimpleBarContext();
const { spacesDisplay } = settings;
const {
displayAllSpacesOnAllScreens,
Expand Down Expand Up @@ -150,6 +157,4 @@ const Space = ({ space, display, currentSpaceIndex, lastOfSpace }) => {
</div>
</React.Fragment>
);
};

export default Space;
}
7 changes: 4 additions & 3 deletions lib/components/spaces/spaces.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import * as Uebersicht from "uebersicht";
import Space from "./space.jsx";
import Stickies from "./stickies.jsx";
import * as Icons from "../icons.jsx";
import { useYabaiContext } from "../yabai-context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";
import * as Yabai from "../../yabai";
import { useSimpleBarContext } from "../context.jsx";

export { spacesStyles as styles } from "../../styles/components/spaces/spaces";

const { React } = Uebersicht;

export const Component = React.memo(() => {
const { SIPDisabled, displayIndex, spaces, windows, settings } =
useSimpleBarContext();
const { spaces, windows } = useYabaiContext();
const { SIPDisabled, displayIndex, settings } = useSimpleBarContext();
const { spacesDisplay, process } = settings;
const {
displayStickyWindowsSeparately,
Expand Down
6 changes: 4 additions & 2 deletions lib/components/spaces/stickies.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as Uebersicht from "uebersicht";
import OpenedApps from "./opened-apps.jsx";
import { useSimpleBarContext } from "../context.jsx";
import { useYabaiContext } from "../yabai-context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

const { React } = Uebersicht;

const Stickies = ({ display }) => {
const { settings, windows } = useSimpleBarContext();
const { windows } = useYabaiContext();
const { settings } = useSimpleBarContext();
const { spacesDisplay } = settings;
const { exclusionsAsRegex, hideDuplicateAppsInSpaces } = spacesDisplay;
const exclusions = exclusionsAsRegex
Expand Down
2 changes: 1 addition & 1 deletion lib/components/spaces/window.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Uebersicht from "uebersicht";
import * as AppIcons from "../../app-icons";
import { useSimpleBarContext } from "../context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";
import * as Yabai from "../../yabai";

Expand Down
Loading

0 comments on commit 89b36bd

Please sign in to comment.