Skip to content

Commit e3536c7

Browse files
authored
[Feat] - Improve compatibility layer initialization for Mac and Linux (#1214)
* [Feat] - Refactor compatibility layer initialization for Mac and Linux support - Updated `initializeCompatibilityLayer` to include Linux in the compatibility checks. - Renamed `setGPTKDefaultOnMacOS` to `setDefaultCompatibilityLayer` for broader applicability. - Enhanced wine version selection logic to accommodate Proton-GE for Linux and improved compatibility checks for MacOS. - Added early return conditions to streamline the process based on platform compatibility. This refactor improves the overall compatibility layer setup for both Mac and Linux environments. * [Refactor] Update WineManager settings and version fetching logic - Changed the default count for wine version info fetching from 50 to 15 to optimize performance. - Renamed Wine-GE settings to Proton-GE in the WineManager component for clarity and consistency. - Updated the state initialization to reflect the new Proton-GE settings. - Added a condition to refresh wine version info if no versions are available, enhancing user experience. * chore: comments * chore: simplify checks * chore: rosetta check --------- Co-authored-by: Flavio F Lima <flavioislima@users.noreply.github.com>
1 parent 95f7f58 commit e3536c7

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

src/backend/utils/compatibility_layers.ts

+31-19
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,11 @@ export async function initializeCompatibilityLayer() {
597597
initializationTasks.push(downloadDefaultWine())
598598
}
599599

600-
if (isMac) {
601-
initializationTasks.push(checkRosettaInstall())
602-
initializationTasks.push(setGPTKDefaultOnMacOS())
600+
if (isMac || isLinux) {
601+
if (isMac) {
602+
initializationTasks.push(checkRosettaInstall())
603+
}
604+
initializationTasks.push(setDefaultCompatibilityLayer())
603605
}
604606

605607
try {
@@ -616,21 +618,17 @@ export async function downloadDefaultWine() {
616618
if (isWindows) return null
617619

618620
try {
619-
// Refresh wine list
620621
await updateWineVersionInfos(true)
621622

622623
// Get list of available wine versions
623624
const availableWine = wineDownloaderInfoStore.get('wine-releases', [])
624625

625-
// use Wine-GE type if on Linux and GPTK or Wine-Crossover if on Mac
626+
// use Proton-GE type if on Linux and GPTK or Wine-Crossover if on Mac
626627
const isGPTKCompatible = isMac ? await isMacSonomaOrHigher() : false
627628
const results = await Promise.all(
628629
availableWine.map(async (version) => {
629630
if (isLinux) {
630-
return (
631-
version.type === 'Wine-GE' &&
632-
version.version.includes('Wine-GE-Proton')
633-
)
631+
return version.type === 'Proton-GE'
634632
}
635633

636634
if (isMac) {
@@ -705,32 +703,46 @@ export async function downloadDefaultWine() {
705703
}
706704
}
707705

708-
export async function setGPTKDefaultOnMacOS() {
709-
const isGPTKCompatible = await isMacSonomaOrHigher()
710-
if (!isGPTKCompatible) {
706+
export async function setDefaultCompatibilityLayer() {
707+
if (!isMac && !isLinux) {
711708
return
712709
}
713710

711+
// For MacOS, check GPTK compatibility
712+
if (isMac) {
713+
const isGPTKCompatible = await isMacSonomaOrHigher()
714+
if (!isGPTKCompatible) {
715+
return
716+
}
717+
}
718+
714719
const { wineVersion: defaultWine } = GlobalConfig.get().getSettings()
715720

716-
const ignoreList = ['crossover', 'toolkit']
721+
// Get target wine type and prefix name based on platform
722+
const targetType = isMac ? 'toolkit' : 'proton'
723+
const prefixName = isMac ? 'GPTK' : 'Proton'
717724

725+
// Early return if already using target type
726+
const ignoreList = ['crossover', 'toolkit', 'proton']
718727
if (
719728
ignoreList.includes(defaultWine.type.toLowerCase()) ||
720729
defaultWine.name.includes('Toolkit')
721730
) {
722731
return
723732
}
724733

734+
// Find target wine version
725735
const wineList = await GlobalConfig.get().getAlternativeWine()
726-
const gptk = wineList.find((wine) => wine.type === 'toolkit')
736+
const targetWine = wineList.find((wine) => wine.type === targetType)
737+
738+
// Set as default if found and valid
739+
if (targetWine && existsSync(targetWine.bin)) {
740+
logInfo(`Changing wine version to ${targetWine.name}`)
741+
GlobalConfig.get().setSetting('wineVersion', targetWine)
727742

728-
if (gptk && existsSync(gptk.bin)) {
729-
logInfo(`Changing wine version to ${gptk.name}`)
730-
GlobalConfig.get().setSetting('wineVersion', gptk)
731-
// update prefix to use the new one as well
743+
// Update prefix path
732744
const installPath = GlobalConfig.get().getSettings().defaultInstallPath
733-
const newPrefix = join(installPath, 'Prefixes', 'GPTK')
745+
const newPrefix = join(installPath, 'Prefixes', prefixName)
734746
GlobalConfig.get().setSetting('winePrefix', newPrefix)
735747
}
736748
return

src/backend/wine/manager/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const wineDownloaderInfoStore = new TypeCheckedStoreBackend(
2828

2929
async function updateWineVersionInfos(
3030
fetch = false,
31-
count = 50
31+
count = 15
3232
): Promise<WineVersionInfo[]> {
3333
if (isWindows) {
3434
return []

src/frontend/screens/WineManager/index.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export default React.memo(function WineManager(): JSX.Element | null {
2828
const { refreshWineVersionInfo, platform } = useContext(ContextProvider)
2929
const isLinux = platform === 'linux'
3030

31-
const winege: WineManagerUISettings = {
32-
type: 'Wine-GE',
33-
value: 'winege',
31+
const protonge: WineManagerUISettings = {
32+
type: 'Proton-GE',
33+
value: 'protonge',
3434
enabled: isLinux
3535
}
3636

@@ -41,13 +41,13 @@ export default React.memo(function WineManager(): JSX.Element | null {
4141
}
4242

4343
const [repository, setRepository] = useState<WineManagerUISettings>(
44-
isLinux ? winege : gamePortingToolkit
44+
isLinux ? protonge : gamePortingToolkit
4545
)
4646
const [wineManagerSettings, setWineManagerSettings] = useState<
4747
WineManagerUISettings[]
4848
>([
49-
{ type: 'Wine-GE', value: 'winege', enabled: isLinux },
5049
{ type: 'Proton-GE', value: 'protonge', enabled: isLinux },
50+
{ type: 'Wine-GE', value: 'winege', enabled: isLinux },
5151
{ type: 'Game-Porting-Toolkit', value: 'toolkit', enabled: !isLinux },
5252
{ type: 'Wine-Crossover', value: 'winecrossover', enabled: !isLinux }
5353
])
@@ -69,6 +69,10 @@ export default React.memo(function WineManager(): JSX.Element | null {
6969
// Track the screen view once
7070
useEffect(() => {
7171
window.api.trackScreen('Compatibility Layer ')
72+
73+
if (wineVersions.length === 0) {
74+
refreshWineVersionInfo(true)
75+
}
7276
}, [])
7377

7478
useEffect(() => {

0 commit comments

Comments
 (0)