Skip to content

Commit

Permalink
Webview - Visit initial web address, go back, forward, home (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuaYoo authored May 7, 2022
1 parent 5b307bc commit 836d89a
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 141 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Secured browser for accessing NPLD content in Legal Deposit Library reading room

### Quickstart

Copy environment variables:

```sh
cp sample.env .env
```

Install and run app locally:

```sh
yarn && yarn start
```
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
{
"html": "./src/index.html",
"js": "./src/renderer.ts",
"name": "main_window"
"name": "main_window",
"preload": {
"js": "./src/preload.ts"
}
}
]
}
Expand All @@ -65,12 +68,13 @@
"@electron-forge/maker-squirrel": "^6.0.0-beta.63",
"@electron-forge/maker-zip": "^6.0.0-beta.63",
"@electron-forge/plugin-webpack": "6.0.0-beta.63",
"@shoelace-style/shoelace": "^2.0.0-beta.73",
"@shoelace-style/shoelace": "2.0.0-beta.72",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@vercel/webpack-asset-relocator-loader": "1.7.0",
"copy-webpack-plugin": "^10.2.4",
"css-loader": "^6.0.0",
"dotenv": "^16.0.0",
"electron": "18.2.0",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.0",
Expand Down
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NPLD_PLAYER_PREFIX=
NPLD_PLAYER_INITIAL_WEB_ADDRESS=https://webrecorder.net
122 changes: 0 additions & 122 deletions src/app-bar.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@ body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
Arial, sans-serif;
margin: 0;
}

#webview {
background: #eee;
height: calc(100vh - 47px); /* app height - app bar height */
}
6 changes: 2 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
<title>NPLD Player</title>
</head>
<body>
<app-bar></app-bar>
<main id="webview">
<!-- TODO Webview goes here -->
</main>
<!-- URL is set in preload script -->
<npld-player></npld-player>
</body>
</html>
30 changes: 27 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { app, BrowserWindow } from 'electron';
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
// whether you're running in development or production).
declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;

// const isDev = !app.isPackaged;
const isDev = !app.isPackaged;

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
Expand All @@ -15,15 +16,38 @@ if (require('electron-squirrel-startup')) {
const createWindow = (): void => {
// Create the browser window.
const mainWindow = new BrowserWindow({
show: false, // show once the renderer process has rendered
height: 600,
width: 800,
webPreferences: {
webviewTag: true, // Enable <webview>
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
});

// and load the index.html of the app.
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);

// Open the DevTools.
mainWindow.webContents.openDevTools();
// Main window events:
mainWindow.once('ready-to-show', () => {
mainWindow.maximize();
mainWindow.show();
});

mainWindow.webContents.on(
'will-attach-webview',
(evt, webPreferences, params) => {
// TODO strip away preload script for security?
// See docs on `webviewTag`: https://www.electronjs.org/docs/latest/api/browser-window
}
);

if (isDev) {
// Open the DevTools.
mainWindow.webContents.openDevTools({
mode: 'detach',
});
}
};

// This method will be called when Electron has finished
Expand Down
Loading

0 comments on commit 836d89a

Please sign in to comment.