Skip to content

Commit

Permalink
Merge pull request #102 from felixrieseberg/allow-autlaunch-aguments
Browse files Browse the repository at this point in the history
feat: add autolaunch args
  • Loading branch information
bitdisaster committed Nov 23, 2020
2 parents a05e4d7 + 767b320 commit 08ca4e4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 26 deletions.
14 changes: 14 additions & 0 deletions __tests__/creator-spec.ts
Expand Up @@ -515,9 +515,23 @@ describe('auto-launch', () => {
});

testIncludes('RegistryRunKey', '<RegistryKey Root="HKMU" Key="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" ForceCreateOnInstall="no" ForceDeleteOnUninstall="no"');
testIncludes('RegistryRunKeyValue', '<RegistryValue Name="com.squirrel.Acme.acme" Type="string" Value="&quot;[APPLICATIONROOTDIRECTORY]acme.exe&quot;" KeyPath="yes"/>');
testIncludes('RegistryRunKey component', '<Component Id="RegistryRunKey"');
testIncludes('RegistryRunKey component-ref', '<ComponentRef Id="RegistryRunKey" />');
regexTestIncludes('AutoLaunch feature', /<Feature Id="AutoLaunch" Title="Launch On Login" Level="2" .*>/);

test('MSICreator includes Auto-Updater feature with arguments', async () => {
const msiCreator = new MSICreator({
...defaultOptions,
features: {autoUpdate: false, autoLaunch: {enabled: true, arguments: ['arg1', 'arg2'] } }});
const { wxsFile } = await msiCreator.create();
wxsContent = await fs.readFile(wxsFile, 'utf-8');
console.log(wxsContent);
expect(wxsFile).toBeTruthy();
});

testIncludes('RegistryRunKey', '<RegistryValue Name="com.squirrel.Acme.acme" Type="string" Value="&quot;[APPLICATIONROOTDIRECTORY]acme.exe&quot; arg1 arg2" KeyPath="yes"/>');

});

