Giter Club home page Giter Club logo

electronclock's Introduction

Alarm Clock

Overview

This is a basic alarm clock desktop application made with electron React and SQLite3. It has been made for demo purposes. As so this project is more of a POC than a proper production-ready project. As well all the steps of packaging, deploying to production or running the project on different environments have not been taken into account. It might evolve depending on the available time. The app displays an "analogic" clock as well as a numeric clock, two different approaches have been taken to build these clocks. The app gives the user to possibility to set-up alarms. Alarms are persisted in a SQLite3 local database.

TODO

  • refactor CSS for responsiveness
  • harmonize the usage CSS and MUI components style
  • error handling for db calls
  • check if alarms are stale and clean-up on alarm fetching
  • managing PRODUCTION and DEVELOPMENT environments
  • fix ES module scope error in vitest
  • pre-commit hook, lint and prettify

๐Ÿ›ซ Quick Setup

# install dependency
npm install

# develop
npm run dev

# if better-sqlite3 is not correctly installed
npm run rebuild

Implementation

Analogic Clock

The analogic clock is based on CSS animations. The idea is to target better performance and use less resources. The resulting animation looks like an analogic clock without making the react component rerendering

Numeric Clock

The analogic clock is based on React rerenders. The idea is to leverage React library. the result is a very neat and simple code ( vs the CSS ). Thus it is easier to debug and test and more predictable.

Alarms

Front-end

Alarms are displayed in the AlarmList component. From a UI point of view the component has two parts: a button that lets the user add new alarms and an alarm list that displays the coming alarms. To do so the component first retrieves the alarms from the database and then displays them as a list.

Every time the user adds or deletes an alarm the component refetches the alarm list from the database. This straightforward mechanism avoids complications that could happen with caching application's state and keeping it in sync with the db. This way the component always displays the data present in the database.

Once alarms are retrieved the component checks the time of each alarm and if the time is later than the actual time it sets up a JavaScript timer. That way the component just checks the time once and waits for the timeout(s) to complete. Another timeout is set up to update the component at the end of the day so the alarms that should repeat every day get their timeout renewed. For the alarms that do not mean to repeat, they are deleted upon user's alarm's acknowledgement (user's click the alarm modal)

Back-end

Alarms are stored in a very simple way each alarm has an id (string), a time (integer) and a repeat (boolean) field. The time is UNIX time in ms so it is easy to manipulate. The repeat is here so the user can set up daily alarms that are not depending on the date. Finaly the id of the alarm is mainly used to update and delete alarms as it is unique for every alarm.

๐Ÿ“‚ Directory structure

โ”œโ”€โ”€ electron                                 Electron-related code
โ”‚   โ”œโ”€โ”€ main                                 Main-process source code
โ”‚   โ””โ”€โ”€ preload                              Preload-scripts source code
โ”‚
โ”œโ”€โ”€ models                                  Connection to SQLite 3 database
โ”‚
โ”œโ”€โ”€ public                                   Static assets
โ””โ”€โ”€ src                                      Renderer source code, React application

IPC: Inter-Process-Communication Setup

IPC is a critical part of electron application because it lets the frontend part of the application leverage Node.js APIs. For this reason IPC should be handled with care to avoid security breaches.

โ” FAQ

Resources

electronclock's People

Contributors

raphael-corize avatar raphaelhebert avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.