1/* =========================================================
2 * Project IT Calendar - TypeScript Declaration File
3 * =========================================================
5 * CRITICAL ARCHITECTURAL FILE - DO NOT DELETE OR MODIFY LIGHTLY
7 * This file provides TypeScript type declarations for the Cinnamon/GJS
8 * runtime environment. It serves as the bridge between TypeScript's
9 * static type system and Cinnamon's dynamic JavaScript environment.
11 * IMPORTANCE LEVEL: HIGHEST - REQUIRED FOR COMPILATION
12 * ------------------------------------------------------------------
14 * WHY THIS FILE IS ABSOLUTELY NECESSARY:
16 * 1. TypeScript Compiler Requirement:
17 * - TypeScript knows NOTHING about Cinnamon/GJS APIs
18 * - Without these declarations, TypeScript would report hundreds of errors
19 * - Compilation would fail entirely
21 * 2. Hybrid Development Environment:
22 * - Development: TypeScript with full type checking
23 * - Production: GJS runtime with no TypeScript system
24 * - This file enables development-time safety while producing runtime code
27 * - Provides IntelliSense, auto-completion, and documentation in VS Code/IDEs
28 * - Enables "Go to Definition" for Cinnamon APIs
29 * - Shows parameter types and return values
31 * 4. Type Safety Across Boundaries:
32 * - Ensures our code correctly uses Cinnamon APIs
33 * - Catches type mismatches at compile time, not runtime
34 * - Documents the expected shape of Cinnamon objects
36 * WARNING TO FUTURE DEVELOPERS:
38 * DO NOT DELETE THIS FILE thinking "it's just types" or "TypeScript can infer".
39 * Cinnamon/GJS APIs are NOT standard JavaScript - they're injected at runtime
40 * and TypeScript has NO WAY to know about them without these declarations.
42 * Removing this file will:
43 * 1. Break TypeScript compilation immediately
44 * 2. Remove all IDE support for Cinnamon APIs
45 * 3. Make refactoring dangerous and error-prone
46 * 4. Introduce runtime errors that could have been caught at compile time
49/* =========================================================
50 * GLOBAL RUNTIME OBJECT DECLARATIONS
51 * =========================================================
53 * These objects exist in the GJS (GNOME JavaScript) runtime environment.
54 * They are injected by Cinnamon when applets are loaded.
58 * The global object in GJS environment.
60 * In Cinnamon applets, this is where:
61 * - Applet classes are registered for Cinnamon to find
62 * - Logging functions (global.log, global.logError) are available
63 * - Shared state between applet instances can be stored
65 * TypeScript needs to know this exists and has certain properties.
67declare const global: any;
70 * The imports object provides access to Cinnamon's module system.
72 * This is GJS's equivalent of Node.js's require() but for Cinnamon modules.
73 * Structure: imports.ui.applet, imports.gi.St, imports.misc.util, etc.
75 * Without this declaration, TypeScript would think `imports` is undefined.
77declare const imports: any;
79/* =========================================================
80 * MODULE SYSTEM DECLARATIONS
81 * =========================================================
83 * These declarations support the hybrid module system used by this project:
84 * - TypeScript/ES6 modules during development
85 * - No modules (global scope) in production GJS environment
89 * CommonJS exports object.
91 * Used when TypeScript compiles in CommonJS mode (for testing/tooling).
92 * In production, we use global assignments, but TypeScript needs to know
93 * `exports` might exist during compilation.
95declare const exports: any;
98 * CommonJS require function.
100 * Used by some build tools and test runners. Not used in production Cinnamon
101 * environment where imports.* is used instead.
103declare function require(path: string): any;
105/* =========================================================
106 * CINNAMON SIGNAL SYSTEM DECLARATIONS
107 * =========================================================
109 * Cinnamon uses a custom signal system (different from DOM events).
110 * This namespace provides TypeScript with the interface for signal handling.
113declare namespace Signals {
115 * Signal interface for GJS objects that emit events.
117 * Used by EventManager, CalendarView, and other components that need
118 * to communicate via events without tight coupling.
122 * this.connect('events-updated', () => this.render());
123 * this.emit('events-updated');
128 * Connect a callback function to a signal.
129 * @param name - Signal name (e.g., 'events-updated')
130 * @param callback - Function to call when signal is emitted
131 * @returns Connection ID that can be used to disconnect
133 connect(name: string, callback: Function): number;
136 * Disconnect a previously connected signal handler.
137 * @param id - Connection ID returned by connect()
139 disconnect(id: number): void;
142 * Emit a signal, calling all connected callbacks.
143 * @param name - Signal name to emit
144 * @param args - Arguments to pass to callbacks
146 emit(name: string, ...args: any[]): void;
150/* =========================================================
151 * CINNAMON APPLET BASE CLASS DECLARATIONS
152 * =========================================================
154 * These declarations describe the base applet classes provided by Cinnamon.
155 * Our applet classes extend these, so TypeScript needs to know their shape.
158declare namespace imports.ui.applet {
160 * Base class for Cinnamon applets that support both text and icon in panel.
162 * Our UniversalCalendarApplet extends this class to get:
163 * - Panel integration
165 * - Icon/text display methods
166 * - Built-in popup menu handling
168 class TextIconApplet {
170 * Constructor called by Cinnamon when applet is loaded.
171 * @param orientation - Panel orientation (horizontal/vertical)
172 * @param panelHeight - Height of the panel in pixels
173 * @param instanceId - Unique instance identifier
175 constructor(orientation: any, panelHeight: number, instanceId: number);
178 * Sets the text label displayed in the panel.
179 * Used by our update_label_and_tooltip() method.
181 set_applet_label(label: string): void;
184 * Sets the tooltip shown when hovering over the applet.
186 set_applet_tooltip(text: string): void;
189 * Sets the icon displayed in the panel.
190 * Used by our on_settings_changed() method.
192 set_applet_icon_name(name: string): void;
196/* =========================================================
197 * CINNAMON / GNOME GI (GOBJECT INTROSPECTION) DECLARATIONS
198 * =========================================================
200 * These are GObject Introspection bindings that expose C/C++ libraries
201 * to JavaScript. They are the foundation of Cinnamon's API.
203 * IMPORTANT: These are NOT TypeScript types for our code - they're
204 * declarations that these modules exist in the GJS runtime.
207declare namespace imports.gi {
209 * Shell Toolkit (St) - Cinnamon's UI widget library.
211 * Used for ALL UI rendering in the applet:
212 * - Buttons, labels, containers
213 * - Layout management (BoxLayout, Table)
214 * - Styling and theming
219 * Clutter - 2D graphics library (lower-level than St).
221 * St is built on Clutter. We use it for:
222 * - Event handling (scroll, keyboard)
223 * - Actor transformations
224 * - Animation (though not used in current implementation)
229 * GIO - GNOME Input/Output library.
232 * - File operations (ICS import)
233 * - DBus communication (CalendarServer)
234 * - Async I/O operations
239 * GLib - Low-level utility library.
242 * - Date/time formatting
244 * - Timeout/scheduling (periodic updates)
250 * Cinnamon - Cinnamon-specific APIs.
252 * Contains CalendarServerProxy for calendar data access.
253 * This is the primary interface to system calendar data.
258/* =========================================================
259 * CINNAMON HELPER MODULE DECLARATIONS
260 * =========================================================
262 * These are Cinnamon-specific utility modules not exposed via GI.
263 * They provide essential applet functionality.
267 * Signal system module.
269 * Provides Signals.addSignalMethods() which adds signal capabilities
270 * to our classes at runtime.
272declare namespace imports.signals {}
275 * Main loop/timer module.
277 * Provides timeout_add_seconds() for periodic updates (like refreshing events).
279declare namespace imports.mainloop {}
284 * Used to create the calendar popup menu attached to the panel applet.
286declare namespace imports.ui.popupMenu {}
291 * Provides AppletSettings for persisting user preferences.
293declare namespace imports.ui.settings {}
296 * Main Cinnamon UI manager.
298 * Provides keybindingManager for global hotkey support.
300declare namespace imports.ui.main {}
305 * Provides spawnCommandLine() for opening external applications
306 * (like cinnamon-settings calendar).
308declare namespace imports.misc.util {}
311 * File utility functions.
313 * Provides requireModule() for dynamic module loading (CalendarView).
315declare namespace imports.misc.fileUtils {}
318 * Internationalization (i18n) module.
320 * Provides Gettext functions for translation support.
322declare namespace imports.gettext {}
324/* =========================================================
325 * APPLICATION-SPECIFIC TYPE DECLARATIONS
326 * =========================================================
328 * These interfaces define data structures used throughout our application.
329 * They are NOT Cinnamon types - they're OUR types that TypeScript needs
330 * to know about across different files.
334 * EventData interface - Core event representation.
336 * This interface defines the shape of calendar events throughout the app.
337 * Used by EventManager, CalendarView, and EventListView.
339 * Note: This MUST match the structure returned by Cinnamon.CalendarServer
340 * and the structure expected by ECal for write operations.
342declare interface EventData {
344 * Unique event identifier.
345 * For events from Cinnamon.CalendarServer: "sourceUid:eventId"
346 * For new events: GLib-generated UUID
351 * Calendar source identifier.
352 * Maps to Evolution Data Server source UID.
353 * Used for write operations (which calendar to modify).
358 * Pure event ID without source prefix.
359 * Used internally for some operations.
370 * For all-day events: next day at 00:00 (per iCalendar spec).
375 * Event title/summary.
380 * Event description (optional).
381 * WARNING: Cinnamon.CalendarServer often doesn't provide this field.
383 description?: string;
386 * Calendar color for visual distinction.
387 * Hex format (e.g., "#3498db").
392 * All-day event flag.
393 * When true, times should be ignored in display.
399 * DateRange interface - For event filtering.
401 * Used by EventManager.getEventsForRange() and EventListView.updateForRange().
403declare interface DateRange {
405 * Range start date (inclusive).
410 * Range end date (exclusive).
416 * Holiday interface - For holiday rule definitions.
418 * Used by CalendarLogic for parsing holiday JSON files.
419 * Each holiday file contains arrays of these objects.
421declare interface Holiday {
424 * - 'f': Fixed date (e.g., Christmas on Dec 25)
425 * - 'e': Easter-based (e.g., Good Friday = Easter - 2)
426 * - 'r': Relative (e.g., "first Monday in September")
431 * Day of month (1-31) for fixed dates.
436 * Month of year (1-12) for fixed dates.
441 * Offset in days from Easter (for easter-based holidays).
442 * Example: -2 = Good Friday, +49 = Pentecost Monday
447 * Holiday name in local language.
452 * Public holiday flag:
453 * - true: Official public holiday (banks/schools closed)
454 * - false: Observance or traditional holiday
459 * Optional condition for historical rule changes.
460 * Format: "year<=1994" or "year>=2000"
465/* =========================================================
466 * COMPILATION NOTES AND WARNINGS
467 * =========================================================
469 * WHY WE USE `any` FOR MOST DECLARATIONS:
471 * 1. Cinnamon APIs are dynamic and change between versions
472 * 2. GJS bindings are generated at runtime, not known at compile time
473 * 3. Exact type definitions would be massive and fragile
474 * 4. The alternative is no type checking at all
476 * The `any` type tells TypeScript:
477 * - "This exists at runtime, trust me"
478 * - "Don't complain about missing properties"
479 * - "But still let me use TypeScript for OUR code"
481 * This is a practical compromise that gives us:
482 * - Type safety for OUR application logic
483 * - Flexibility for Cinnamon's runtime APIs
484 * - Working code that compiles and runs
487/* =========================================================
488 * WHAT HAPPENS IF THIS FILE IS REMOVED?
489 * =========================================================
491 * 1. TypeScript compilation fails immediately with errors like:
492 * - "Cannot find name 'global'"
493 * - "Cannot find name 'imports'"
494 * - "Cannot find namespace 'Signals'"
496 * 2. IDE features stop working:
497 * - No auto-completion for Cinnamon APIs
498 * - No type checking for function parameters
499 * - "Go to Definition" breaks for Cinnamon objects
501 * 3. Development becomes error-prone:
502 * - Typos in API calls won't be caught until runtime
503 * - Wrong parameter types cause silent failures
504 * - Refactoring becomes dangerous
506 * 4. The project becomes unmaintainable:
507 * - New developers can't understand what APIs are available
508 * - Code reviews can't catch type-related bugs
509 * - Upgrades to new Cinnamon versions become guesswork
512/* =========================================================
513 * BEST PRACTICES FOR MODIFYING THIS FILE
514 * =========================================================
516 * 1. ADD, DON'T REMOVE:
517 * - If you add a new Cinnamon API usage, add its declaration here
518 * - Never remove declarations "because they're not used"
519 * - Old declarations don't hurt and might be needed later
521 * 2. BE PRECISE WHEN POSSIBLE:
522 * - If you know the exact type signature, declare it
523 * - Use `any` only when you don't know or can't document
524 * - Add JSDoc comments for complex APIs
526 * 3. KEEP IT ORGANIZED:
527 * - Group related declarations together
528 * - Use sections and comments
529 * - Follow the existing structure
531 * 4. TEST COMPILATION:
532 * - After any change, run `tsc` to ensure it still compiles
533 * - Check that IDE auto-completion still works
534 * - Verify no new TypeScript errors appear
537/* =========================================================
538 * LEGACY AND COMPATIBILITY NOTES
539 * =========================================================
541 * Some of these declarations exist for historical reasons:
543 * 1. Multiple module systems:
544 * - We support both TypeScript modules and GJS global scope
545 * - This is why we have both `exports` and `global` declarations
547 * 2. Cinnamon version differences:
548 * - Different Cinnamon versions expose different APIs
549 * - We declare only what we use, not everything available
551 * 3. Evolution Data Server complexity:
552 * - ECal/ICal declarations are minimal because they're complex
553 * - We use these APIs through careful, tested patterns
555 * This file represents YEARS of accumulated knowledge about
556 * Cinnamon applet development. Treat it with respect.