diff --git a/Makefile b/Makefile index f249105..06b8644 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ build: clean # Create extension package mkdir -p build/ gnome-extensions pack -f \ + --extra-source=avatarLoader.js \ --extra-source=metadata.json \ --extra-source=LICENSE \ --extra-source=README.md \ diff --git a/extension.js b/extension.js index a83f466..4d99ce7 100644 --- a/extension.js +++ b/extension.js @@ -357,6 +357,8 @@ class GitLabIssuesIndicator extends PanelMenu.Button { try { if (message.status_code === 201 || message.status_code === 200) { Main.notify(this._('GitLab Issues Timer'), `${this._('Time sent')}: ${duration} ${this._('on issue')} #${this._selectedIssue.iid}`); + } else if (message.status_code === 401 || message.status_code === 403) { + Main.notify(this._('Error'), this._('Please configure the server URL and token in preferences')); } else { Main.notify(this._('Error'), `${this._('Unable to send time')}: ${message.status_code}`); } diff --git a/issueSelector.js b/issueSelector.js index e3ccc06..5e10f71 100644 --- a/issueSelector.js +++ b/issueSelector.js @@ -152,36 +152,64 @@ class IssueSelectorDialog extends ModalDialog.ModalDialog { _loadProjects() { this._showLoading(this._('Loading projects...')); - const url = this._settings.get_string('gitlab-url'); - const token = this._settings.get_string('gitlab-token'); - - const apiUrl = `${url}/api/v4/projects?membership=true&per_page=100&order_by=last_activity_at`; - - const message = Soup.Message.new('GET', apiUrl); - message.request_headers.append('PRIVATE-TOKEN', token); - - this._httpSession.send_and_read_async( - message, - GLib.PRIORITY_DEFAULT, - null, - (session, result) => { - try { - const bytes = session.send_and_read_finish(result); - const decoder = new TextDecoder('utf-8'); - const response = decoder.decode(bytes.get_data()); - - if (message.status_code === 200) { - this._projects = JSON.parse(response); - this._updateProjectList(); - this._hideLoading(); - } else { - this._showLoading(`${this._('Error')}: ${message.status_code}`); + try { + const url = this._settings.get_string('gitlab-url'); + const token = this._settings.get_string('gitlab-token'); + + log(`GitLab Issue Selector: Fetching projects from URL: ${url}`); + log(`GitLab Issue Selector: Using token length: ${token ? token.length : 0}`); + + const apiUrl = `${url}/api/v4/projects?membership=true&per_page=100&order_by=last_activity_at`; + + const message = Soup.Message.new('GET', apiUrl); + message.request_headers.append('PRIVATE-TOKEN', token); + + this._httpSession.send_and_read_async( + message, + GLib.PRIORITY_DEFAULT, + null, + (session, result) => { + let response = ''; + try { + const bytes = session.send_and_read_finish(result); + const decoder = new TextDecoder('utf-8'); + response = decoder.decode(bytes.get_data()); + + log(`GitLab Issue Selector: API response status code: ${message.status_code}`); + log(`GitLab Issue Selector: API response length: ${response.length}`); + + if (message.status_code === 200) { + log('GitLab Issue Selector: Parsing projects JSON...'); + this._projects = JSON.parse(response); + log(`GitLab Issue Selector: Loaded ${this._projects.length} projects`); + this._updateProjectList(); + this._hideLoading(); + } else if (message.status_code === 401 || message.status_code === 403) { + const authMessage = this._('Please configure the server URL and token in preferences'); + this._projects = []; + this._updateProjectList(); + this._showLoading(authMessage); + Main.notify(this._('Error'), authMessage); + } else { + log(`GitLab Issue Selector: Error fetching projects: ${message.status_code}`); + log(`GitLab Issue Selector: Response body: ${response}`); + this._showLoading(`${this._('Error')}: ${message.status_code}`); + } + } catch (e) { + log(`GitLab Issue Selector: Error parsing projects: ${e.message}`); + log(`GitLab Issue Selector: Full error: ${e.stack}`); + if (response) { + log(`GitLab Issue Selector: Response: ${response}`); + } + this._showLoading(`${this._('Error')}: ${e.message}`); } - } catch (e) { - this._showLoading(`${this._('Error')}: ${e.message}`); } - } - ); + ); + } catch (e) { + log(`GitLab Issue Selector: Error loading projects: ${e.message}`); + log(`GitLab Issue Selector: Full error: ${e.stack}`); + this._showLoading(`${this._('Error')}: ${e.message}`); + } } _updateProjectList() { @@ -284,6 +312,12 @@ class IssueSelectorDialog extends ModalDialog.ModalDialog { this._allIssues = JSON.parse(response); this._updateIssueList(); this._hideLoading(); + } else if (message.status_code === 401 || message.status_code === 403) { + const authMessage = this._('Please configure the server URL and token in preferences'); + this._allIssues = []; + this._updateIssueList(); + this._showLoading(authMessage); + Main.notify(this._('Error'), authMessage); } else { this._showLoading(`${this._('Error')}: ${message.status_code}`); } diff --git a/reportDialog.js b/reportDialog.js index 7cd8a66..0142862 100644 --- a/reportDialog.js +++ b/reportDialog.js @@ -299,6 +299,10 @@ class ReportDialog extends ModalDialog.ModalDialog { this._selectProject(project, null); } } + } else if (message.status_code === 401 || message.status_code === 403) { + const authMessage = this._('Please configure the server URL and token in preferences'); + this._projects = []; + Main.notify(this._('Error'), authMessage); } else { Main.notify(this._('Error'), `${this._('Unable to load projects')}: ${message.status_code}`); } @@ -448,6 +452,9 @@ class ReportDialog extends ModalDialog.ModalDialog { if (message.status_code === 200) { const issues = JSON.parse(response); this._processReportData(issues); + } else if (message.status_code === 401 || message.status_code === 403) { + this._hideLoading(); + Main.notify(this._('Error'), this._('Please configure the server URL and token in preferences')); } else { this._hideLoading(); Main.notify(this._('Error'), `${this._('Unable to load report')}: ${message.status_code}`);