Skip to content

Commit

Permalink
other: Progress on background threads
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed May 23, 2021
1 parent 7f99fa8 commit f417e64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1>Background</h1>

<script type="text/javascript">
const { ipcRenderer } = require('electron');

// let the main thread know this thread is ready to process something
function ready() {
ipcRenderer.send('bg-ready');
}

ready();
</script>
18 changes: 18 additions & 0 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AutoCorrection from './autocorrection';
import { RECEIVE_FILE_PATH, REQUEST_FILE_PATH } from './constants/OpenFileIPC';

let mainWindow: BrowserWindow | null = null;
let bgWindow: BrowserWindow | null = null;
let file = '';

if (process.env.NODE_ENV === 'production') {
Expand All @@ -46,6 +47,19 @@ const installExtensions = async () => {
).catch(console.log);
};

function createBgWindow() {
bgWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
},
});
bgWindow.loadURL(`file://${__dirname}/background.html`);
bgWindow.on('closed', () => {
bgWindow = null;
});
}

const createWindow = async () => {
if (
process.env.NODE_ENV === 'development' ||
Expand Down Expand Up @@ -93,12 +107,16 @@ const createWindow = async () => {
});

mainWindow.on('closed', () => {
bgWindow?.close();
mainWindow = null;
});

const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu();

// Create background worker window
if (bgWindow === null) createBgWindow();

new AppUpdater();
new Backup();
new Importer(mainWindow);
Expand Down

0 comments on commit f417e64

Please sign in to comment.