Skip to content

Commit

Permalink
feat(tauri): add tray icon updating and a number of other commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Oct 1, 2023
1 parent 1a4365e commit b9cf906
Show file tree
Hide file tree
Showing 13 changed files with 1,645 additions and 282 deletions.
1 change: 1 addition & 0 deletions app/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"redux-devtools-extension": "^2.13.8",
"redux-undo": "^1.0.1",
"styled-components": "^5.3.11",
"tauri-plugin-autostart-api": "https://github.com/tauri-apps/tauri-plugin-autostart#v1",
"use-stay-awake": "^0.1.5"
},
"devDependencies": {
Expand Down
19 changes: 18 additions & 1 deletion app/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Suspense } from "react";
import React, { Suspense, useEffect } from "react";
import { HashRouter as Router, Switch, Route } from "react-router-dom";
import {
ThemeProvider,
Expand All @@ -14,6 +14,23 @@ export default function App() {
const settings = useSelector(
(state: AppStateTypes) => state.settings
);

useEffect(() => {
const contextEvent = (event: MouseEvent) => {
if (event.target) {
let target = event.target as HTMLElement;
if (target.tagName === "TEXTAREA") {
return true;
}
}
event.preventDefault();
return false;
};
document.addEventListener("contextmenu", contextEvent);
return () =>
document.removeEventListener("contextmenu", contextEvent);
}, []);

return (
<ThemeProvider>
<CounterProvider>
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const Layout: React.FC<Props> = ({ history, location, children }) => {

return (
<StyledLayout noTransition={noTransition}>
{!useNativeTitlebar.current && (
{!settings.useNativeTitlebar && (
<Titlebar
darkMode={settings.enableDarkTheme}
timerType={timer.timerType}
Expand Down
18 changes: 14 additions & 4 deletions app/renderer/src/contexts/connectors/TauriConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import {
SET_FULLSCREEN_BREAK,
SET_MINIMIZE,
SET_NATIVE_TITLEBAR,
SET_OPEN_AT_LOGIN,
SET_SHOW,
SET_UI_THEME,
TRAY_ICON_UPDATE,
} from "@pomatez/shareables";
import { encodeSvg } from "../../utils";
import { TraySVG } from "../../components";
import { enable, disable } from "tauri-plugin-autostart-api";

export const TauriConnectorProvider: React.FC = ({ children }) => {
const { invoke } = window.__TAURI__;

const settings: SettingTypes = useSelector(
(state: AppStateTypes) => state.settings
);

/**
* Rust uses lowercase snake_case for function names so we need to convert to lower case for the calls.
* @param event
Expand All @@ -32,14 +38,18 @@ export const TauriConnectorProvider: React.FC = ({ children }) => {
[invoke]
);

useEffect(() => {
if (settings.openAtLogin) {
enable().catch((err) => console.error(err));
} else {
disable().catch((err) => console.error(err));
}
}, [settings.openAtLogin]);

// TODO do logic to switch out the connectors based on the platform

const timer = useSelector((state: AppStateTypes) => state.timer);

const settings: SettingTypes = useSelector(
(state: AppStateTypes) => state.settings
);

const { count, duration, timerType, shouldFullscreen } =
useContext(CounterContext);
const dashOffset = (duration - count) * (24 / duration);
Expand Down
1 change: 1 addition & 0 deletions app/renderer/src/styles/components/titlebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const StyledMarkWrapper = styled.div`
column-gap: 0.8rem;
padding-left: 1rem;
pointer-events: none;
`;

export const StyledMarkLogo = styled.img`
Expand Down
Loading

0 comments on commit b9cf906

Please sign in to comment.