Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Add more freedom on Mac with different version of Arduino #375

Merged
merged 2 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 20 additions & 4 deletions src/arduino/arduinoSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export class ArduinoSettings implements IArduinoSettings {

public get defaultExamplePath(): string {
if (os.platform() === "darwin") {
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/examples");
if (this._arduinoPath.match(/Arduino.*\.app/)){
Copy link
Contributor

@testforstephen testforstephen Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 Duplicate if logics.
Suggest to add a utility method resolveMacArduinoAppPath in src/common/util.ts. Then just need join "/Contents/xxx"

resolveMacArduinoAppPath(arduinoPath: string): string {
if (/Arduino.*\.app/.test(arduinoPath)) {
return arduinoPath;
} else {
return path.join(arduinoPath, "Arduino.app");
}
}

return path.join(this._arduinoPath, "/Contents/Java/examples");
}else{
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/examples");
}
} else {
return path.join(this._arduinoPath, "examples");
}
Expand All @@ -68,15 +72,23 @@ export class ArduinoSettings implements IArduinoSettings {

public get defaultPackagePath(): string {
if (os.platform() === "darwin") {
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/hardware");
if (this._arduinoPath.match(/Arduino.*\.app/)){
return path.join(this._arduinoPath, "/Contents/Java/hardware");
}else{
return path.join(this._arduinoPath, "Arduino.app/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");
if (this._arduinoPath.match(/Arduino.*\.app/)){
return path.join(this._arduinoPath, "/Contents/Java/libraries");
}else{
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/libraries");
}
} else { // linux and win32
return path.join(this._arduinoPath, "libraries");
}
Expand All @@ -85,7 +97,11 @@ 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"));
if (this._arduinoPath.match(/Arduino.*\.app/)){
return path.join(this._arduinoPath, path.normalize("/Contents/MacOS/Arduino"));
}else{
return path.join(this._arduinoPath, path.normalize("Arduino.app/Contents/MacOS/Arduino"));
}
} else if (platform === "linux") {
return path.join(this._arduinoPath, "arduino");
} else if (platform === "win32") {
Expand Down
6 changes: 5 additions & 1 deletion src/common/sys/darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export function resolveArduinoPath(): string {
}

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

export function findFile(fileName: string, cwd: string): string {
Expand Down