2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50:56 +00:00

fix: maximize behaviour

This commit is contained in:
18alantom 2022-05-06 11:57:28 +05:30
parent 0f2d1284b2
commit b7f0757d69
6 changed files with 37 additions and 17 deletions

10
main.ts
View File

@ -17,9 +17,6 @@ import registerIpcMainMessageListeners from './main/registerIpcMainMessageListen
import registerProcessListeners from './main/registerProcessListeners'; import registerProcessListeners from './main/registerProcessListeners';
import { IPC_CHANNELS } from './utils/messages'; import { IPC_CHANNELS } from './utils/messages';
const WIDTH = 1200;
const HEIGHT = 900;
export class Main { export class Main {
title: string = 'Frappe Books'; title: string = 'Frappe Books';
icon: string; icon: string;
@ -29,6 +26,9 @@ export class Main {
checkedForUpdate = false; checkedForUpdate = false;
mainWindow: BrowserWindow | null = null; mainWindow: BrowserWindow | null = null;
WIDTH = 1200;
HEIGHT = 900;
constructor() { constructor() {
this.icon = this.isDevelopment this.icon = this.isDevelopment
? path.resolve('./build/icon.png') ? path.resolve('./build/icon.png')
@ -75,8 +75,8 @@ export class Main {
vibrancy: 'sidebar', vibrancy: 'sidebar',
transparent: this.isMac, transparent: this.isMac,
backgroundColor: '#80FFFFFF', backgroundColor: '#80FFFFFF',
width: WIDTH, width: this.WIDTH,
height: HEIGHT, height: this.HEIGHT,
title: this.title, title: this.title,
webPreferences: { webPreferences: {
contextIsolation: false, // TODO: Switch this off contextIsolation: false, // TODO: Switch this off

View File

@ -1,5 +1,4 @@
import { app } from 'electron'; import { app } from 'electron';
// @ts-ignore
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer'; import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
import { Main } from '../main'; import { Main } from '../main';

View File

@ -13,13 +13,14 @@ import { IPC_ACTIONS } from '../utils/messages';
export default function registerIpcMainActionListeners(main: Main) { export default function registerIpcMainActionListeners(main: Main) {
ipcMain.handle(IPC_ACTIONS.TOGGLE_MAXIMIZE_CURRENT_WINDOW, (event) => { ipcMain.handle(IPC_ACTIONS.TOGGLE_MAXIMIZE_CURRENT_WINDOW, (event) => {
const maximizing = main.mainWindow!.isMaximized(); const maximized = main.mainWindow!.isFullScreen();
if (maximizing) { if (maximized) {
main.mainWindow!.maximize(); main.mainWindow?.setFullScreen(false);
main.mainWindow?.setSize(main.WIDTH, main.HEIGHT, true);
} else { } else {
main.mainWindow!.unmaximize(); main.mainWindow?.setFullScreen(true);
} }
return maximizing; return maximized;
}); });
ipcMain.handle(IPC_ACTIONS.GET_OPEN_FILEPATH, async (event, options) => { ipcMain.handle(IPC_ACTIONS.GET_OPEN_FILEPATH, async (event, options) => {

View File

@ -19,8 +19,7 @@
</template> </template>
<script> <script>
import { runWindowAction } from "src/utils/ipcCalls"; import { runWindowAction } from 'src/utils/ipcCalls';
export default { export default {
name: 'WindowControls', name: 'WindowControls',
@ -31,6 +30,11 @@ export default {
default: () => ['close', 'minimize', 'maximize'], default: () => ['close', 'minimize', 'maximize'],
}, },
}, },
data() {
return {
fullscreen: false,
};
},
methods: { methods: {
async action(name) { async action(name) {
if (!this.buttons.includes(name)) { if (!this.buttons.includes(name)) {
@ -38,12 +42,26 @@ export default {
} }
const actionRan = await runWindowAction(name); const actionRan = await runWindowAction(name);
this.setFullscreen(actionRan);
this.$emit(actionRan); this.$emit(actionRan);
}, },
setFullscreen(actionRan) {
if (actionRan === 'maximize') {
this.fullscreen = true;
} else if (actionRan === 'unmaximize') {
this.fullscreen = false;
}
},
getColorClasses(name) { getColorClasses(name) {
let minimize = 'bg-yellow-500 hover:bg-yellow-700';
if (this.fullscreen) {
minimize = 'bg-gray-500';
}
let classes = { let classes = {
close: 'bg-red-500 hover:bg-red-700', close: 'bg-red-500 hover:bg-red-700',
minimize: 'bg-yellow-500 hover:bg-yellow-700', minimize,
maximize: 'bg-green-500 hover:bg-green-700', maximize: 'bg-green-500 hover:bg-green-700',
}[name]; }[name];

View File

@ -71,8 +71,8 @@
import { t } from 'fyo'; import { t } from 'fyo';
import Button from 'src/components/Button'; import Button from 'src/components/Button';
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
import { routeTo } from 'src/utils';
import { getDatesAndPeriodicity } from 'src/utils/misc'; import { getDatesAndPeriodicity } from 'src/utils/misc';
import { routeTo } from 'src/utils/ui';
import PeriodSelector from './PeriodSelector'; import PeriodSelector from './PeriodSelector';
import SectionHeader from './SectionHeader'; import SectionHeader from './SectionHeader';

View File

@ -35,11 +35,13 @@ export async function runWindowAction(name: WindowAction) {
ipcRenderer.send(IPC_MESSAGES.MINIMIZE_CURRENT_WINDOW); ipcRenderer.send(IPC_MESSAGES.MINIMIZE_CURRENT_WINDOW);
break; break;
case 'maximize': case 'maximize':
const maximizing = await ipcRenderer.invoke( const maximized = await ipcRenderer.invoke(
IPC_ACTIONS.TOGGLE_MAXIMIZE_CURRENT_WINDOW IPC_ACTIONS.TOGGLE_MAXIMIZE_CURRENT_WINDOW
); );
name = maximizing ? name : 'unmaximize'; name = maximized ? 'unmaximize' : name;
break; break;
default:
throw new Error(`invalid window action ${name}`);
} }
return name; return name;
} }