Created
June 3, 2024 18:01
-
-
Save absidue/8124af98e9971c17b1455cc6c38aab3d to your computer and use it in GitHub Desktop.
Electron forgetting Web File System API directory test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'unsafe-inline'"> | |
<title>Hello World!</title> | |
<style> | |
body { | |
font-family: sans-serif !important | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Forgetful file picker</h1> | |
<p>The first time you use the picker it should open to the downloads directory, the second time it should remember the directory that you selected the previous file in (e.g. the desktop), however Electron will show the downloads directory again instead. | |
<br> | |
https://developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker#id | |
</p> | |
<button id="picker-button">Click to select a file</button> | |
<script src="./renderer.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { app, BrowserWindow } = require('electron') | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600 | |
}) | |
mainWindow.loadFile('index.html') | |
} | |
app.whenReady().then(() => { | |
createWindow() | |
app.on('activate', function () { | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "stingy-orange-examine-3hwma", | |
"productName": "stingy-orange-examine-3hwma", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "absidue", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "30.0.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById('picker-button').addEventListener('click', () => { | |
window.showOpenFilePicker({ | |
multiple: false, | |
id: 'remember-directory-id', | |
startIn: 'downloads', | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment