Skip to content

Commit

Permalink
Merge pull request #84 from geopjr-forks/303
Browse files Browse the repository at this point in the history
3.0.3
  • Loading branch information
GeopJr authored May 21, 2022
2 parents fb1c52e + 3ec5f22 commit ac83b40
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Shards install
run: shards install
run: shards install --skip-postinstall --skip-executables
- name: Generate gresource
run: make gresource || curl "https://raw.githubusercontent.com/GeopJr/GeopJr/main/collision.gresource" -o data/dev.geopjr.Collision.gresource
- name: Spec
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.dwarf
*~
collision
!collision/
.flatpak-builder/
*.gresource
.rucksack
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
crystal 1.4.0
crystal 1.4.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

### Dependencies

- `Crystal` - `~1.4.0`
- `Crystal` - `~1.4.1`
- `GTK`
- `libadwaita`
- `gettext`
Expand Down
11 changes: 11 additions & 0 deletions data/dev.geopjr.Collision.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
</screenshot>
</screenshots>
<releases>
<release version="3.0.3" date="2022-05-21">
<description>
<ul>
<li>Handle feedback on buttons when spammed</li>
<li>Hash comparison is now case-insensitive</li>
<li>Fixed some memory related issues</li>
<li>Added Swedish and Catalan translations</li>
<li>Updated translations</li>
</ul>
</description>
</release>
<release version="3.0.2" date="2022-04-22">
<description>
<ul>
Expand Down
8 changes: 5 additions & 3 deletions data/ui/tools.ui
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkBox" id="tools">
<property name="homogeneous">1</property>
<property name="spacing">45</property>
<object class="GtkGrid" id="tools">
<property name="row-homogeneous">1</property>
<property name="row-spacing">32</property>
<property name="column-homogeneous">1</property>
<property name="column-spacing">45</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
Expand Down
8 changes: 4 additions & 4 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ shards:

gi-crystal:
git: https://github.com/hugopl/gi-crystal.git
version: 0.9.0+git.commit.3076bb54ac23569b57bc7eb9e6d8af278d7f3f43
version: 0.11.0

gtk4:
git: https://github.com/hugopl/gtk4.cr.git
version: 0.7.0+git.commit.c4f6975a402bf025677b53dba125330f9a40009f
version: 0.9.0

libadwaita:
git: https://github.com/geopjr/libadwaita.cr.git
version: 1.0.0+git.commit.4b9842eae67e3641dea511349a664efaf7d04a3e
version: 1.0.0+git.commit.ebf5b221d3dbcc5852dc1433b440f99a8b7f094b

non-blocking-spawn:
git: https://github.com/geopjr/non-blocking-spawn.git
version: 1.0.1
version: 1.0.2

version_from_shard:
git: https://github.com/hugopl/version_from_shard.git
Expand Down
11 changes: 6 additions & 5 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: collision
version: 3.0.2
version: 3.0.3

authors:
- GeopJr <[email protected]>
Expand All @@ -11,17 +11,18 @@ targets:
dependencies:
libadwaita:
github: GeopJr/libadwaita.cr
commit: 4b9842eae67e3641dea511349a664efaf7d04a3e
branch: stable
commit: ebf5b221d3dbcc5852dc1433b440f99a8b7f094b
compiled_license:
github: elorest/compiled_license
version: ~> 1.2.1
version: ~> 1.2.2
non-blocking-spawn:
github: GeopJr/non-blocking-spawn
version: ~> 1.0.1
version: ~> 1.0.2
gettext:
github: GeopJr/gettext.cr
version: ~> 1.0.0

crystal: 1.4.0
crystal: 1.4.1

license: BSD-2-Clause
2 changes: 1 addition & 1 deletion spec/feedback_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "./spec_helper"
require "../src/modules/functions/feedback.cr"
require "../src/collision/functions/feedback.cr"

describe "icon" do
it "returns the correct symbolic icon for feedback based on whether or not the task was successful" do
Expand Down
2 changes: 1 addition & 1 deletion spec/hash_generator_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "./spec_helper"
require "../src/modules/functions/generate_hash.cr"
require "../src/collision/functions/generate_hash.cr"

describe "hash generator" do
it "gets hashes from file" do
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ require "spec"
require "libadwaita"
require "gettext"

require "../src/modules/prerequisites.cr"
module Collision
HASH_FUNCTIONS = ["MD5", "SHA1", "SHA256", "SHA512"]
end
36 changes: 29 additions & 7 deletions src/collision.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@ require "compiled_license"
require "gettext"
require "log"

require "./modules/prerequisites.cr"
require "./modules/functions/*"
require "./modules/views/*"
require "./modules/views/tools/*"
if Non::Blocking.threads.size == 0
STDERR.puts "App is running in single-threaded mode. Exiting."
exit(1)
end

module Collision
LOGGER = Log.for("Collision", ARGV[0]? == "--debug" ? Log::Severity::Debug : Log::Severity::Warn)

begin
Gettext.setlocale(Gettext::LC::ALL, "")
Gettext.bindtextdomain("dev.geopjr.Collision", {{env("COLLISION_LOCALE_LOCATION").nil? ? "/usr/share/locale" : env("COLLISION_LOCALE_LOCATION")}})
Gettext.textdomain("dev.geopjr.Collision")
rescue ex
LOGGER.debug { ex }
end

HASH_FUNCTIONS = ["MD5", "SHA1", "SHA256", "SHA512"]
VERSION = {{read_file("./shard.yml").split("version: ")[1].split("\n")[0]}} # Shards binary might not be in PATH, reading yml is safer

