mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-10-12 12:58:33 +00:00
PROEDITOR-53: Changed the way we set the workspace
Got rid of the `sketch` search parameter from the URL. Rules: - Get the desired workspace location from the - `Path` defined as the `window.location.hash` of the URL, - most recent workspaces, - most recent sketches from the default sketch folder. - Validate the location. - If no valid location was found, create a new sketch in the default sketch folder. Note: when validating the location of the workspace root, the root must always exist. However, when in pro-mode, the desired workspace root must not be a sketch directory with the `.ino` file, but can be any existing location. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -16,7 +16,19 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
|
||||
async getSketches(uri?: string): Promise<Sketch[]> {
|
||||
const sketches: Array<Sketch & { mtimeMs: number }> = [];
|
||||
const fsPath = FileUri.fsPath(uri ? uri : (await this.configService.getConfiguration()).sketchDirUri);
|
||||
let fsPath: undefined | string;
|
||||
if (!uri) {
|
||||
const { sketchDirUri } = (await this.configService.getConfiguration());
|
||||
fsPath = FileUri.fsPath(sketchDirUri);
|
||||
if (!fs.existsSync(fsPath)) {
|
||||
fs.mkdirpSync(fsPath);
|
||||
}
|
||||
} else {
|
||||
fsPath = FileUri.fsPath(uri);
|
||||
}
|
||||
if (!fs.existsSync(fsPath)) {
|
||||
return [];
|
||||
}
|
||||
const fileNames = fs.readdirSync(fsPath);
|
||||
for (const fileName of fileNames) {
|
||||
const filePath = path.join(fsPath, fileName);
|
||||
@@ -56,12 +68,13 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
return this.getSketchFiles(FileUri.create(sketchDir).toString());
|
||||
}
|
||||
|
||||
async createNewSketch(parentUri: string): Promise<Sketch> {
|
||||
async createNewSketch(parentUri?: string): Promise<Sketch> {
|
||||
const monthNames = ['january', 'february', 'march', 'april', 'may', 'june',
|
||||
'july', 'august', 'september', 'october', 'november', 'december'
|
||||
];
|
||||
const today = new Date();
|
||||
const parent = FileUri.fsPath(parentUri);
|
||||
const uri = !!parentUri ? parentUri : (await this.configService.getConfiguration()).sketchDirUri;
|
||||
const parent = FileUri.fsPath(uri);
|
||||
|
||||
const sketchBaseName = `sketch_${monthNames[today.getMonth()]}${today.getDate()}`;
|
||||
let sketchName: string | undefined;
|
||||
|
Reference in New Issue
Block a user