Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main process code, including preferences save/load system #67

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ app.on('activate', () => {

// import the ipc handlers setup in other files
import './main/platform.ts';
import './main/ipcs/window.ts';
import './main/ipcs/dialog.ts';
import './main/macMenu.ts';
41 changes: 41 additions & 0 deletions src/main/ipcs/dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { BrowserWindow, ipcMain, dialog } from 'electron';

ipcMain.handle('showUnsavedSaveDialog', async (e, name: string): Promise<UnsavedChangesResponse> => {
const result = await dialog.showMessageBox(BrowserWindow.fromWebContents(e.sender), {
message: 'Do you want to save the changes you made to ' + name + '?',
detail: 'Your changes will be lost if you dont save them.',
title: 'VizCon',
buttons: ['Save', "Don't Save", 'Cancel'],
type: 'warning',
noLink: true,
});

switch (result.response) {
case 0:
return 'save';
case 1:
return 'dontsave';
default:
return 'cancel';
}
});

ipcMain.handle('showUnsavedCompileDialog', async (e, name: string): Promise<UnsavedChangesResponse> => {
const result = await dialog.showMessageBox(BrowserWindow.fromWebContents(e.sender), {
message: 'Do you want to save the changes you made to ' + name + ' before you compile?',
detail: "Your changes will be not be compiled if you don't save them.",
title: 'VizCon',
buttons: ['Save', "Don't Save", 'Cancel'],
type: 'warning',
noLink: true,
});

switch (result.response) {
case 0:
return 'save';
case 1:
return 'dontsave';
default:
return 'cancel';
}
});
26 changes: 26 additions & 0 deletions src/main/ipcs/window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BrowserWindow, ipcMain } from 'electron';

ipcMain.handle('minimize', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.minimize();
});

ipcMain.handle('maximize', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.maximize();
});

ipcMain.handle('restore', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.restore();
});

ipcMain.handle('close', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.close();
});

ipcMain.handle('isMaximized', e => {
const window = BrowserWindow.fromWebContents(e.sender);
return window.isMaximized();
});
65 changes: 0 additions & 65 deletions src/main/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,6 @@ function updateLastSuccessfulFile(files: string[]): void {
}
}

ipcMain.handle('minimize', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.minimize();
});

ipcMain.handle('maximize', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.maximize();
});

ipcMain.handle('restore', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.restore();
});

ipcMain.handle('close', e => {
const window = BrowserWindow.fromWebContents(e.sender);
window.close();
});

ipcMain.handle('isMaximized', e => {
const window = BrowserWindow.fromWebContents(e.sender);
return window.isMaximized();
});

ipcMain.handle('openFileDialog', e => {
const window = BrowserWindow.fromWebContents(e.sender);
const results = dialog.showOpenDialogSync(window, {
Expand Down Expand Up @@ -247,43 +222,3 @@ ipcMain.on('launchProgram', (event, msg) => {
port.start();
launchProgram(msg.path, port);
});

ipcMain.handle('showUnsavedSaveDialog', async (e, name: string): Promise<UnsavedChangesResponse> => {
const result = await dialog.showMessageBox(BrowserWindow.fromWebContents(e.sender), {
message: 'Do you want to save the changes you made to ' + name + '?',
detail: 'Your changes will be lost if you dont save them.',
title: 'VizCon',
buttons: ['Save', "Don't Save", 'Cancel'],
type: 'warning',
noLink: true,
});

switch (result.response) {
case 0:
return 'save';
case 1:
return 'dontsave';
default:
return 'cancel';
}
});

ipcMain.handle('showUnsavedCompileDialog', async (e, name: string): Promise<UnsavedChangesResponse> => {
const result = await dialog.showMessageBox(BrowserWindow.fromWebContents(e.sender), {
message: 'Do you want to save the changes you made to ' + name + ' before you compile?',
detail: "Your changes will be not be compiled if you don't save them.",
title: 'VizCon',
buttons: ['Save', "Don't Save", 'Cancel'],
type: 'warning',
noLink: true,
});

switch (result.response) {
case 0:
return 'save';
case 1:
return 'dontsave';
default:
return 'cancel';
}
});