Skip to content

Commit

Permalink
Update to Electron 17, fix deleting drop-in mods from the settings view.
Browse files Browse the repository at this point in the history
  • Loading branch information
dscalzi committed Mar 4, 2022
1 parent ccf099a commit 15fc12b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 82 deletions.
15 changes: 9 additions & 6 deletions app/assets/js/dropinmodutil.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs-extra')
const path = require('path')
const { shell } = require('electron')
const { ipcRenderer, shell } = require('electron')
const { SHELL_OPCODE } = require('./ipcconstants')

// Group #1: File Name (without .disabled, if any)
// Group #2: File Extension (jar, zip, or litemod)
Expand Down Expand Up @@ -95,14 +96,16 @@ exports.addDropinMods = function(files, modsdir) {
* @returns {Promise.<boolean>} True if the mod was deleted, otherwise false.
*/
exports.deleteDropinMod = async function(modsDir, fullName){
try {
await shell.trashItem(path.join(modsDir, fullName))
return true
} catch(error) {

const res = await ipcRenderer.invoke(SHELL_OPCODE.TRASH_ITEM, path.join(modsDir, fullName))

if(!res.result) {
shell.beep()
console.error('Error deleting drop-in mod.', error)
console.error('Error deleting drop-in mod.', res.error)
return false
}

return true
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/assets/js/ipcconstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ exports.MSFT_ERROR = {
ALREADY_OPEN: 'MSFT_AUTH_ERR_ALREADY_OPEN',
NOT_FINISHED: 'MSFT_AUTH_ERR_NOT_FINISHED'
}

exports.SHELL_OPCODE = {
TRASH_ITEM: 'TRASH_ITEM'
}
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const remoteMain = require('@electron/remote/main')
remoteMain.initialize()

// Requirements
const { app, BrowserWindow, ipcMain, Menu } = require('electron')
const { app, BrowserWindow, ipcMain, Menu, shell } = require('electron')
const autoUpdater = require('electron-updater').autoUpdater
const ejse = require('ejs-electron')
const fs = require('fs')
const isDev = require('./app/assets/js/isdev')
const path = require('path')
const semver = require('semver')
const { pathToFileURL } = require('url')
const { AZURE_CLIENT_ID, MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR } = require('./app/assets/js/ipcconstants')
const { AZURE_CLIENT_ID, MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR, SHELL_OPCODE } = require('./app/assets/js/ipcconstants')

// Setup auto updater.
function initAutoUpdater(event, data) {
Expand Down Expand Up @@ -85,6 +85,21 @@ ipcMain.on('distributionIndexDone', (event, res) => {
event.sender.send('distributionIndexDone', res)
})

// Handle trash item.
ipcMain.handle(SHELL_OPCODE.TRASH_ITEM, async (event, ...args) => {
try {
await shell.trashItem(args[0])
return {
result: true
}
} catch(error) {
return {
result: false,
error: error
}
}
})

// Disable hardware acceleration.
// https://electronjs.org/docs/tutorial/offscreen-rendering
app.disableHardwareAcceleration()
Expand Down
140 changes: 70 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15fc12b

Please sign in to comment.