ARTICLE = Gettext.gettext("https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions")

RESOURCE = Gio::Resource.new_from_data(GLib::Bytes.new_take({{read_file("./data/dev.geopjr.Collision.gresource")}}.bytes))
RESOURCE._register
end

require "./collision/functions/*"
require "./collision/views/*"
require "./collision/views/tools/*"

macro gen_hash(buttons)
{
Expand All @@ -17,8 +41,6 @@ macro gen_hash(buttons)
end

module Collision
extend self

B_UI = Gtk::Builder.new_from_resource("/dev/geopjr/Collision/ui/welcomer.ui")
B_HL = Gtk::Builder.new_from_resource("/dev/geopjr/Collision/ui/header_left.ui")
B_HR = Gtk::Builder.new_from_resource("/dev/geopjr/Collision/ui/header_right.ui")
Expand Down Expand Up @@ -69,7 +91,7 @@ module Collision
tooltip_text: Gettext.gettext("Insert a MD5/SHA-1/SHA-256/SHA-512 Hash")
)

TOOLS_BOX = Gtk::Box.cast(B_TL["tools"])
TOOLS_GRID = Gtk::Grid.cast(B_TL["tools"])
TOOL_VERIFY_OVERLAY = Gtk::Overlay.cast(B_TL["verifyOverlay"])
TOOL_VERIFY_OVERLAY_LABEL = Gtk::Label.cast(B_TL["verifyOverlayLabel"])
TOOL_VERIFY_FEEDBACK = Gtk::Image.cast(B_TL["verifyFeedback"])
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Collision

hash_list_page = STACK.add_titled(HASH_LIST, "hashes", HASH_LIST_TITLE)
hash_list_page.icon_name = "octothorp-symbolic"
tools_page = STACK.add_titled(TOOLS_BOX, "verify", TOOLS_TITLE)
tools_page = STACK.add_titled(TOOLS_GRID, "verify", TOOLS_TITLE)
tools_page.icon_name = "test-pass-symbolic"

clamp = Adw::Clamp.cast(FILE_INFO.child.not_nil!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ module Collision
hash.file(filename).final.hexstring.downcase
end

# If there are more than one threads available (except the current one),
# spawn fibers else just run in sync.
def handle_spawning(&block)
if Non::Blocking.threads.size == 0
LOGGER.debug { "Single thread fiber" }
yield
else
Non::Blocking.spawn(same_thread: false, &block)
end
Non::Blocking.spawn(same_thread: false, &block)
end

def on_finished(&block)
@@finished_fibers += 1
LOGGER.debug { "Finished fiber #{@@finished_fibers}/#{ACTION_ROWS.keys.size}" }

yield if @@finished_fibers == ACTION_ROWS.keys.size
Expand All @@ -48,6 +40,8 @@ module Collision
hash_value = calculate_hash(hash_type, filename)
ACTION_ROWS[hash_type].subtitle = hash_value.gsub(/.{1,4}/) { |x| x + " " }[0..-2]
CLIPBOARD_HASH[hash_type] = hash_value
@@finished_fibers += 1

on_finished(&block)
end
end
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 17 additions & 2 deletions src/modules/views/main.cr → src/collision/views/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Collision

clipboard = window.clipboard
COPY_BUTTONS.each do |hash_type, btn|
soft_locked = false
btn.clicked_signal.connect do
LOGGER.debug { "Copied #{hash_type} hash" }

Expand All @@ -50,13 +51,17 @@ module Collision
success = false
end

next if soft_locked
soft_locked = true

btn.icon_name = Collision.icon(success)
feedback_class = success ? "success" : "error"
btn.add_css_class(feedback_class)
Non::Blocking.spawn do
sleep 1.1.seconds # 1 feels fast, 1.5 feels slow
btn.icon_name = "edit-copy-symbolic"
btn.remove_css_class(feedback_class)
soft_locked = false

LOGGER.debug { "Copy button feedback reset" }
end
Expand All @@ -78,9 +83,19 @@ module Collision
end

def startup(app : Adw::Application)
tools_grid_first_child = TOOLS_GRID.first_child
tools_grid_last_child = TOOLS_GRID.last_child
BOTTOM_TABS.notify_signal["reveal"].connect do
TOOLS_BOX.orientation = BOTTOM_TABS.reveal ? Gtk::Orientation::Vertical : Gtk::Orientation::Horizontal
TOOLS_BOX.spacing = BOTTOM_TABS.reveal ? 32 : 45
next if tools_grid_last_child.nil? || tools_grid_first_child.nil?
row = 0
column = 1
if BOTTOM_TABS.reveal
row = 1
column = 0
end

TOOLS_GRID.remove(tools_grid_last_child)
TOOLS_GRID.attach(tools_grid_last_child, column, row, 1, 1)
end

TOOL_COMPARE_BUTTON_SPINNER.visible = false
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Collision
extend self

def handle_input_change(text : String)
result = CLIPBOARD_HASH.values.includes?(text)
result = CLIPBOARD_HASH.values.includes?(text.downcase)
if text.size == 0
TOOL_VERIFY_OVERLAY_LABEL.visible = true
TOOL_VERIFY_FEEDBACK.visible = false
Expand Down
File renamed without changes.
21 changes: 0 additions & 21 deletions src/modules/prerequisites.cr

This file was deleted.

0 comments on commit ac83b40

Please sign in to comment.