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 5a87e08014..77a8272517 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -275,25 +275,27 @@ 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 } 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() + const sanitizedTitle = gameInfo.title + const pattern = new RegExp('[:|/|*|?|<|>|\\|&|{|}|%|$|@|`|!|+]') + sanitizedTitle.replaceAll(pattern, '') + + 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 @@ -302,12 +304,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 +323,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 609af003f6..c820a99a8a 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -688,8 +688,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) => { @@ -835,14 +835,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/Game/GameSubMenu/index.tsx b/src/screens/Game/GameSubMenu/index.tsx index 449f75b671..35cbe5b286 100644 --- a/src/screens/Game/GameSubMenu/index.tsx +++ b/src/screens/Game/GameSubMenu/index.tsx @@ -95,7 +95,7 @@ export default function GamesSubmenu({ appName, isInstalled, title }: Props) { } function handleShortcuts() { - ipcRenderer.send('addShortcut', appName, true) + ipcRenderer.send('addShortcut', appName, { desktop: true, startMenu: true }) } useEffect(() => { 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 caaccd4ffe..8e7c4038ff 100644 --- a/src/screens/Settings/index.tsx +++ b/src/screens/Settings/index.tsx @@ -74,16 +74,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, @@ -211,8 +201,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 || '') @@ -238,8 +226,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/state/GlobalState.tsx b/src/state/GlobalState.tsx index 89b492ca51..e63af92f44 100644 --- a/src/state/GlobalState.tsx +++ b/src/state/GlobalState.tsx @@ -237,7 +237,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) diff --git a/src/test_helpers/testTypes.ts b/src/test_helpers/testTypes.ts index 07db8d859a..82af1b9b46 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 6f063a2df2..7d322e15a2 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