Skip to content

Commit

Permalink
aftersign
Browse files Browse the repository at this point in the history
  • Loading branch information
bunsenstraat committed Sep 13, 2024
1 parent c8e7d14 commit eb72d52
Showing 1 changed file with 66 additions and 65 deletions.
131 changes: 66 additions & 65 deletions apps/remixdesktop/aftersign.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,93 +11,94 @@ if (process.env.DO_NOT_NOTARIZE) {
exports.default = async function notarizing(context) {
return []
}
}
} else {

exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context // Provided by electron-builder
exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context // Provided by electron-builder

console.log('NOTARIZING')
console.log('NOTARIZING')

if (electronPlatformName !== 'darwin' || !process.env.CIRCLE_BRANCH) {
return
}
if (electronPlatformName !== 'darwin' || !process.env.CIRCLE_BRANCH) {
return
}

const appName = context.packager.appInfo.productFilename
const appPath = `${appOutDir}/${appName}.app`

// Function to promisify the exec command
function execShellCommand(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(new Error(`Error: ${error.message}`));
return;
}
if (stderr) {
reject(new Error(`Stderr: ${stderr}`));
return;
}
console.log(`stdout: ${stdout}`);
resolve(stdout);
const appName = context.packager.appInfo.productFilename
const appPath = `${appOutDir}/${appName}.app`

// Function to promisify the exec command
function execShellCommand(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(new Error(`Error: ${error.message}`));
return;
}
if (stderr) {
reject(new Error(`Stderr: ${stderr}`));
return;
}
console.log(`stdout: ${stdout}`);
resolve(stdout);
});
});
});
}

// Function to check if the app is stapled
// Async function to check the stapling status
async function checkStapleStatus() {
try {
console.log(`xcrun stapler validate "${appPath}"`)
await execShellCommand(`xcrun stapler validate "${appPath}"`);
console.log('App is already stapled. No action needed.');
return true
} catch (error) {
console.log(`App is not stapled: ${error.message}`);
return false
}
}

// Function to check if the app is stapled
// Async function to check the stapling status
async function checkStapleStatus() {
try {
console.log(`xcrun stapler validate "${appPath}"`)
await execShellCommand(`xcrun stapler validate "${appPath}"`);
console.log('App is already stapled. No action needed.');
return true
} catch (error) {
console.log(`App is not stapled: ${error.message}`);
return false
}
}



async function runNotarize() {

console.log('NOTARIZING + ', `xcrun stapler staple "${appPath}"`)
console.log({
appBundleId: 'org.ethereum.remix-ide', // Your app's bundle ID
appPath: `${appOutDir}/${appName}.app`, // Path to your .app
appleId: process.env.APPLE_ID, // Your Apple ID
appleIdPassword: process.env.APPLE_ID_PASSWORD, // App-specific password
teamId: process.env.APPLE_TEAM_ID, // Your Apple Developer team ID (optional)
})
async function runNotarize() {

try {
const r = await notarize({
console.log('NOTARIZING + ', `xcrun stapler staple "${appPath}"`)
console.log({
appBundleId: 'org.ethereum.remix-ide', // Your app's bundle ID
appPath: `${appOutDir}/${appName}.app`, // Path to your .app
appleId: process.env.APPLE_ID, // Your Apple ID
appleIdPassword: process.env.APPLE_ID_PASSWORD, // App-specific password
teamId: process.env.APPLE_TEAM_ID, // Your Apple Developer team ID (optional)
})

console.log(r)
try {
const r = await notarize({
appBundleId: 'org.ethereum.remix-ide', // Your app's bundle ID
appPath: `${appOutDir}/${appName}.app`, // Path to your .app
appleId: process.env.APPLE_ID, // Your Apple ID
appleIdPassword: process.env.APPLE_ID_PASSWORD, // App-specific password
teamId: process.env.APPLE_TEAM_ID, // Your Apple Developer team ID (optional)
})

// Stapling the app
console.log('STAPLING', `xcrun stapler staple "${appPath}"`)
console.log(r)

await execShellCommand(`xcrun stapler staple "${appPath}"`)
// Stapling the app
console.log('STAPLING', `xcrun stapler staple "${appPath}"`)

} catch (error) {
console.error('Error during notarization:', error)
throw new Error('Error during notarization', error)
}
await execShellCommand(`xcrun stapler staple "${appPath}"`)

}
} catch (error) {
console.error('Error during notarization:', error)
throw new Error('Error during notarization', error)
}

if(!await checkStapleStatus()){
await runNotarize()
await checkStapleStatus()
}else{
return []
}

if (!await checkStapleStatus()) {
await runNotarize()
await checkStapleStatus()
} else {
return []
}
}
}
}

0 comments on commit eb72d52

Please sign in to comment.