fix auto grant

This commit is contained in:
pompurin404 2024-09-21 16:24:01 +08:00
parent ca42519e85
commit cc434a644a
No known key found for this signature in database

View File

@ -226,27 +226,22 @@ export async function autoGrantCorePermition(corePath: string): Promise<void> {
const { encryptedPassword } = await getAppConfig() const { encryptedPassword } = await getAppConfig()
const execPromise = promisify(exec) const execPromise = promisify(exec)
if (encryptedPassword && isEncryptionAvailable()) { if (encryptedPassword && isEncryptionAvailable()) {
try {
const password = safeStorage.decryptString(Buffer.from(encryptedPassword)) const password = safeStorage.decryptString(Buffer.from(encryptedPassword))
if (process.platform === 'linux') { if (process.platform === 'linux') {
try {
await execPromise(`echo "${password}" | sudo -S chown root:root "${corePath}"`) await execPromise(`echo "${password}" | sudo -S chown root:root "${corePath}"`)
await execPromise(`echo "${password}" | sudo -S chmod +sx "${corePath}"`) await execPromise(`echo "${password}" | sudo -S chmod +sx "${corePath}"`)
} catch (error) {
patchAppConfig({ encryptedPassword: undefined })
throw error
}
} }
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
try {
await execPromise(`echo "${password}" | sudo -S chown root:admin "${corePath}"`) await execPromise(`echo "${password}" | sudo -S chown root:admin "${corePath}"`)
await execPromise(`echo "${password}" | sudo -S chmod +sx "${corePath}"`) await execPromise(`echo "${password}" | sudo -S chmod +sx "${corePath}"`)
}
} catch (error) { } catch (error) {
patchAppConfig({ encryptedPassword: undefined }) patchAppConfig({ encryptedPassword: undefined })
throw error throw error
} }
} }
} }
}
export async function manualGrantCorePermition(password?: string): Promise<void> { export async function manualGrantCorePermition(password?: string): Promise<void> {
const { core = 'mihomo' } = await getAppConfig() const { core = 'mihomo' } = await getAppConfig()