From ee3545aa19ca909dff6e14a5d78c7a49248b9dee Mon Sep 17 00:00:00 2001 From: VetheonGames Date: Sat, 22 Jun 2024 11:28:28 -0600 Subject: [PATCH] Add in occasional message to ask for support --- bin/todo_marker | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/todo_marker b/bin/todo_marker index 0b869c4..335d2c3 100755 --- a/bin/todo_marker +++ b/bin/todo_marker @@ -4,6 +4,10 @@ # !/usr/bin/env ruby require 'todo_marker' +require 'date' + +DONATION_LINK = 'https://www.paypal.com/donate/?hosted_button_id=YF5XS7ZXQ6F8A' +TIMESTAMP_FILE = File.join(Dir.home, '.todo_marker_last_donation_prompt') if ARGV.empty? puts 'Usage: todo_marker ' @@ -18,3 +22,22 @@ end TodoMarker.generate_todo_md(directory) puts "TODO.md has been generated in the #{directory} directory." + +def should_show_donation_message? + return true unless File.exist?(TIMESTAMP_FILE) + + last_prompt = Date.parse(File.read(TIMESTAMP_FILE).strip) + (Date.today - last_prompt).to_i >= 7 # Show message once a week +rescue ArgumentError + true +end + +def update_timestamp + File.write(TIMESTAMP_FILE, Date.today.to_s) +end + +if should_show_donation_message? + puts "\nEnjoying TodoMarker? Consider donating to support development:" + puts DONATION_LINK + update_timestamp +end