describe('perUser install by default', () => {
Expand Down
46 changes: 27 additions & 19 deletions e2e/src/e2e-auto-launch.ts
Expand Up @@ -9,10 +9,6 @@ import { checkInstall, getInstallPaths, install, uninstall, uninstallViaPowershe
import { createMsiPackage, defaultMsiOptions, HARNESS_APP_DIR, OUT_DIR } from './utils/msi-packager';
import { getRegistryKeyValue } from './utils/registry';

interface TestConfig {
arch: 'x86' | 'x64';
}

const msiPath = path.join(OUT_DIR, 'HelloWix.msi');
const autoLaunchMsiOptions = {
...defaultMsiOptions,
Expand All @@ -34,18 +30,24 @@ describe('MSI auto-launch', () => {
fs.rmdirSync(getInstallPaths({ ...defaultMsiOptions, arch: 'x64'}).appRootFolder, { recursive: true });
});

const testConfigs: TestConfig[] = [
{arch: 'x86'},
{arch: 'x64'},
const testConfigs = [
{ label: 'x86', config: { arch: 'x86', features: { autoUpdate: false, autoLaunch: true }}},
{ label: 'x64', config: { arch: 'x64', features: { autoUpdate: false, autoLaunch: true }}},
{ label: 'x64 with launch args', config: { arch: 'x64', features: {
autoUpdate: false, autoLaunch: {
enabled: true,
arguments: ['-arg1', '-arg2']
}
}}},
];

testConfigs.forEach((testConfig) => {
describe((`arch:${testConfig.arch}`), () => {
testConfigs.forEach((test) => {
describe((`arch:${test.label}`), () => {
const msiOptions = {
...autoLaunchMsiOptions,
...testConfig
...test.config
};
const msiPaths123beta = getInstallPaths(msiOptions);
const msiPaths123beta = getInstallPaths(msiOptions as any);

const entryPoints = [
{ name: 'stubExe', path: msiPaths123beta.stubExe },
Expand All @@ -54,33 +56,39 @@ describe('MSI auto-launch', () => {
{ name: 'auto-launch key', path: autoLaunchRegistryKeyValue },
];

it(`packages (${testConfig.arch})`, async () => {
await createMsiPackage(msiOptions);
it(`packages (${test.label})`, async () => {
await createMsiPackage(msiOptions as any);
});

it(`installs (${testConfig.arch})`, async () => {
it(`installs (${test.label})`, async () => {
await install(msiPath, 2);
const version = getWindowsCompliantVersion(msiOptions.version);
expect(await checkInstall(`${msiOptions.name} (Machine)`, msiOptions.version)).ok();
expect(await checkInstall(`${msiOptions.name} (Machine - MSI)`, version)).ok();
});

it(`has all files in program files (${testConfig.arch})`, () => {
it(`has all files in program files (${test.label})`, () => {
expect(fs.pathExistsSync(msiPaths123beta.stubExe)).ok();
expect(fs.pathExistsSync(msiPaths123beta.appFolder)).ok();
expectSameFolderContent(HARNESS_APP_DIR, msiPaths123beta.appFolder);
});

it(`has shortcuts (${testConfig.arch})`, () => {
it(`has shortcuts (${test.label})`, () => {
expect(fs.pathExistsSync(msiPaths123beta.startMenuShortcut)).ok();
expect(fs.pathExistsSync(msiPaths123beta.desktopShortcut)).ok();
});

it(`has auto-launch registry key (${testConfig.arch})`, async () => {
it(`has auto-launch registry key (${test.label})`, async () => {
autoLaunchRegistryKeyValue = await getRegistryKeyValue(msiPaths123beta.registryRunKey,
msiPaths123beta.appUserModelId);
entryPoints[3].path = autoLaunchRegistryKeyValue;
expect(autoLaunchRegistryKeyValue).to.be(msiPaths123beta.stubExe);
let args = '';
if (typeof test.config.features.autoLaunch === 'object'
&& test.config.features.autoLaunch !== null) {
args = test.config.features.autoLaunch.arguments ?
` ${test.config.features.autoLaunch.arguments.join(' ')}` : '';
}
expect(autoLaunchRegistryKeyValue).to.be(`"${msiPaths123beta.stubExe}"${args}`);
});

entryPoints.forEach(async (entryPoint) => {
Expand All @@ -92,7 +100,7 @@ describe('MSI auto-launch', () => {
});
});

it(`uninstalls (${testConfig.arch})`, async () => {
it(`uninstalls (${test.label})`, async () => {
await uninstall(msiPath);
expect(await checkInstall(`${msiOptions.name} (Machine)`)).not.ok();
expect(await checkInstall(`${msiOptions.name} (Machine - MSI)`)).not.ok();
Expand Down
4 changes: 2 additions & 2 deletions e2e/src/e2e-per-user.ts
Expand Up @@ -28,7 +28,7 @@ const autoLaunchMsiOptions = {
}
};

describe('MSI perUser install', () => {
describe.only('MSI perUser install', () => {
before(async () => {
if (await checkInstall(`${defaultMsiOptions.name} (Machine - MSI)`)) {
await uninstallViaPowershell(`${defaultMsiOptions.name} (Machine - MSI)`);
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('MSI perUser install', () => {
it(`has auto-launch registry key (${testConfig.arch})`, async () => {
autoLaunchRegistryKeyValue = await getRegistryKeyValue(msiPaths123beta.registryRunKey,
msiPaths123beta.appUserModelId);
expect(autoLaunchRegistryKeyValue).to.be(msiPaths123beta.stubExe);
expect(autoLaunchRegistryKeyValue).to.be(`"${msiPaths123beta.stubExe}"`);
entryPoints[3].path = autoLaunchRegistryKeyValue;
});

Expand Down
14 changes: 13 additions & 1 deletion e2e/src/utils/app-process.ts
@@ -1,13 +1,25 @@
import { split } from 'lodash';
import Shell from 'node-powershell';

export const launch = async (path: string) => {
let quotedPath = /^.*"$/.test(path) ? path : `"${path}"`;
const commandArr = path.split('"');
let args = '';
if (commandArr.length > 2) {
quotedPath = `"${commandArr[1]}"`;
const psArgArray = commandArr
.splice(2, commandArr.length)
.join()
.trim();
args = psArgArray.length > 0 ? `-ArgumentList "${psArgArray}"` : '';
}
const ps = new Shell({
executionPolicy: 'Bypass',
noProfile: true
});

try {
ps.addCommand(`try { Start-Process "${path}" -ErrorAction Stop } catch {}`);
ps.addCommand(`try { Start-Process ${quotedPath} ${args} -ErrorAction Stop } catch {}`);
await ps.invoke();
} finally {
ps.dispose();
Expand Down
5 changes: 4 additions & 1 deletion harness/harness.js
Expand Up @@ -27,7 +27,10 @@ async function harness() {
upgradeCode: '90E8ABD6-B284-4495-81F7-4913E25A6FA3',
features: {
autoUpdate: true,
autoLaunch: true,
autoLaunch: {
enabled: true,
arguments: ['arg1', 'arg2']
},
},
});

Expand Down
21 changes: 18 additions & 3 deletions src/creator.ts
Expand Up @@ -73,9 +73,14 @@ export interface UIImages {
upIcon?: string; // WixUIUpIco
}

export interface AutoLaunchOptions {
enabled: boolean;
arguments: Array<string>;
}

export interface Features {
autoUpdate: boolean;
autoLaunch: boolean;
autoLaunch: boolean | AutoLaunchOptions;
}

export class MSICreator {
Expand Down Expand Up @@ -120,6 +125,7 @@ export class MSICreator {
public arch: 'x64' | 'ia64'| 'x86' = 'x86';
public autoUpdate: boolean;
public autoLaunch: boolean;
public autoLaunchArgs: Array<string>;
public defaultInstallMode: 'perUser' | 'perMachine';
public productCode: string;

Expand Down Expand Up @@ -163,9 +169,15 @@ export class MSICreator {
this.ui = options.ui !== undefined ? options.ui : false;
this.autoUpdate = false;
this.autoLaunch = false;
this.autoLaunchArgs = [];
if (typeof options.features === 'object' && options.features !== null) {
this.autoUpdate = options.features.autoUpdate;
this.autoLaunch = options.features.autoLaunch;
if (typeof options.features.autoLaunch === 'object' && options.features.autoLaunch !== null) {
this.autoLaunch = options.features.autoLaunch.enabled;
this.autoLaunchArgs = options.features.autoLaunch.arguments;
} else {
this.autoLaunch = options.features.autoLaunch;
}
}
}

Expand Down Expand Up @@ -732,13 +744,16 @@ export class MSICreator {
}

if (this.autoLaunch) {
const args = this.autoLaunchArgs.length > 0 ?
` ${this.autoLaunchArgs.join(' ')}`.replace(/"/gi, '&quot;') : '';

registry.push({
id: 'RegistryRunKey',
root: 'HKMU',
name: '{{AppUserModelId}}',
key: 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run',
type: 'string',
value: '[APPLICATIONROOTDIRECTORY]{{ApplicationBinary}}.exe',
value: `&quot;[APPLICATIONROOTDIRECTORY]{{ApplicationBinary}}.exe&quot;${args}`,
featureAffinity: 'autoLaunch',
forceDeleteOnUninstall: 'no'
});
Expand Down

0 comments on commit 08ca4e4

Please sign in to comment.