-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0de710
Showing
12 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
root = true | ||
|
||
[*.cr] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true |
This file contains 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,6 @@ | ||
/docs/ | ||
/bin/ | ||
/.shards/ | ||
*.dwarf | ||
|
||
/lib/hoop |
This file contains 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,6 @@ | ||
language: crystal | ||
|
||
# Uncomment the following if you'd like Travis to run specs and check code formatting | ||
# script: | ||
# - crystal spec | ||
# - crystal tool format --check |
This file contains 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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Gabriel Holodak | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains 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,27 @@ | ||
# theme-watcher | ||
|
||
TODO: Write a description here | ||
|
||
## Installation | ||
|
||
TODO: Write installation instructions here | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Development | ||
|
||
TODO: Write development instructions here | ||
|
||
## Contributing | ||
|
||
1. Fork it (<https://github.com/your-github-user/theme-watcher/fork>) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request | ||
|
||
## Contributors | ||
|
||
- [Gabriel Holodak](https://github.com/your-github-user) - creator and maintainer |
This file contains 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,6 @@ | ||
version: 1.0 | ||
shards: | ||
hoop: | ||
path: ~/code/hoop | ||
version: 0 | ||
|
This file contains 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,17 @@ | ||
name: theme-watcher | ||
version: 0.1.0 | ||
|
||
authors: | ||
- Gabriel Holodak <[email protected]> | ||
|
||
targets: | ||
theme-watcher: | ||
main: src/theme-watcher.cr | ||
|
||
dependencies: | ||
hoop: | ||
path: ~/code/hoop | ||
|
||
crystal: 0.31.1 | ||
|
||
license: MIT |
This file contains 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,2 @@ | ||
require "spec" | ||
require "../src/theme-watcher" |
This file contains 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,9 @@ | ||
require "./spec_helper" | ||
|
||
describe Theme::Watcher do | ||
# TODO: Write tests | ||
|
||
it "works" do | ||
false.should eq(true) | ||
end | ||
end |
This file contains 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,36 @@ | ||
require "hoop" | ||
|
||
include Hoop | ||
|
||
# NSAutoreleasePool.new | ||
# NSApp.activation_policy = LibAppKit::NSApplicationActivationPolicy::Regular | ||
|
||
class NSDistributedNotificationCenter < NSNotificationCenter | ||
# register_class | ||
# static_method "defaultCenter", nil, "NSDistributedNotificationCenter", "default_center" | ||
# TODO: "NSString" should really be "NSNotificationName" but I'm not sure how to make a string pointer | ||
# method "addObserver:selector:name:object:", ["id", "SEL", "NSString", "id"], "void", "add_observer" | ||
end | ||
|
||
class NSUserDefaults < NSObject | ||
register_class | ||
static_method "standardUserDefaults", nil, "NSUserDefaults", "standard_user_defaults" | ||
method "stringForKey:", ["NSString"], "SafeString", "string_for_key" | ||
end | ||
|
||
class SafeString | ||
@str : String? | ||
|
||
# Necessary to safely handle a *NSString | ||
def initialize(ptr : UInt8*) | ||
if ptr.null? | ||
@str = nil | ||
else | ||
@str = NSString.new(ptr).to_s | ||
end | ||
end | ||
|
||
def with_default(default : String) String | ||
@str || default | ||
end | ||
end |
This file contains 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,58 @@ | ||
require "hoop" | ||
require "./ns_extensions" | ||
|
||
DARK_THEME = "gruvbox-dark-hard" | ||
LIGHT_THEME = "one-light" | ||
|
||
|
||
class ShellWriter | ||
@zsh : Process | ||
|
||
def initialize | ||
pipe_file = File.open(Path["~/color_pipe.txt"].expand, "wb") | ||
@zsh = Process.new("zsh", ["-s"], | ||
input: Process::Redirect::Pipe, | ||
output: pipe_file, | ||
error: Process::Redirect::Inherit, | ||
) | ||
@zsh.input << %(eval "$($DOTDIR/base16/base16-shell/profile_helper.sh)"\n) | ||
end | ||
|
||
def write_theme(theme : String) | ||
@zsh.input << "eval base16_#{theme}\n" | ||
end | ||
end | ||
|
||
class ThemeHandler < NSObject | ||
@writer = ShellWriter.new | ||
|
||
export_class | ||
action "theme_changed", "notice", "themeChanged:" do | ||
# notification = NSNotification.new(notice) | ||
|
||
case current_theme | ||
when /light/i | ||
# π π π π π | ||
puts("π #{LIGHT_THEME}") | ||
@writer.write_theme(LIGHT_THEME) | ||
when /dark/i | ||
# π π | ||
puts("π #{DARK_THEME}") | ||
@writer.write_theme(DARK_THEME) | ||
else | ||
puts("π #{current_theme}") | ||
end | ||
end | ||
|
||
def current_theme : String | ||
NSUserDefaults.standard_user_defaults.string_for_key("AppleInterfaceStyle").with_default("Light") | ||
end | ||
end | ||
|
||
handler = ThemeHandler.new.to_objc | ||
dnc = NSDistributedNotificationCenter.default_center | ||
dnc.add_observer(handler, "themeChanged:", "AppleInterfaceThemeChangedNotification", nil) | ||
|
||
puts "running" | ||
NSApp.run | ||
puts "done" |
This file contains 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,21 @@ | ||
abstract class ThemeSetter | ||
abstract def set_theme(theme : String) | ||
end | ||
|
||
class ShellThemeSetter < ThemeSetter | ||
@zsh : Process | ||
|
||
def initialize | ||
pipe_file = File.open(Path["~/color_pipe.txt"].expand, "wb") | ||
@zsh = Process.new("zsh", ["-s"], | ||
input: Process::Redirect::Pipe, | ||
output: pipe_file, | ||
error: Process::Redirect::Inherit, | ||
) | ||
@zsh.input << %(eval "$($DOTDIR/base16/base16-shell/profile_helper.sh)"\n) | ||
end | ||
|
||
def set_theme(theme : String) | ||
@zsh.input << "eval base16_#{theme}\n" | ||
end | ||
end |