Skip to content

Commit

Permalink
Merge pull request #375 from DeqingSun/edit_Mac_Path
Browse files Browse the repository at this point in the history
Add more freedom on Mac with different version of Arduino
  • Loading branch information
testforstephen committed Jul 19, 2017
2 parents b5f1c2e + 0c977e4 commit 405d5bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/arduino/arduinoSettings.ts
Expand Up @@ -56,7 +56,7 @@ export class ArduinoSettings implements IArduinoSettings {

public get defaultExamplePath(): string {
if (os.platform() === "darwin") {
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/examples");
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/examples");
} else {
return path.join(this._arduinoPath, "examples");
}
Expand All @@ -68,15 +68,15 @@ export class ArduinoSettings implements IArduinoSettings {

public get defaultPackagePath(): string {
if (os.platform() === "darwin") {
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/hardware");
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/hardware");
} else { // linux and win32.
return path.join(this._arduinoPath, "hardware");
}
}

public get defaultLibPath(): string {
if (os.platform() === "darwin") {
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/libraries");
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/libraries");
} else { // linux and win32
return path.join(this._arduinoPath, "libraries");
}
Expand All @@ -85,7 +85,7 @@ export class ArduinoSettings implements IArduinoSettings {
public get commandPath(): string {
const platform = os.platform();
if (platform === "darwin") {
return path.join(this._arduinoPath, path.normalize("Arduino.app/Contents/MacOS/Arduino"));
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), path.normalize("/Contents/MacOS/Arduino"));
} else if (platform === "linux") {
return path.join(this._arduinoPath, "arduino");
} else if (platform === "win32") {
Expand Down
4 changes: 2 additions & 2 deletions src/common/sys/darwin.ts
Expand Up @@ -3,7 +3,7 @@

import * as childProcess from "child_process";
import * as path from "path";
import { directoryExistsSync, fileExistsSync } from "../util";
import { directoryExistsSync, fileExistsSync, resolveMacArduinoAppPath } from "../util";

export function resolveArduinoPath(): string {
let result;
Expand All @@ -19,7 +19,7 @@ export function resolveArduinoPath(): string {
}

export function validateArduinoPath(arduinoPath: string): boolean {
return fileExistsSync(path.join(arduinoPath, "Arduino.app/Contents/MacOS/Arduino"));
return fileExistsSync(path.join(resolveMacArduinoAppPath(arduinoPath), "/Contents/MacOS/Arduino"));
}

export function findFile(fileName: string, cwd: string): string {
Expand Down
13 changes: 13 additions & 0 deletions src/common/util.ts
Expand Up @@ -388,3 +388,16 @@ export function getRegistryValues(hive: string, key: string, name: string): Prom
export function convertToHex(number, width = 0) {
return padStart(number.toString(16), width, "0");
}

/**
* This will accept any Arduino*.app on Mac OS,
* in case you named Arduino with a version number
* @argument {string} arduinoPath
*/
export function resolveMacArduinoAppPath(arduinoPath: string): string {
if (/Arduino.*\.app/.test(arduinoPath)) {
return arduinoPath;
} else {
return path.join(arduinoPath, "Arduino.app");
}
}

0 comments on commit 405d5bd

Please sign in to comment.