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

Commit 405d5bd

Browse files
Merge pull request #375 from DeqingSun/edit_Mac_Path
Add more freedom on Mac with different version of Arduino
2 parents b5f1c2e + 0c977e4 commit 405d5bd

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/arduino/arduinoSettings.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ArduinoSettings implements IArduinoSettings {
5656

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

6969
public get defaultPackagePath(): string {
7070
if (os.platform() === "darwin") {
71-
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/hardware");
71+
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/hardware");
7272
} else { // linux and win32.
7373
return path.join(this._arduinoPath, "hardware");
7474
}
7575
}
7676

7777
public get defaultLibPath(): string {
7878
if (os.platform() === "darwin") {
79-
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/libraries");
79+
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/libraries");
8080
} else { // linux and win32
8181
return path.join(this._arduinoPath, "libraries");
8282
}
@@ -85,7 +85,7 @@ export class ArduinoSettings implements IArduinoSettings {
8585
public get commandPath(): string {
8686
const platform = os.platform();
8787
if (platform === "darwin") {
88-
return path.join(this._arduinoPath, path.normalize("Arduino.app/Contents/MacOS/Arduino"));
88+
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), path.normalize("/Contents/MacOS/Arduino"));
8989
} else if (platform === "linux") {
9090
return path.join(this._arduinoPath, "arduino");
9191
} else if (platform === "win32") {

src/common/sys/darwin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as childProcess from "child_process";
55
import * as path from "path";
6-
import { directoryExistsSync, fileExistsSync } from "../util";
6+
import { directoryExistsSync, fileExistsSync, resolveMacArduinoAppPath } from "../util";
77

88
export function resolveArduinoPath(): string {
99
let result;
@@ -19,7 +19,7 @@ export function resolveArduinoPath(): string {
1919
}
2020

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

2525
export function findFile(fileName: string, cwd: string): string {

src/common/util.ts

+13
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,16 @@ export function getRegistryValues(hive: string, key: string, name: string): Prom
388388
export function convertToHex(number, width = 0) {
389389
return padStart(number.toString(16), width, "0");
390390
}
391+
392+
/**
393+
* This will accept any Arduino*.app on Mac OS,
394+
* in case you named Arduino with a version number
395+
* @argument {string} arduinoPath
396+
*/
397+
export function resolveMacArduinoAppPath(arduinoPath: string): string {
398+
if (/Arduino.*\.app/.test(arduinoPath)) {
399+
return arduinoPath;
400+
} else {
401+
return path.join(arduinoPath, "Arduino.app");
402+
}
403+
}

0 commit comments

Comments
 (0)