Skip to content

Commit

Permalink
feat: show the app on every timer ends if hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
roldanjr committed Jun 29, 2020
1 parent 560eea9 commit 2858737
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
7 changes: 7 additions & 0 deletions app/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getTrayIcon,
isWindow,
getFromStorage,
SET_SHOW,
} from "./helpers";
import store from "./store";

Expand Down Expand Up @@ -284,6 +285,12 @@ ipcMain.on(SET_UI_THEME, (e, { isDarkMode }) => {

ipcMain.on(SET_MINIMIZE, () => win?.minimize());

ipcMain.on(SET_SHOW, () => {
if (!win?.isVisible()) {
win?.show();
}
});

ipcMain.on(SET_CLOSE, () => app.quit());

ipcMain.on(SET_NATIVE_TITLEBAR, (e, { useNativeTitlebar }) => {
Expand Down
2 changes: 2 additions & 0 deletions app/electron/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const SET_NATIVE_TITLEBAR = "SET_NATIVE_TITLEBAR";
export const SET_UI_THEME = "SET_UI_THEME";
export const SET_MINIMIZE = "SET_MINIMIZE";
export const SET_CLOSE = "SET_CLOSE";
export const SET_SHOW = "SET_SHOW";

export const TO_MAIN: string[] = [
SET_ALWAYS_ON_TOP,
Expand All @@ -12,6 +13,7 @@ export const TO_MAIN: string[] = [
SET_UI_THEME,
SET_MINIMIZE,
SET_CLOSE,
SET_SHOW,
];

export const FROM_MAIN: string[] = [];
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "productivity-timer",
"version": "2.13.4-beta",
"version": "2.14.5-beta",
"private": true,
"license": "MIT",
"main": "public/electron.js",
Expand Down
21 changes: 15 additions & 6 deletions app/src/contexts/ElectronContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import isElectron from "is-electron";
import { AppStateTypes, SettingTypes } from "store";
import { CounterContext } from "./CounterContext";

export const SET_ALWAYS_ON_TOP = "SET_ALWAYS_ON_TOP";
export const SET_FULLSCREEN_BREAK = "SET_FULLSCREEN_BREAK";
export const SET_NATIVE_TITLEBAR = "SET_NATIVE_TITLEBAR";
export const SET_UI_THEME = "SET_UI_THEME";
export const SET_MINIMIZE = "SET_MINIMIZE";
export const SET_CLOSE = "SET_CLOSE";
const SET_ALWAYS_ON_TOP = "SET_ALWAYS_ON_TOP";
const SET_FULLSCREEN_BREAK = "SET_FULLSCREEN_BREAK";
const SET_NATIVE_TITLEBAR = "SET_NATIVE_TITLEBAR";
const SET_UI_THEME = "SET_UI_THEME";
const SET_MINIMIZE = "SET_MINIMIZE";
const SET_CLOSE = "SET_CLOSE";
const SET_SHOW = "SET_SHOW";

type ElectronProps = {
onMinimizeCallback?: () => void;
Expand All @@ -23,6 +24,8 @@ const ElectronContext = React.createContext<ElectronProps>({});
const ElectronProvider: React.FC = ({ children }) => {
const { electron } = window;

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

const settings: SettingTypes = useSelector(
(state: AppStateTypes) => state.settings
);
Expand Down Expand Up @@ -57,6 +60,12 @@ const ElectronProvider: React.FC = ({ children }) => {
}
}, [electron]);

useEffect(() => {
if (isElectron() && !settings.enableFullscreenBreak) {
electron.send(SET_SHOW);
}
}, [electron, timer.timerType, settings.enableFullscreenBreak]);

useEffect(() => {
if (isElectron()) {
electron.send(SET_ALWAYS_ON_TOP, {
Expand Down

0 comments on commit 2858737

Please sign in to comment.