Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] - Improve compatibility layer initialization for Mac and Linux #1214

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions src/backend/utils/compatibility_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,11 @@ export async function initializeCompatibilityLayer() {
initializationTasks.push(downloadDefaultWine())
}

if (isMac) {
initializationTasks.push(checkRosettaInstall())
initializationTasks.push(setGPTKDefaultOnMacOS())
if (isMac || isLinux) {
if (isMac) {
initializationTasks.push(checkRosettaInstall())
}
initializationTasks.push(setDefaultCompatibilityLayer())
}

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

try {
// Refresh wine list
await updateWineVersionInfos(true)

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

// use Wine-GE type if on Linux and GPTK or Wine-Crossover if on Mac
// use Proton-GE type if on Linux and GPTK or Wine-Crossover if on Mac
const isGPTKCompatible = isMac ? await isMacSonomaOrHigher() : false
const results = await Promise.all(
availableWine.map(async (version) => {
if (isLinux) {
return (
version.type === 'Wine-GE' &&
version.version.includes('Wine-GE-Proton')
)
return version.type === 'Proton-GE'
}

if (isMac) {
Expand Down Expand Up @@ -705,32 +703,46 @@ export async function downloadDefaultWine() {
}
}

export async function setGPTKDefaultOnMacOS() {
const isGPTKCompatible = await isMacSonomaOrHigher()
if (!isGPTKCompatible) {
export async function setDefaultCompatibilityLayer() {
if (!isMac && !isLinux) {
return
}

// For MacOS, check GPTK compatibility
if (isMac) {
const isGPTKCompatible = await isMacSonomaOrHigher()
if (!isGPTKCompatible) {
return
}
}

const { wineVersion: defaultWine } = GlobalConfig.get().getSettings()

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

// Early return if already using target type
const ignoreList = ['crossover', 'toolkit', 'proton']
if (
ignoreList.includes(defaultWine.type.toLowerCase()) ||
defaultWine.name.includes('Toolkit')
) {
return
}

// Find target wine version
const wineList = await GlobalConfig.get().getAlternativeWine()
const gptk = wineList.find((wine) => wine.type === 'toolkit')
const targetWine = wineList.find((wine) => wine.type === targetType)

// Set as default if found and valid
if (targetWine && existsSync(targetWine.bin)) {
logInfo(`Changing wine version to ${targetWine.name}`)
GlobalConfig.get().setSetting('wineVersion', targetWine)

if (gptk && existsSync(gptk.bin)) {
logInfo(`Changing wine version to ${gptk.name}`)
GlobalConfig.get().setSetting('wineVersion', gptk)
// update prefix to use the new one as well
// Update prefix path
const installPath = GlobalConfig.get().getSettings().defaultInstallPath
const newPrefix = join(installPath, 'Prefixes', 'GPTK')
const newPrefix = join(installPath, 'Prefixes', prefixName)
GlobalConfig.get().setSetting('winePrefix', newPrefix)
}
return
Expand Down
2 changes: 1 addition & 1 deletion src/backend/wine/manager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const wineDownloaderInfoStore = new TypeCheckedStoreBackend(

async function updateWineVersionInfos(
fetch = false,
count = 50
count = 15
): Promise<WineVersionInfo[]> {
if (isWindows) {
return []
Expand Down
14 changes: 9 additions & 5 deletions src/frontend/screens/WineManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default React.memo(function WineManager(): JSX.Element | null {
const { refreshWineVersionInfo, platform } = useContext(ContextProvider)
const isLinux = platform === 'linux'

const winege: WineManagerUISettings = {
type: 'Wine-GE',
value: 'winege',
const protonge: WineManagerUISettings = {
type: 'Proton-GE',
value: 'protonge',
enabled: isLinux
}

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

const [repository, setRepository] = useState<WineManagerUISettings>(
isLinux ? winege : gamePortingToolkit
isLinux ? protonge : gamePortingToolkit
)
const [wineManagerSettings, setWineManagerSettings] = useState<
WineManagerUISettings[]
>([
{ type: 'Wine-GE', value: 'winege', enabled: isLinux },
{ type: 'Proton-GE', value: 'protonge', enabled: isLinux },
{ type: 'Wine-GE', value: 'winege', enabled: isLinux },
{ type: 'Game-Porting-Toolkit', value: 'toolkit', enabled: !isLinux },
{ type: 'Wine-Crossover', value: 'winecrossover', enabled: !isLinux }
])
Expand All @@ -69,6 +69,10 @@ export default React.memo(function WineManager(): JSX.Element | null {
// Track the screen view once
useEffect(() => {
window.api.trackScreen('Compatibility Layer ')

if (wineVersions.length === 0) {
refreshWineVersionInfo(true)
}
}, [])

useEffect(() => {
Expand Down
Loading