Skip to content

Commit

Permalink
Skip saving LocalDirectory-type repos to localStorage, since the File…
Browse files Browse the repository at this point in the history
…SystemDirectoryHandle can not be stored as a string, requires IndexedDB
  • Loading branch information
james-strauss-uwa committed Nov 4, 2024
1 parent 7c2e2d2 commit d2cfd32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/Repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,28 @@ export class Repositories {
Utils.showUserMessage("Error", "Repository name is empty!");
return;
}

if (repositoryBranch.trim() == ""){
Utils.showUserMessage("Error", "Repository branch is empty! If you wish to use the master branch, please enter 'master'.");
return;
}
}

// add extension to userString to indicate repository service
const localStorageKey : string = Utils.getLocalStorageKey(repositoryService, repositoryName, repositoryBranch);
if (localStorageKey === null){
Utils.showUserMessage("Error", "Unknown repository service. Not GitHub or GitLab! (" + repositoryService + ")");
return;
}
// add details of repository to HTML localStorage, so that EAGLE remembers to load this repository at startup
//
// NOTE: we can't save LocalDirectory-type repositories, since the FileSystemDirectoryHandle containing the
// details of the repository can not be saved in localStorage, it requires IndexedDB
if (repositoryService === Repository.Service.GitHub || repositoryService === Repository.Service.GitLab){
const localStorageKey : string = Utils.getLocalStorageKey(repositoryService, repositoryName, repositoryBranch);
const localStorageValue : string = Utils.getLocalStorageValue(repositoryService, repositoryName, repositoryBranch);

// Adding the repo name into the local browser storage.
localStorage.setItem(localStorageKey, Utils.getLocalStorageValue(repositoryService, repositoryName, repositoryBranch));
// Adding the repo name into the local browser storage.
localStorage.setItem(localStorageKey, localStorageValue);
} else {
console.log("Skip saving new repository to localStorage. Not a git repository.")
}

// Reload the repository lists
// load the repository lists
if (repositoryService === Repository.Service.GitHub){
GitHub.loadRepoList();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,19 +1336,19 @@ export class Utils {
return this.getBottomWindowHeight() + $('#statusBar').height()
}

// TODO: move to Repository.ts?
static getLocalStorageKey(repositoryService : Repository.Service, repositoryName : string, repositoryBranch : string) : string {
switch (repositoryService){
case Repository.Service.GitHub:
return repositoryName + "|" + repositoryBranch + ".github_repository_and_branch";
case Repository.Service.GitLab:
return repositoryName + "|" + repositoryBranch + ".gitlab_repository_and_branch";
case Repository.Service.LocalDirectory:
return repositoryName + ".local_directory";
default:
return null;
}
}

// TODO: move to Repository.ts?
static getLocalStorageValue(repositoryService : Repository.Service, repositoryName : string, repositoryBranch : string) : string {
return repositoryName+"|"+repositoryBranch;
}
Expand Down

0 comments on commit d2cfd32

Please sign in to comment.