Electron 9, Fixed breaking changes from 7 and 8.

Fixed file selectors not behaving properly due to breaking change in Electron 7 (#67).
Renamed shell.openItem to shell.openPath (Electron 9 breaking change).

Resolves #67.
This commit is contained in:
Daniel Scalzi 2020-05-21 21:02:58 -04:00
parent b1abe07aeb
commit 8726638a23
No known key found for this signature in database
GPG Key ID: D18EA3FB4B142A57
6 changed files with 46 additions and 38 deletions

View File

@ -1233,34 +1233,26 @@ input:checked + .toggleSwitchSlider:before {
height: 30px; height: 30px;
} }
/* File input for file selection. */ /* File selection button. */
.settingsFileSelSel { .settingsFileSelButton {
width: 0px; border: 0px;
height: 0px;
opacity: 0;
}
.settingsFileSelSel::-webkit-file-upload-button {
display: none;
}
/* Wrapper label to add a custom style to the file input. */
.settingsFileSelLabel {
border-left: 0px;
border-radius: 0px 3px 3px 0px; border-radius: 0px 3px 3px 0px;
font-size: 12px; font-size: 12px;
padding: 0px 5px; padding: 0px 5px;
cursor: pointer; cursor: pointer;
display: flex;
align-items: center;
background: rgba(126, 126, 126, 0.57); background: rgba(126, 126, 126, 0.57);
transition: 0.25s ease; transition: 0.25s ease;
white-space: nowrap; white-space: nowrap;
outline: none;
} }
.settingsFileSelLabel:hover, .settingsFileSelButton:hover,
.settingsFileSelLabel:focus, .settingsFileSelButton:focus {
.settingsFileSelSel:focus ~ #settingsJavaExecLabel {
text-shadow: 0px 0px 20px white; text-shadow: 0px 0px 20px white;
} }
.settingsFileSelButton:active {
text-shadow: 0px 0px 20px rgba(255, 255, 255, 0.75);
color: rgba(255, 255, 255, 0.75);
}
/* Description for the file selector. */ /* Description for the file selector. */
.settingsFileSelDesc { .settingsFileSelDesc {

View File

@ -42,15 +42,34 @@ bindSettingsSelect()
function bindFileSelectors(){ function bindFileSelectors(){
for(let ele of document.getElementsByClassName('settingsFileSelSel')){ for(let ele of document.getElementsByClassName('settingsFileSelButton')){
if(ele.id === 'settingsJavaExecSel'){
ele.onchange = (e) => { ele.onclick = async e => {
ele.previousElementSibling.value = ele.files[0].path const isJavaExecSel = ele.id === 'settingsJavaExecSel'
const directoryDialog = ele.hasAttribute('dialogDirectory') && ele.getAttribute('dialogDirectory') == 'true'
const properties = directoryDialog ? ['openDirectory', 'createDirectory'] : ['openFile']
const options = {
properties
}
if(ele.hasAttribute('dialogTitle')) {
options.title = ele.getAttribute('dialogTitle')
}
if(isJavaExecSel && process.platform === 'win32') {
options.filters = [
{ name: 'Executables', extensions: ['exe'] },
{ name: 'All Files', extensions: ['*'] }
]
}
const res = await remote.dialog.showOpenDialog(remote.getCurrentWindow(), options)
if(!res.canceled) {
ele.previousElementSibling.value = res.filePaths[0]
if(isJavaExecSel) {
populateJavaExecDetails(ele.previousElementSibling.value) populateJavaExecDetails(ele.previousElementSibling.value)
} }
} else {
ele.onchange = (e) => {
ele.previousElementSibling.value = ele.files[0].path
} }
} }
} }
@ -694,7 +713,7 @@ function bindDropinModFileSystemButton(){
const fsBtn = document.getElementById('settingsDropinFileSystemButton') const fsBtn = document.getElementById('settingsDropinFileSystemButton')
fsBtn.onclick = () => { fsBtn.onclick = () => {
DropinModUtil.validateDir(CACHE_SETTINGS_MODS_DIR) DropinModUtil.validateDir(CACHE_SETTINGS_MODS_DIR)
shell.openItem(CACHE_SETTINGS_MODS_DIR) shell.openPath(CACHE_SETTINGS_MODS_DIR)
} }
fsBtn.ondragenter = e => { fsBtn.ondragenter = e => {
e.dataTransfer.dropEffect = 'move' e.dataTransfer.dropEffect = 'move'
@ -818,7 +837,7 @@ function bindShaderpackButton() {
spBtn.onclick = () => { spBtn.onclick = () => {
const p = path.join(CACHE_SETTINGS_INSTANCE_DIR, 'shaderpacks') const p = path.join(CACHE_SETTINGS_INSTANCE_DIR, 'shaderpacks')
DropinModUtil.validateDir(p) DropinModUtil.validateDir(p)
shell.openItem(p) shell.openPath(p)
} }
spBtn.ondragenter = e => { spBtn.ondragenter = e => {
e.dataTransfer.dropEffect = 'move' e.dataTransfer.dropEffect = 'move'

View File

@ -203,8 +203,7 @@
</svg> </svg>
</div> </div>
<input class="settingsFileSelVal" id="settingsJavaExecVal" type="text" value="null" cValue="JavaExecutable" disabled> <input class="settingsFileSelVal" id="settingsJavaExecVal" type="text" value="null" cValue="JavaExecutable" disabled>
<input class="settingsFileSelSel" id="settingsJavaExecSel" type="file" <%= process.platform === 'win32' ? 'accept=.exe' : '' %>> <button class="settingsFileSelButton" id="settingsJavaExecSel" dialogTitle="Select Java Executable" dialogDirectory="false">Choose File</button>
<label class="settingsFileSelLabel" for="settingsJavaExecSel">Choose File</label>
</div> </div>
</div> </div>
<div class="settingsFileSelDesc">The Java executable is validated before game launch. <strong>Requires Java 8 x64.</strong><br>The path should end with <strong>bin<%= process.platform === 'win32' ? '\\javaw.exe' : '/java' %></strong>.</div> <div class="settingsFileSelDesc">The Java executable is validated before game launch. <strong>Requires Java 8 x64.</strong><br>The path should end with <strong>bin<%= process.platform === 'win32' ? '\\javaw.exe' : '/java' %></strong>.</div>
@ -262,8 +261,7 @@
</svg> </svg>
</div> </div>
<input class="settingsFileSelVal" type="text" value="null" cValue="DataDirectory" disabled> <input class="settingsFileSelVal" type="text" value="null" cValue="DataDirectory" disabled>
<input class="settingsFileSelSel" id="settingsDataDirSel" type="file" webkitdirectory> <button class="settingsFileSelButton" dialogTitle="Select Data Directory" dialogDirectory="true">Choose Folder</button>
<label class="settingsFileSelLabel" for="settingsDataDirSel">Choose Folder</label>
</div> </div>
</div> </div>
<div class="settingsFileSelDesc">All game files and local Java installations will be stored in the data directory.<br>Screenshots and world saves are stored in the instance folder for the corresponding server configuration.</div> <div class="settingsFileSelDesc">All game files and local Java installations will be stored in the data directory.<br>Screenshots and world saves are stored in the instance folder for the corresponding server configuration.</div>

View File

@ -1,6 +1,5 @@
// Requirements // Requirements
const {app, BrowserWindow, ipcMain} = require('electron') const { app, BrowserWindow, ipcMain, Menu } = require('electron')
const Menu = require('electron').Menu
const autoUpdater = require('electron-updater').autoUpdater const autoUpdater = require('electron-updater').autoUpdater
const ejse = require('ejs-electron') const ejse = require('ejs-electron')
const fs = require('fs') const fs = require('fs')

6
package-lock.json generated
View File

@ -953,9 +953,9 @@
} }
}, },
"electron": { "electron": {
"version": "8.3.0", "version": "9.0.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-8.3.0.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-9.0.0.tgz",
"integrity": "sha512-XRjiIJICZCgUr2vKSUI2PTkfP0gPFqCtqJUaTJSfCTuE3nTrxBKOUNeRMuCzEqspKkpFQU3SB3MdbMSHmZARlQ==", "integrity": "sha512-JsaSQNPh+XDYkLj8APtVKTtvpb86KIG57W5OOss4TNrn8L3isC9LsCITwfnVmGIXHhvX6oY/weCtN5hAAytjVg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@electron/get": "^1.0.1", "@electron/get": "^1.0.1",

View File

@ -41,7 +41,7 @@
}, },
"devDependencies": { "devDependencies": {
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"electron": "^8.3.0", "electron": "^9.0.0",
"electron-builder": "^22.6.1", "electron-builder": "^22.6.1",
"eslint": "^7.0.0" "eslint": "^7.0.0"
}, },