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

Update afterSign.js #310

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
60 changes: 38 additions & 22 deletions app/build_hooks/afterSign.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
/* ///////////////////////////////
// Notarization
// See https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
// /////////////////////////////*/
require( 'dotenv' ).config()
const { notarize } = require( '@electron/notarize' )
const log = ( ...messages ) => console.log( ...messages )
// Import required modules
require('dotenv').config();
const { notarize } = require('@electron/notarize');

exports.default = async function notarizing( context ) {

log( '\n\n🪝 afterSign hook triggered: ' )
const { appOutDir } = context
const { APPLEID, APPLEIDPASS, TEAMID } = process.env
const appName = context.packager.appInfo.productFilename
// Logging function for better readability
const log = (...messages) => console.log(...messages);

return await notarize( {
appBundleId: 'co.palokaj.battery',
tool: "notarytool",
appPath: `${ appOutDir }/${ appName }.app`,
appleId: APPLEID,
appleIdPassword: APPLEIDPASS,
teamId: TEAMID
} )
}
exports.default = async function notarizing(context) {
log('\n\n🪝 afterSign hook triggered:');

// Destructure necessary properties from context and environment variables
const { appOutDir } = context;
const { APPLEID, APPLEIDPASS, TEAMID } = process.env;

// Ensure environment variables are set before proceeding
if (!APPLEID || !APPLEIDPASS || !TEAMID) {
log('Error: Missing environment variables. Please check APPLEID, APPLEIDPASS, and TEAMID.');
throw new Error('Notarization failed due to missing environment variables.');
}

// Retrieve the app name
const appName = context.packager.appInfo.productFilename;

try {
// Call notarize with the appropriate parameters
await notarize({
appBundleId: 'co.palokaj.battery',
tool: 'notarytool',
appPath: `${appOutDir}/${appName}.app`,
appleId: APPLEID,
appleIdPassword: APPLEIDPASS,
teamId: TEAMID,
});

log('✅ Notarization completed successfully.');
} catch (error) {
log('❌ Notarization failed:', error);
throw new Error('Notarization process encountered an error.');
}
};