Skip to content

Commit 59c57f5

Browse files
authored
Merge pull request #51 from arrterian/add-donate-notification
Add donate notification
2 parents 414e794 + 44b4be4 commit 59c57f5

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nix-env-selector",
33
"displayName": "Nix Environment Selector",
44
"description": "Allows switch environment for Visual Studio Code and extensions based on Nix config file.",
5-
"version": "1.0.5",
5+
"version": "1.0.6",
66
"keywords": [
77
"nix",
88
"nix-env",

resources/donate-wfp.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/ext/actions.cljs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
(:require ["fs" :refer [readdir]]
33
[config :refer [config vscode-config]]
44
[vscode.window :as w]
5+
[vscode.env :refer [open-external-url]]
56
[vscode.command :as cmd]
67
[vscode.workspace :as workspace]
78
[vscode.status-bar :as status-bar]
89
[ext.lang :as l]
10+
[ext.constants :as constants]
911
[ext.nix-env :as env]
1012
[promesa.core :as p]
1113
[utils.helpers :refer [unrender-workspace]]))
@@ -23,7 +25,6 @@
2325
(not))) %1)
2426
files-res)))
2527

26-
2728
(defn show-propose-env-dialog []
2829
(let [select-label (-> l/lang :label :select-env)
2930
dismiss-label (-> l/lang :label :dismiss)
@@ -37,6 +38,21 @@
3738
:nix-env-selector/suggestion
3839
false))))))
3940

41+
(defn show-donate-message [state]
42+
(let [show-message-info-path (str :nix-env-selector/select-env)
43+
show-message? (.get state show-message-info-path true)
44+
support-label (-> l/lang :label :support)
45+
dismiss-label (-> l/lang :label :dismiss)
46+
support-message (-> l/lang :notification :support)]
47+
(when show-message?
48+
(p/chain (w/show-notification support-message
49+
[support-label
50+
dismiss-label])
51+
(fn [answer]
52+
(.update state show-message-info-path false)
53+
(when
54+
(= answer support-label)
55+
(open-external-url constants/donate-url)))))))
4056

4157
(defn show-reload-dialog []
4258
(let [reload-label (-> l/lang :label :reload)

src/main/ext/constants.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(ns ext.constants)
2+
3+
(def donate-url "https://secure.wayforpay.com/button/b2fdead505bff")

src/main/ext/lang.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
(def ^:private lang-eng
44
{:notification {:env-restored "Original vscode environment will apply after reload"
55
:env-applied "Environment successfully prepared and will be using after reload"
6-
:env-available "The nix environment is available in your workspace"}
6+
:env-available "The nix environment is available in your workspace"
7+
:support "Do you like the extension? You can support the author if you wish"}
78
:label {:env-loading "$(loading~spin) Applying environment..."
89
:env-selected "$(beaker) Environment: %ENV_NAME%"
910
:env-need-reload "$(beaker) Need reload"
1011
:select-config-placeholder "Select environment config"
1112
:disabled-nix "Disable Nix environment"
1213
:reload "Reload"
1314
:select-env "Select"
14-
:dismiss "Dismiss"}})
15+
:dismiss "Dismiss"
16+
:support "Support"}})
1517

1618
(def lang lang-eng)

src/main/main.cljs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:require [config :refer [config update-config!]]
33
[promesa.core :as p]
44
[vscode.status-bar :as status]
5-
[vscode.context :refer [subsciribe]]
5+
[vscode.context :refer [subsciribe global-state]]
66
[vscode.command :as cmd]
77
[ext.actions :as act]
88
[ext.nix-env :as env]
@@ -13,15 +13,19 @@
1313
(update-config!)
1414
(let [status-bar (status/create :left 100)]
1515
(if (or (not-empty (:nix-file @config)) (not-empty (:nix-packages @config)))
16-
(do
16+
(try
1717
(-> (env/get-nix-env-sync {:nix-config (:nix-file @config)
1818
:packages (:nix-packages @config)
1919
:args (:nix-args @config)
2020
:nix-shell-path (:nix-shell-path @config)})
2121
(env/set-current-env))
2222
(->> status-bar
2323
(status/show {:text (render-env-status lang (:nix-file @config))
24-
:command :nix-env-selector/select-env})))
24+
:command :nix-env-selector/select-env}))
25+
(act/show-donate-message (global-state ctx))
26+
27+
(catch :default e
28+
(js/console.error "Applying environment error" e)))
2529

2630
;; show notification that nix config available
2731
;; if workspace contains .nix file(s)

src/main/vscode/context.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44

55
(defn subsciribe [ctx cmd]
66
(.push (.-subscriptions ctx) cmd))
7+
8+
(defn global-state [ctx]
9+
(.-globalState ctx))

src/main/vscode/env.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(ns vscode.env
2+
(:require ["vscode" :refer [env Uri]]))
3+
4+
(set! *warn-on-infer* false)
5+
6+
(defn open-external-url [url]
7+
(.openExternal env
8+
(.parse Uri url)))

0 commit comments

Comments
 (0)