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:
parent
0f2d1284b2
commit
b7f0757d69
10
main.ts
10
main.ts
@ -17,9 +17,6 @@ import registerIpcMainMessageListeners from './main/registerIpcMainMessageListen
|
||||
import registerProcessListeners from './main/registerProcessListeners';
|
||||
import { IPC_CHANNELS } from './utils/messages';
|
||||
|
||||
const WIDTH = 1200;
|
||||
const HEIGHT = 900;
|
||||
|
||||
export class Main {
|
||||
title: string = 'Frappe Books';
|
||||
icon: string;
|
||||
@ -29,6 +26,9 @@ export class Main {
|
||||
checkedForUpdate = false;
|
||||
mainWindow: BrowserWindow | null = null;
|
||||
|
||||
WIDTH = 1200;
|
||||
HEIGHT = 900;
|
||||
|
||||
constructor() {
|
||||
this.icon = this.isDevelopment
|
||||
? path.resolve('./build/icon.png')
|
||||
@ -75,8 +75,8 @@ export class Main {
|
||||
vibrancy: 'sidebar',
|
||||
transparent: this.isMac,
|
||||
backgroundColor: '#80FFFFFF',
|
||||
width: WIDTH,
|
||||
height: HEIGHT,
|
||||
width: this.WIDTH,
|
||||
height: this.HEIGHT,
|
||||
title: this.title,
|
||||
webPreferences: {
|
||||
contextIsolation: false, // TODO: Switch this off
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { app } from 'electron';
|
||||
// @ts-ignore
|
||||
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
|
||||
import { Main } from '../main';
|
||||
|
||||
|
@ -13,13 +13,14 @@ import { IPC_ACTIONS } from '../utils/messages';
|
||||
|
||||
export default function registerIpcMainActionListeners(main: Main) {
|
||||
ipcMain.handle(IPC_ACTIONS.TOGGLE_MAXIMIZE_CURRENT_WINDOW, (event) => {
|
||||
const maximizing = main.mainWindow!.isMaximized();
|
||||
if (maximizing) {
|
||||
main.mainWindow!.maximize();
|
||||
const maximized = main.mainWindow!.isFullScreen();
|
||||
if (maximized) {
|
||||
main.mainWindow?.setFullScreen(false);
|
||||
main.mainWindow?.setSize(main.WIDTH, main.HEIGHT, true);
|
||||
} else {
|
||||
main.mainWindow!.unmaximize();
|
||||
main.mainWindow?.setFullScreen(true);
|
||||
}
|
||||
return maximizing;
|
||||
return maximized;
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_ACTIONS.GET_OPEN_FILEPATH, async (event, options) => {
|
||||
|
@ -19,8 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { runWindowAction } from "src/utils/ipcCalls";
|
||||
|
||||
import { runWindowAction } from 'src/utils/ipcCalls';
|
||||
|
||||
export default {
|
||||
name: 'WindowControls',
|
||||
@ -31,6 +30,11 @@ export default {
|
||||
default: () => ['close', 'minimize', 'maximize'],
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
fullscreen: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async action(name) {
|
||||
if (!this.buttons.includes(name)) {
|
||||
@ -38,12 +42,26 @@ export default {
|
||||
}
|
||||
|
||||
const actionRan = await runWindowAction(name);
|
||||
|
||||
this.setFullscreen(actionRan);
|
||||
this.$emit(actionRan);
|
||||
},
|
||||
setFullscreen(actionRan) {
|
||||
if (actionRan === 'maximize') {
|
||||
this.fullscreen = true;
|
||||
} else if (actionRan === 'unmaximize') {
|
||||
this.fullscreen = false;
|
||||
}
|
||||
},
|
||||
getColorClasses(name) {
|
||||
let minimize = 'bg-yellow-500 hover:bg-yellow-700';
|
||||
if (this.fullscreen) {
|
||||
minimize = 'bg-gray-500';
|
||||
}
|
||||
|
||||
let classes = {
|
||||
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',
|
||||
}[name];
|
||||
|
||||
|
@ -71,8 +71,8 @@
|
||||
import { t } from 'fyo';
|
||||
import Button from 'src/components/Button';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { routeTo } from 'src/utils';
|
||||
import { getDatesAndPeriodicity } from 'src/utils/misc';
|
||||
import { routeTo } from 'src/utils/ui';
|
||||
import PeriodSelector from './PeriodSelector';
|
||||
import SectionHeader from './SectionHeader';
|
||||
|
||||
|
@ -35,11 +35,13 @@ export async function runWindowAction(name: WindowAction) {
|
||||
ipcRenderer.send(IPC_MESSAGES.MINIMIZE_CURRENT_WINDOW);
|
||||
break;
|
||||
case 'maximize':
|
||||
const maximizing = await ipcRenderer.invoke(
|
||||
const maximized = await ipcRenderer.invoke(
|
||||
IPC_ACTIONS.TOGGLE_MAXIMIZE_CURRENT_WINDOW
|
||||
);
|
||||
name = maximizing ? name : 'unmaximize';
|
||||
name = maximized ? 'unmaximize' : name;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`invalid window action ${name}`);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user