From 6573cf524df7b4d3868a11196ae0cd75b6136187 Mon Sep 17 00:00:00 2001 From: dragonDScript Date: Sat, 4 Dec 2021 15:23:02 +0100 Subject: [PATCH 1/6] Remove settings for shortcuts and refactor addShortcuts function --- electron/config.ts | 2 -- electron/games.ts | 2 +- electron/legendary/games.ts | 12 ++++---- electron/main.ts | 16 +++++----- electron/types.ts | 2 -- .../components/OtherSettings/index.tsx | 29 ------------------- src/screens/Settings/index.tsx | 18 ------------ src/test_helpers/testTypes.ts | 2 -- src/types.ts | 2 -- 9 files changed, 13 insertions(+), 72 deletions(-) diff --git a/electron/config.ts b/electron/config.ts index 954f160270..7723e3bdd7 100644 --- a/electron/config.ts +++ b/electron/config.ts @@ -378,8 +378,6 @@ class GlobalConfigV0 extends GlobalConfig { return { checkUpdatesInterval: 10, enableUpdates: false, - addDesktopShortcuts: false, - addStartMenuShortcuts: false, autoInstallDxvk: false, checkForUpdatesOnStartup: true, customWinePaths: isWindows ? null : [], diff --git a/electron/games.ts b/electron/games.ts index c936416ee8..3c384a6f5b 100644 --- a/electron/games.ts +++ b/electron/games.ts @@ -20,7 +20,7 @@ abstract class Game { abstract hasUpdate() : Promise abstract import(path : string) : Promise abstract install(args: InstallArgs) : Promise<{status: string}> - abstract addShortcuts(): Promise + abstract addShortcuts({addToStartMenu, addToDesktop}: {addToStartMenu: boolean, addToDesktop: boolean}): Promise abstract launch(launchArguments?: string) : Promise abstract moveInstall(newInstallPath : string) : Promise abstract repair() : Promise diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index 902730beca..1e39342c60 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -275,11 +275,10 @@ class LegendaryGame extends Game { /** * Adds a desktop shortcut to $HOME/Desktop and to /usr/share/applications * so that the game can be opened from the start menu and the desktop folder. - * Both can be disabled with addDesktopShortcuts and addStartMenuShortcuts * @async * @public */ - public async addShortcuts(fromMenu?: boolean) { + public async addShortcuts({addToStartMenu, addToDesktop}: {addToStartMenu: boolean, addToDesktop: boolean}) { if (process.platform === 'darwin') { return } @@ -287,7 +286,6 @@ class LegendaryGame extends Game { const gameInfo = await this.getGameInfo() const launchWithProtocol = `heroic://launch/${gameInfo.app_name}` const [ desktopFile, menuFile ] = this.shortcutFiles(gameInfo.title) - const { addDesktopShortcuts, addStartMenuShortcuts } = await GlobalConfig.get().getSettings() switch (process.platform) { case 'linux': { @@ -302,12 +300,12 @@ Icon=${icon} Categories=Game; ` - if (addDesktopShortcuts || fromMenu) { + if (addToDesktop) { writeFile(desktopFile, shortcut, () => { logInfo('Shortcut saved on ' + desktopFile) }) } - if (addStartMenuShortcuts || fromMenu) { + if (addToStartMenu) { writeFile(menuFile, shortcut, () => { logInfo('Shortcut saved on ' + menuFile) }) @@ -321,11 +319,11 @@ Categories=Game; iconIndex: 0 } - if (addDesktopShortcuts || fromMenu) { + if (addToDesktop) { shell.writeShortcutLink(desktopFile, shortcutOptions) } - if (addStartMenuShortcuts || fromMenu) { + if (addToStartMenu) { shell.writeShortcutLink(menuFile, shortcutOptions) } break diff --git a/electron/main.ts b/electron/main.ts index 7a7e1f6929..bdee1d494d 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -683,8 +683,8 @@ ipcMain.handle('openDialog', async (e, args) => { }) const openMessageBox = async (args: Electron.MessageBoxOptions) => { - const { response } = await showMessageBox({ ...args }) - return { response } + const { response, checkboxChecked } = await showMessageBox({ ...args }) + return { response, checkboxChecked } } ipcMain.handle('openMessageBox', async (_, args: Electron.MessageBoxOptions) => { @@ -830,14 +830,12 @@ ipcMain.handle('egsSync', async (event, args) => { } }) -ipcMain.on('addShortcut', async (event, appName: string, fromMenu: boolean) => { +ipcMain.on('addShortcut', async (event, appName: string, { desktop, startMenu } : {desktop: boolean, startMenu: boolean}) => { const game = Game.get(appName) - game.addShortcuts(fromMenu) - openMessageBox({ - buttons: [i18next.t('box.ok', 'Ok')], - message: i18next.t('box.shortcuts.message', 'Shortcuts were created on Desktop and Start Menu'), - title: i18next.t('box.shortcuts.title', 'Shortcuts') - }) + const opts = { + addToDesktop: desktop, addToStartMenu: startMenu + } + game.addShortcuts(opts) }) ipcMain.on('removeShortcut', async (event, appName: string) => { diff --git a/electron/types.ts b/electron/types.ts index 7af160dee8..5dceec6b61 100644 --- a/electron/types.ts +++ b/electron/types.ts @@ -6,8 +6,6 @@ interface About { export interface AppSettings { checkUpdatesInterval: number, enableUpdates: boolean - addDesktopShortcuts: boolean - addStartMenuShortcuts: boolean altLegendaryBin: string audioFix: boolean autoInstallDxvk: boolean diff --git a/src/screens/Settings/components/OtherSettings/index.tsx b/src/screens/Settings/components/OtherSettings/index.tsx index 21294660ba..22dd9180af 100644 --- a/src/screens/Settings/components/OtherSettings/index.tsx +++ b/src/screens/Settings/components/OtherSettings/index.tsx @@ -22,8 +22,6 @@ interface Props { offlineMode: boolean otherOptions: string primeRun: boolean - addDesktopShortcuts: boolean - addGamesToStartMenu: boolean discordRPC: boolean setLauncherArgs: (value: string) => void setOtherOptions: (value: string) => void @@ -38,8 +36,6 @@ interface Props { toggleOffline: () => void togglePrimeRun: () => void toggleUseGameMode: () => void - toggleAddDesktopShortcuts: () => void - toggleAddGamesToStartMenu: () => void toggleDiscordRPC: () => void targetExe: string useGameMode: boolean @@ -64,10 +60,6 @@ export default function OtherSettings({ primeRun, togglePrimeRun, setMaxRecentGames, - addDesktopShortcuts, - addGamesToStartMenu, - toggleAddDesktopShortcuts, - toggleAddGamesToStartMenu, discordRPC, toggleDiscordRPC, maxRecentGames, @@ -82,7 +74,6 @@ export default function OtherSettings({ const { platform } = useContext(ContextProvider) const isWin = platform === 'win32' const isLinux = platform === 'linux' - const supportsShortcuts = isWin || isLinux return ( <> @@ -158,26 +149,6 @@ export default function OtherSettings({ - {supportsShortcuts && isDefault && <> - - - {t('setting.adddesktopshortcuts', 'Add desktop shortcuts automatically')} - - - - - - {t('setting.addgamestostartmenu', 'Add games to start menu automatically')} - - - - } {isDefault && {t('setting.discordRPC', 'Enable Discord Rich Presence')} diff --git a/src/screens/Settings/index.tsx b/src/screens/Settings/index.tsx index 766b196a6a..719cb5552d 100644 --- a/src/screens/Settings/index.tsx +++ b/src/screens/Settings/index.tsx @@ -77,16 +77,6 @@ function Settings() { ) const [customWinePaths, setCustomWinePaths] = useState([] as Array) const [savesPath, setSavesPath] = useState('') - const { - on: addDesktopShortcuts, - toggle: toggleAddDesktopShortcuts, - setOn: setAddDesktopShortcuts - } = useToggle(false) - const { - on: addStartMenuShortcuts, - toggle: toggleAddGamesToStartMenu, - setOn: setAddGamesToStartMenu - } = useToggle(false) const { on: useGameMode, toggle: toggleUseGameMode, @@ -214,8 +204,6 @@ function Settings() { setMaxWorkers(config.maxWorkers ?? 0) setMaxRecentGames(config.maxRecentGames ?? 5) setCustomWinePaths(config.customWinePaths || []) - setAddDesktopShortcuts(config.addDesktopShortcuts || false) - setAddGamesToStartMenu(config.addStartMenuShortcuts || false) setCustomWinePaths(config.customWinePaths || []) setCheckForUpdatesOnStartup(config.checkForUpdatesOnStartup || true) setTargetExe(config.targetExe || '') @@ -241,8 +229,6 @@ function Settings() { const GlobalSettings = { altLegendaryBin, - addDesktopShortcuts, - addStartMenuShortcuts, audioFix, autoInstallDxvk, checkForUpdatesOnStartup, @@ -409,10 +395,6 @@ function Settings() { isDefault={isDefault} maxRecentGames={maxRecentGames} setMaxRecentGames={setMaxRecentGames} - addDesktopShortcuts={addDesktopShortcuts} - addGamesToStartMenu={addStartMenuShortcuts} - toggleAddDesktopShortcuts={toggleAddDesktopShortcuts} - toggleAddGamesToStartMenu={toggleAddGamesToStartMenu} toggleDiscordRPC={toggleDiscordRPC} discordRPC={discordRPC} targetExe={targetExe} diff --git a/src/test_helpers/testTypes.ts b/src/test_helpers/testTypes.ts index be20f717d1..a2c7a5ea13 100644 --- a/src/test_helpers/testTypes.ts +++ b/src/test_helpers/testTypes.ts @@ -193,8 +193,6 @@ const test_plugin = new TestType({ */ const test_appsettings = new TestType({ altLegendaryBin: '', - addDesktopShortcuts: false, - addStartMenuShortcuts: false, audioFix: false, autoInstallDxvk: false, autoSyncSaves: false, diff --git a/src/types.ts b/src/types.ts index 19bf98aea8..508a3ad87f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,8 +4,6 @@ interface About { } export interface AppSettings { altLegendaryBin: string - addDesktopShortcuts: boolean - addStartMenuShortcuts: boolean audioFix: boolean autoInstallDxvk: boolean autoSyncSaves: boolean From 9faa8b95e8ca8a26712558173434ace11bc11691 Mon Sep 17 00:00:00 2001 From: dragonDScript Date: Sat, 4 Dec 2021 15:24:40 +0100 Subject: [PATCH 2/6] Add to desktop and start menu until I make the proper UI --- src/screens/Game/GameSubMenu/index.tsx | 2 +- src/state/GlobalState.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/Game/GameSubMenu/index.tsx b/src/screens/Game/GameSubMenu/index.tsx index 43ac4a56a8..679c54dc7e 100644 --- a/src/screens/Game/GameSubMenu/index.tsx +++ b/src/screens/Game/GameSubMenu/index.tsx @@ -105,7 +105,7 @@ export default function GamesSubmenu({ } function handleShortcuts() { - ipcRenderer.send('addShortcut', appName, true) + ipcRenderer.send('addShortcut', appName, { desktop: true, startMenu: true }) } useEffect(() => { diff --git a/src/state/GlobalState.tsx b/src/state/GlobalState.tsx index d171ad9025..79b3117dc2 100644 --- a/src/state/GlobalState.tsx +++ b/src/state/GlobalState.tsx @@ -216,7 +216,7 @@ export class GlobalState extends PureComponent { if (percent > 95) { notifyKey = 'finished' filter = 'installed' - ipcRenderer.send('addShortcut', appName, false) + ipcRenderer.send('addShortcut', appName, { desktop: true, startMenu: true }) } this.handleFilter(filter) From 4c0e210c792bb7c83871c690f79e8022539c66d1 Mon Sep 17 00:00:00 2001 From: dragonDScript Date: Sat, 4 Dec 2021 15:31:21 +0100 Subject: [PATCH 3/6] Sanitize title --- electron/legendary/games.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index 1e39342c60..e359ecc5c9 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -285,13 +285,23 @@ class LegendaryGame extends Game { const gameInfo = await this.getGameInfo() const launchWithProtocol = `heroic://launch/${gameInfo.app_name}` - const [ desktopFile, menuFile ] = this.shortcutFiles(gameInfo.title) + const sanitizedTitle = gameInfo.title + // TODO: use regexp + sanitizedTitle.replaceAll('/', ' ') + sanitizedTitle.replaceAll('\\', ' ') + sanitizedTitle.replaceAll(':', ' ') + sanitizedTitle.replaceAll('*', ' ') + sanitizedTitle.replaceAll('?', ' ') + sanitizedTitle.replaceAll('<', ' ') + sanitizedTitle.replaceAll('>', ' ') + sanitizedTitle.replaceAll('|', ' ') + const [ desktopFile, menuFile ] = this.shortcutFiles(sanitizedTitle) switch (process.platform) { case 'linux': { const icon = await this.getIcon(gameInfo.app_name) const shortcut = `[Desktop Entry] -Name=${gameInfo.title} +Name=${sanitizedTitle} Exec=xdg-open ${launchWithProtocol} Terminal=false Type=Application From 036daa023cebdb6910c283fc07df039cfb84522d Mon Sep 17 00:00:00 2001 From: dragonDScript Date: Sat, 4 Dec 2021 20:35:07 +0100 Subject: [PATCH 4/6] Use Regex --- electron/legendary/games.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index e23e57cfec..938b9366c4 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -286,15 +286,9 @@ class LegendaryGame extends Game { const gameInfo = await this.getGameInfo() const launchWithProtocol = `heroic://launch/${gameInfo.app_name}` const sanitizedTitle = gameInfo.title - // TODO: use regexp - sanitizedTitle.replaceAll('/', ' ') - sanitizedTitle.replaceAll('\\', ' ') - sanitizedTitle.replaceAll(':', ' ') - sanitizedTitle.replaceAll('*', ' ') - sanitizedTitle.replaceAll('?', ' ') - sanitizedTitle.replaceAll('<', ' ') - sanitizedTitle.replaceAll('>', ' ') - sanitizedTitle.replaceAll('|', ' ') + const pattern = new RegExp('[:|/|*|?|<|>||]') + sanitizedTitle.replaceAll(pattern, ' ') + const [ desktopFile, menuFile ] = this.shortcutFiles(sanitizedTitle) switch (process.platform) { From 27b82f86e331b1a12c6cff1b209a56072a5a401b Mon Sep 17 00:00:00 2001 From: dragonDScript Date: Sat, 4 Dec 2021 22:24:32 +0100 Subject: [PATCH 5/6] Replace with an empty string so it will be removed instead of adding a empty space on it --- electron/legendary/games.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index 938b9366c4..f947beb85b 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -287,7 +287,7 @@ class LegendaryGame extends Game { const launchWithProtocol = `heroic://launch/${gameInfo.app_name}` const sanitizedTitle = gameInfo.title const pattern = new RegExp('[:|/|*|?|<|>||]') - sanitizedTitle.replaceAll(pattern, ' ') + sanitizedTitle.replaceAll(pattern, '') const [ desktopFile, menuFile ] = this.shortcutFiles(sanitizedTitle) From d13abad2848871fc58d1e40c2d6209271b248323 Mon Sep 17 00:00:00 2001 From: dragonDScript <46191980+dragonDScript@users.noreply.github.com> Date: Sun, 5 Dec 2021 14:51:34 +0100 Subject: [PATCH 6/6] More restrictive pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Flávio F Lima --- electron/legendary/games.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index f947beb85b..77a8272517 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -286,7 +286,7 @@ class LegendaryGame extends Game { const gameInfo = await this.getGameInfo() const launchWithProtocol = `heroic://launch/${gameInfo.app_name}` const sanitizedTitle = gameInfo.title - const pattern = new RegExp('[:|/|*|?|<|>||]') + const pattern = new RegExp('[:|/|*|?|<|>|\\|&|{|}|%|$|@|`|!|+]') sanitizedTitle.replaceAll(pattern, '') const [ desktopFile, menuFile ] = this.shortcutFiles(sanitizedTitle)