-
Couldn't load subscription status.
- Fork 579
hijir@mushi: initial release #7360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .idea |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Hijri Date Applet for Cinnamon | ||
|
|
||
| A Cinnamon desktop panel applet that displays the current Hijri (Islamic) date using | ||
| the [Aladhan API](https://aladhan.com/prayer-times-api). The date updates at a configurable interval and supports both | ||
| Arabic and English display options. | ||
|
|
||
| ## Features | ||
|
|
||
| * Displays current Hijri date on the Cinnamon panel | ||
| * Configurable: | ||
|
|
||
| * Language (Arabic or English) | ||
| * Date format (`DD-MM-YYYY`, `YYYY-MM-DD`, `Month Day, Year`) | ||
| * Show numeric month or month name | ||
| * Separator character (e.g., `-`, `/`, ` `) | ||
| * Refresh interval | ||
| * Converts numbers to Arabic numerals when Arabic language is selected | ||
|
|
||
| ## Requirements | ||
|
|
||
| * Internet connection (to fetch Hijri date from Aladhan API) | ||
|
|
||
| ## Settings | ||
|
|
||
| You can access settings via the applet's right-click menu. | ||
|
|
||
| * **Language:** Display date in English or Arabic | ||
| * **Date Format:** Choose between different formats | ||
| * **Month Display:** Show month as a name or number | ||
| * **Separator:** Customize the separator character | ||
| * **Refresh Interval:** Set how often the date should update (in seconds) | ||
|
|
||
| ## API Used | ||
|
|
||
| [Aladhan](https://aladhan.com/islamic-calendar-api#get-/gToH/-date-) | ||
|
|
||
| ## Feedback | ||
|
|
||
| You can leave a comment on [cinnamon-spices.linuxmint.com](https://cinnamon-spices.linuxmint.com/) or create an issue on | ||
| my [Hijri Applet](https://github.com/mubashirzamir/hijri-applet) development GitHub repository. | ||
|
|
||
| This is where I develop new features and test ideas before submitting updates to the official Cinnamon Spices | ||
| repository. | ||
|
|
||
| If you find this applet useful, please let me know by liking it both on the Cinnamon Spices site and on GitHub. Your | ||
| feedback and support help motivate continued development and improvements. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| const Applet = imports.ui.applet; | ||
| const Soup = imports.gi.Soup; | ||
| const GLib = imports.gi.GLib; | ||
| const ByteArray = imports.byteArray; | ||
| const Settings = imports.ui.settings; | ||
|
|
||
| const BASE_URL = "https://api.aladhan.com/v1/gToH"; | ||
| const SETTINGS = { | ||
| 'language': 'en', | ||
| 'format': 'DD-MM-YYYY', | ||
| 'separator': ' ', | ||
| 'showMonthName': true, | ||
| 'refreshInterval': 3600 // in seconds | ||
| }; | ||
|
|
||
| const convertToArabicDigits = (str) => { | ||
| const arabicDigits = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]; | ||
| return str.replace(/\d/g, (d) => arabicDigits[parseInt(d)]); | ||
| }; | ||
|
|
||
| class HijriApplet extends Applet.TextApplet { | ||
| constructor(metadata, orientation, panelHeight, instanceId) { | ||
| super(orientation, panelHeight, instanceId); | ||
| this._setAppletLabel("Loading..."); | ||
|
|
||
| // Date variables | ||
| this.day; | ||
| this.month; | ||
| this.year; | ||
|
|
||
| // Hijri date | ||
| this.hijri; | ||
|
|
||
| // Session for HTTP requests | ||
| this.session = new Soup.Session(); | ||
|
|
||
| // Variables to throttle manual refreshes | ||
| this.isUpdating = false; | ||
| this.lastClickTime = 0; | ||
| this.throttleInterval = 2000; // 2 seconds in ms | ||
|
|
||
| // Setting defaults | ||
| this.language = SETTINGS.language; | ||
| this.format = SETTINGS.format; | ||
| this.showMonthName = SETTINGS.showMonthName; | ||
| this.separator = SETTINGS.separator; | ||
| this.refreshInterval = SETTINGS.refreshInterval; | ||
|
|
||
| this._initSettings(metadata, instanceId); | ||
| this._updateDate(); | ||
|
|
||
| this.timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, this.refreshInterval, () => { | ||
| this._updateDate(); | ||
| return true; | ||
| }); | ||
| } | ||
|
|
||
| _initSettings(metadata, instanceId) { | ||
| this.settings = new Settings.AppletSettings(this, metadata.uuid, instanceId); | ||
|
|
||
| for (const setting of Object.keys(SETTINGS)) { | ||
| this.settings.bindProperty( | ||
| Settings.BindingDirection.IN, | ||
| setting, | ||
| setting, | ||
| this._updateDate.bind(this), | ||
| null | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async _updateDate() { | ||
| if (this.isUpdating) { | ||
| return; | ||
| } | ||
|
|
||
| this.isUpdating = true; | ||
|
|
||
| try { | ||
| const url = this._buildURL(); | ||
| const request = this._buildRequest(url); | ||
| const response = await this._sendRequest(request); | ||
| const date = this._handleResponse(response, request); | ||
|
|
||
| this._setAppletLabel(date || "Error"); | ||
| } catch (e) { | ||
| this._logError(e); | ||
| this._setAppletLabel("Error"); | ||
| } finally { | ||
| this.isUpdating = false; | ||
| } | ||
| } | ||
|
|
||
| _buildURL() { | ||
| const now = new Date(); | ||
| const dateStr = `${now.getDate()}-${now.getMonth() + 1}-${now.getFullYear()}`; | ||
|
|
||
| return `${BASE_URL}?date=${dateStr}`; | ||
| } | ||
|
|
||
| _buildRequest(url) { | ||
| return Soup.Message.new("GET", url); | ||
| } | ||
|
|
||
| _sendRequest(request) { | ||
| return new Promise((resolve, reject) => { | ||
| this.session.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (session, res) => { | ||
| try { | ||
| let result = session.send_and_read_finish(res); | ||
| resolve(result); | ||
| } catch (e) { | ||
| this._logError(e); | ||
| reject(e); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| _handleResponse(response, request) { | ||
| if (!this._isRequestSuccessful(request)) { | ||
| this._handleRequestError(request); | ||
| return null; | ||
| } | ||
|
|
||
| const json = this._parseResponse(response); | ||
| this.hijri = json?.data?.hijri; | ||
|
|
||
| if (!this.hijri) { | ||
| this._handleInvalidStructure(); | ||
| return null; | ||
| } | ||
|
|
||
| return this._formatHijriDate(); | ||
| } | ||
|
|
||
| _isRequestSuccessful(request) { | ||
| return request.get_status() === Soup.Status.OK; | ||
| } | ||
|
|
||
| _handleRequestError(request) { | ||
| this._logError(`Request failed with status: ${request.get_status()}`); | ||
| this._logError(`Request failed with reason: ${request.get_reason()}`); | ||
| } | ||
|
|
||
| _parseResponse(response) { | ||
| try { | ||
| return JSON.parse(ByteArray.toString(response.get_data())); | ||
| } catch (e) { | ||
| this._logError("Failed to parse JSON response."); | ||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| _handleInvalidStructure() { | ||
| this._logError("Invalid response structure for Hijri date."); | ||
| } | ||
|
|
||
| _formatHijriDate() { | ||
| const hijri = this.hijri; | ||
|
|
||
| // Handle showMonthName setting | ||
| if (this.showMonthName) { | ||
| this.month = hijri.month[this.language] || hijri.month.en; | ||
| } else { | ||
| this.month = hijri.month.number.toString().padStart(2, "0"); | ||
| } | ||
|
|
||
| // Handle language setting | ||
| if (this.language === "ar") { | ||
| this.day = convertToArabicDigits(hijri.day); | ||
| this.year = convertToArabicDigits(hijri.year); | ||
|
|
||
| if (!this.showMonthName) { | ||
| this.month = convertToArabicDigits(hijri.month.number.toString().padStart(2, "0")); | ||
| } | ||
| } else { | ||
| this.day = hijri.day.toString().padStart(2, "0"); | ||
| this.year = hijri.year.toString(); | ||
| } | ||
|
|
||
| // Handle format and separator settings | ||
| switch (this.format) { | ||
| case "YYYY-MM-DD": | ||
| return `${this.year}${this.separator}${this.month}${this.separator}${this.day}`; | ||
| case "Month Day, Year": | ||
| return `${this.month}${this.separator}${this.day}${this.separator}${this.year}`; | ||
| default: | ||
| return `${this.day}${this.separator}${this.month}${this.separator}${this.year}`; | ||
| } | ||
| } | ||
|
|
||
| _setAppletLabel(label) { | ||
| this.set_applet_label(label); | ||
| } | ||
|
|
||
| _logError(message) { | ||
| global.logError(`hijri@mushi: ${message}`); | ||
| } | ||
|
|
||
| // Manual refresh | ||
| on_applet_clicked(event) { | ||
| const now = Date.now(); | ||
|
|
||
| if (this.isUpdating) { | ||
| return; | ||
| } | ||
|
|
||
| if (now - this.lastClickTime < this.throttleInterval) { | ||
| return; | ||
| } | ||
|
|
||
| this.lastClickTime = now; | ||
| this._updateDate(); | ||
| } | ||
|
|
||
| on_applet_removed_from_panel() { | ||
| if (this.timer) { | ||
| GLib.source_remove(this.timer); | ||
| this.timer = null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function main(metadata, orientation, panelHeight, instanceId) { | ||
| return new HijriApplet(metadata, orientation, panelHeight, instanceId); | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "uuid": "hijri@mushi", | ||
| "name": "Hijri Date", | ||
| "description": "Show today's date in the Hijri calendar.", | ||
| "version": "1.0", | ||
| "cinnamon-version": ["4.0", "5.0", "6.0"], | ||
| "author": "Mushi", | ||
| "applets": [ | ||
| { | ||
| "name": "Hijri Date", | ||
| "uuid": "hijri@mushi", | ||
| "description": "Show Hijri date in the panel.", | ||
| "settings-schema": "settings-schema.json" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "language": { | ||
| "type": "combobox", | ||
| "default": "en", | ||
| "description": "Language", | ||
| "options": { | ||
| "English": "en", | ||
| "Arabic": "ar" | ||
| } | ||
| }, | ||
| "format": { | ||
| "type": "combobox", | ||
| "default": "DD-MM-YYYY", | ||
| "description": "Date format", | ||
| "options": { | ||
| "DD-MM-YYYY": "DD-MM-YYYY", | ||
| "YYYY-MM-DD": "YYYY-MM-DD", | ||
| "Month Day, Year": "Month Day, Year" | ||
| } | ||
| }, | ||
| "separator": { | ||
| "type": "combobox", | ||
| "default": " ", | ||
| "description": "Date separator", | ||
| "options": { | ||
| "Space": " ", | ||
| "Dash": "-", | ||
| "Slash": "/", | ||
| "Dot": "." | ||
| } | ||
| }, | ||
| "showMonthName": { | ||
| "type": "checkbox", | ||
| "default": true, | ||
| "description": "Use month name instead of number" | ||
| }, | ||
| "refreshInterval": { | ||
| "type": "spinbutton", | ||
| "default": 3600, | ||
| "description": "Refresh interval in seconds", | ||
| "min": 3600, | ||
| "max": 86400, | ||
| "step": 3600 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "author": "mubashirzamir", | ||
| "license": "GPL-3.0" | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I've closed the request after noticing the typos in my commit message and post title. Will make a new PR and post a link here as well. Apologies.