Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: b/w when window is unfocused

Abdullah Atta690b157387de
diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsx
index b1a88c382..1d7590fa3 100644
--- a/apps/web/src/app.tsx
+++ b/apps/web/src/app.tsx
@@ -38,6 +38,8 @@ import {
import GlobalMenuWrapper from "./components/global-menu-wrapper";
import AppEffects from "./app-effects";
import HashRouter from "./components/hash-router";
+import { useWindowFocus } from "./hooks/use-window-focus";
+import { Global } from "@emotion/react";
new WebExtensionRelay();
@@ -47,10 +49,23 @@ function App() {
const isMobile = useMobile();
const [show, setShow] = useState(true);
const isFocusMode = useStore((store) => store.isFocusMode);
+ const { isFocused } = useWindowFocus();
console.timeEnd("loading app");
return (
<>
+ {isFocused ? null : (
+ <Global
+ styles={`
+ body {
+ filter: brightness(0.95) grayscale(1);
+ }
+ .titlebar {
+ background: var(--background-secondary) !important;
+ }
+ `}
+ />
+ )}
<Suspense fallback={<div style={{ display: "none" }} />}>
<div id="menu-wrapper">
<GlobalMenuWrapper />
@@ -69,7 +84,11 @@ function App() {
id="app"
bg="background"
className={isFocusMode ? "app-focus-mode" : ""}
- sx={{ overflow: "hidden", flexDirection: "column", height: "100%" }}
+ sx={{
+ overflow: "hidden",
+ flexDirection: "column",
+ height: "100%"
+ }}
>
{isMobile ? (
<MobileAppContents />
diff --git a/apps/web/src/components/title-bar/index.tsx b/apps/web/src/components/title-bar/index.tsx
index e41a4d26a..5057431ba 100644
--- a/apps/web/src/components/title-bar/index.tsx
+++ b/apps/web/src/components/title-bar/index.tsx
@@ -65,6 +65,7 @@ export function TitleBar() {
return (
<BaseThemeProvider
scope="titleBar"
+ className="titlebar"
sx={{
background: "background",
height: TITLE_BAR_HEIGHT,
diff --git a/apps/web/src/hooks/use-window-controls.ts b/apps/web/src/hooks/use-window-controls.ts
index 6ae430073..644032e53 100644
--- a/apps/web/src/hooks/use-window-controls.ts
+++ b/apps/web/src/hooks/use-window-controls.ts
@@ -37,7 +37,6 @@ export function useWindowControls() {
function onFullscreenChange() {
setIsFullscreen(!!document.fullscreenElement);
- console.log(document.fullscreenElement);
}
document.addEventListener("fullscreenchange", onFullscreenChange);
return () => {
diff --git a/apps/web/src/hooks/use-window-focus.ts b/apps/web/src/hooks/use-window-focus.ts
new file mode 100644
index 000000000..3395acf46
--- /dev/null
+++ b/apps/web/src/hooks/use-window-focus.ts
@@ -0,0 +1,43 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { useEffect, useState } from "react";
+
+export function useWindowFocus() {
+ const [isFocused, setIsFocused] = useState<boolean>(true);
+
+ useEffect(() => {
+ function onFocus() {
+ setIsFocused(true);
+ }
+ function onBlur() {
+ setIsFocused(false);
+ }
+ window.addEventListener("focus", onFocus);
+ window.addEventListener("blur", onBlur);
+ return () => {
+ document.removeEventListener("focus", onFocus);
+ document.removeEventListener("blur", onBlur);
+ };
+ }, []);
+
+ return {
+ isFocused
+ };
+}