Skip to content

Commit

Permalink
Added window maximize function, optimized drawer behavior when last f…
Browse files Browse the repository at this point in the history
…ile is removed from sleek
  • Loading branch information
ransome1 committed Sep 23, 2023
1 parent 530afa5 commit f091568
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sleek
[![Code scan and test cases](https://github.com/ransome1/sleek/actions/workflows/code-scan.yml/badge.svg?branch=develop)](https://github.com/ransome1/sleek/actions/workflows/code-scan.yml)
[![sleek](https://snapcraft.io/sleek/badge.svg)](https://snapcraft.io/sleek)

## ❤️ Become a contributer.
[sleek is currently being rewritten.](https://github.com/ransome1/sleek/discussions/501) Now is a good time to join us in our mission to provide a user-friendly, free, and open-source todo.txt client. We're actively inviting passionate contributors skilled in `React`, `TypeScript`, `Electron`, and `Jest/Playwright` to join our collaborative effort. The `develop` branch reflects the most recent progress. Here you'll find our roadmap: https://github.com/users/ransome1/projects/3.

Expand Down
53 changes: 35 additions & 18 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createTray } from './tray';
import './modules/Ipc';

const files: File[] = (configStorage.get('files') as File[]) || [];
const windowMaximized: boolean = configStorage.get('windowMaximized');

let mainWindow: BrowserWindow | null = null;
let eventListeners: Record<string, any> = {};
Expand All @@ -38,19 +39,33 @@ const handleClosed = () => {
}

const handleResize = () => {
if (mainWindow) {
if (!windowMaximized && mainWindow) {
const { width, height } = mainWindow.getBounds();
configStorage.set('windowDimensions', { width, height });
}
}

const handleMove = () => {
if (mainWindow) {
if (!windowMaximized && mainWindow) {
const { x, y } = mainWindow.getBounds();
configStorage.set('windowPosition', { x, y });
}
}

const handleUnmaximize = () => {
configStorage.set('windowMaximized', false)
}

const handleMaximize = () => {
configStorage.set('windowMaximized', true)
}

const handleShow = () => {
if (app.dock) {
app.dock.show();
}
}

const createWindow = async() => {
mainWindow = new BrowserWindow({
width: 1280,
Expand All @@ -76,27 +91,33 @@ const createWindow = async() => {
}
});
}

const windowDimensions: { width: number; height: number } | null = configStorage.get('windowDimensions') as { width: number; height: number } | null;

if (windowDimensions) {
const { width, height } = windowDimensions;
mainWindow.setSize(width, height);
if(windowMaximized) {
mainWindow.maximize();
} else {
const windowDimensions: { width: number; height: number } | null = configStorage.get('windowDimensions') as { width: number; height: number } | null;

if (windowDimensions) {
const { width, height } = windowDimensions;
mainWindow.setSize(width, height);

const windowPosition: { x: number; y: number } | null = configStorage.get('windowPosition') as { x: number; y: number } | null;
if (windowPosition) {
const { x, y } = windowPosition;
mainWindow.setPosition(x, y);
const windowPosition: { x: number; y: number } | null = configStorage.get('windowPosition') as { x: number; y: number } | null;
if (windowPosition) {
const { x, y } = windowPosition;
mainWindow.setPosition(x, y);
}
}
}

mainWindow.loadURL(resolveHtmlPath('index.html'));
mainWindow
.on('ready-to-show', handleReadyToShow)
.on('resize', handleResize)
.on('move', handleMove)
.on('show', handleShow)
.on('closed', handleClosed);
.on('closed', handleClosed)
.on('maximize', handleMaximize)
.on('unmaximize', handleUnmaximize);
return "Main window has been created successfully"
}

Expand All @@ -123,11 +144,7 @@ const handleReadyToShow = async () => {
// }
}

const handleShow = () => {
if (app.dock) {
app.dock.show();
}
}


const handleWindowAllClosed = () => {
const tray: boolean = configStorage.get('tray');
Expand Down
20 changes: 12 additions & 8 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,18 @@ const App = () => {
isSettingsOpen={isSettingsOpen}
setIsSettingsOpen={setIsSettingsOpen}
/>
<DrawerComponent
isDrawerOpen={isDrawerOpen}
setIsDrawerOpen={setIsDrawerOpen}
attributes={attributes}
filters={filters}
sorting={sorting}
setSorting={setSorting}
/>
{files?.length > 0 && (
<>
<DrawerComponent
isDrawerOpen={isDrawerOpen}
setIsDrawerOpen={setIsDrawerOpen}
attributes={attributes}
filters={filters}
sorting={sorting}
setSorting={setSorting}
/>
</>
)}
<Box className="flexItems">
{files?.length > 0 && (
<>
Expand Down

0 comments on commit f091568

Please sign in to comment.