Commit d54f349e authored by nanahira's avatar nanahira

test rosetta

parent 4cd077c0
Pipeline #15019 failed with stages
in 10 minutes and 32 seconds
......@@ -4,6 +4,7 @@ import * as ini from 'ini';
import * as fs from 'fs';
import * as child_process from 'child_process';
import * as Mustache from 'mustache';
import { checkRosetta } from './utility/arch';
export enum Category {
game,
......@@ -342,7 +343,6 @@ export class App {
}
async spawnApp(children: App[], action_name = 'main', argsTemplate?: any) {
if (this.id === 'th123') {
let th105 = <App>this.references.get('th105');
if (th105.isInstalled()) {
......@@ -357,9 +357,14 @@ export class App {
}
const appCwd = (<AppLocal>this.local).path;
const {execute, args, env, cwd} = await this.getSpawnAction(children, action_name, null, null, null, argsTemplate);
const spawnAction = await this.getSpawnAction(children, action_name, null, null, null, argsTemplate);
if (await checkRosetta()) {
spawnAction.args = ['-arch', 'arm64', spawnAction.execute].concat(spawnAction.args);
spawnAction.execute = 'arch';
}
const { execute, args, env, cwd } = spawnAction;
console.log(execute, args, env, cwd, appCwd);
return child_process.spawn(execute, args, {env: env, cwd: cwd || appCwd});
return child_process.spawn(execute, args, { env, cwd: cwd || appCwd });
}
get isYGOPro(): boolean {
......
import {ApplicationRef, EventEmitter, Injectable, NgZone} from '@angular/core';
import {Http} from '@angular/http';
import * as child_process from 'child_process';
import {ChildProcess} from 'child_process';
import { ChildProcess, execFile, execFileSync } from 'child_process';
import * as crypto from 'crypto';
import {remote} from 'electron';
import * as sudo from 'electron-sudo';
......@@ -19,8 +19,8 @@ import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices';
import {ComparableSet} from './shared/ComparableSet';
import {AppsJson} from './apps-json-type';
import * as os from 'os';
import Timer = NodeJS.Timer;
import { getArch } from './utility/arch';
const Logger = {
info: (...message: any[]) => {
......@@ -657,7 +657,7 @@ export class AppsService {
if (!['zh-CN', 'en-US', 'ja-JP'].includes(locale)) {
locale = 'en-US';
}
let updateUrl = App.updateUrl(app, process.platform, locale, os.arch());
let updateUrl = App.updateUrl(app, process.platform, locale, await getArch());
let metalink = await this.http.post(updateUrl, changedFiles).map((response) => response.text()).toPromise();
let downloadDir = path.join(path.dirname(app.local!.path), 'downloading');
let downloadId = await this.downloadService.addMetalink(metalink, downloadDir);
......@@ -715,7 +715,7 @@ export class AppsService {
if (!['zh-CN', 'en-US', 'ja-JP'].includes(locale)) {
locale = 'en-US';
}
let metalinkUrl = App.downloadUrl(_app, process.platform, locale, os.arch());
let metalinkUrl = App.downloadUrl(_app, process.platform, locale, await getArch());
_app.status.status = 'downloading';
let metalink = await this.http.get(metalinkUrl).map((response) => response.text()).toPromise();
let downloadId = await this.downloadService.addMetalink(metalink, dir);
......@@ -1123,7 +1123,7 @@ export class AppsService {
locale = 'en-US';
}
let checksumUrl = App.checksumUrl(app, process.platform, locale, os.arch());
let checksumUrl = App.checksumUrl(app, process.platform, locale, await getArch());
return this.http.get(checksumUrl)
.map((response) => {
let map = new Map<string, string>();
......
import { promisify } from 'util';
import { execFile } from 'child_process';
import * as os from 'os';
export async function checkRosetta() {
if (process.platform !== 'darwin') {
return false;
}
const execFileAsync = promisify(execFile);
const sysctlRosettaInfoKey = 'sysctl.proc_translated';
let isRosetta = false;
try {
console.log('Checking for macOS Rosetta environment');
const result = await execFileAsync('sysctl', [sysctlRosettaInfoKey], { encoding: 'utf8' });
isRosetta = result.stdout.includes(`${sysctlRosettaInfoKey}: 1`);
console.log(`Checked for macOS Rosetta environment (isRosetta=${isRosetta})`);
} catch (e) {
console.error(`sysctl shell command to check for macOS Rosetta environment failed: ${e}`);
}
return isRosetta;
}
export async function getArch() {
const execFileAsync = promisify(execFile);
const archFromOs = os.arch();
if (archFromOs !== 'x64' || process.platform !== 'darwin') {
// not mac or real x64
return archFromOs;
}
const isRosetta = await checkRosetta();
let isArm64Mac = false;
try {
console.log('Checking for arm64 in uname');
const result = await execFileAsync('uname', ['-a'], { encoding: 'utf8' });
const isArm = result.stdout.includes('ARM');
console.log(`Checked 'uname -a': arm64=${isArm}`);
isArm64Mac = isArm64Mac || isArm;
} catch (e) {
console.error(`uname shell command to check for arm64 failed: ${e}`);
}
isArm64Mac = isArm64Mac || process.arch === 'arm64' || isRosetta;
return isArm64Mac ? 'arm64' : archFromOs;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment