Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e17cf894b8 | ||
|
|
dec492e39a | ||
|
|
20540937fe | ||
|
|
3dd29d7bb7 | ||
|
|
90ac2b0c7c | ||
|
|
e459255b23 | ||
|
|
9165716899 | ||
|
|
49cf63c6b8 | ||
|
|
d0b5f99e28 | ||
|
|
e1b28d2f83 | ||
|
|
24a2a23b23 | ||
|
|
25536e9bcb | ||
|
|
2f984fc411 | ||
|
|
596eee712b | ||
|
|
7b18037862 | ||
|
|
41cffb1a1c | ||
|
|
6ddfba93d9 | ||
|
|
6a1e12c83a | ||
|
|
e24261ab02 | ||
|
|
60d294b20f | ||
|
|
1ee051a106 | ||
|
|
ea1a167dd3 | ||
|
|
1a91a6b22e | ||
|
|
941c525409 | ||
|
|
d7f741c2ad | ||
|
|
ab73b28582 | ||
|
|
95ccf3a984 | ||
|
|
93eccc3470 | ||
|
|
f86f20321d | ||
|
|
475e2da999 | ||
|
|
985cac99e6 | ||
|
|
832b9bdf97 | ||
|
|
264502e1e6 | ||
|
|
6015dbda2f | ||
|
|
d879ee02fc | ||
|
|
27c55c6f09 | ||
|
|
395e380a3f | ||
|
|
ae6e61d6fa | ||
|
|
5ae7151916 | ||
|
|
0e2821eeca | ||
|
|
3ef374f79d | ||
|
|
9413cdc500 | ||
|
|
80d57342f9 | ||
|
|
089ec5dc54 | ||
|
|
a9ec669a27 | ||
|
|
7ed503390d | ||
|
|
33bc06a366 | ||
|
|
9c6a7ea2e2 | ||
|
|
3126d7b672 | ||
|
|
b5be5e4995 | ||
|
|
6a0b4b13f2 | ||
|
|
d3ad7b3797 | ||
|
|
6ae99e641b | ||
|
|
d1bf35607e | ||
|
|
603bcdffa4 | ||
|
|
71f2d56301 | ||
|
|
7f816d96cc | ||
|
|
5a2e2a5292 | ||
|
|
73f0c3e313 | ||
|
|
ff94887899 | ||
|
|
a8a357dc4b | ||
|
|
21d76a5245 | ||
|
|
0627495113 | ||
|
|
3397760955 | ||
|
|
ec9169306f | ||
|
|
1e48cb85d2 | ||
|
|
055e265f2f | ||
|
|
f692453ee2 | ||
|
|
272cc36788 | ||
|
|
5948ee6a4c | ||
|
|
47fc720df0 | ||
|
|
8008ba1298 | ||
|
|
7251beb2f1 | ||
|
|
79c48e4852 | ||
|
|
a709220e3a | ||
|
|
f5d23bce49 | ||
|
|
be4d1d5cab | ||
|
|
8dad2eb81b | ||
|
|
8019709534 | ||
|
|
83b9b0d457 | ||
|
|
e559c3ee38 | ||
|
|
a829c2e135 | ||
|
|
173baf899d | ||
|
|
ad2f45f062 | ||
|
|
85d04eab4b | ||
|
|
ec8ad133d1 | ||
|
|
c8b4d2ed8f | ||
|
|
b377ac8e38 | ||
|
|
12e0d5496d | ||
|
|
8593b5ac5f | ||
|
|
122dfccc00 | ||
|
|
7e95f151ed | ||
|
|
087c9aacbb | ||
|
|
5bea17da29 | ||
|
|
af25086090 | ||
|
|
80673696e9 | ||
|
|
1668908489 | ||
|
|
18164f1075 | ||
|
|
c461cdc37e | ||
|
|
bd843c77b2 | ||
|
|
9f3ba75ce6 | ||
|
|
a3fbb17615 | ||
|
|
eb8c4003a3 | ||
|
|
a4559ae168 | ||
|
|
03f0adbdd6 | ||
|
|
17c0a3b438 | ||
|
|
e1652d99dc | ||
|
|
1c029fc70e | ||
|
|
7ab42ec1de | ||
|
|
4b21a5abb6 | ||
|
|
b78e775285 | ||
|
|
a872d126ce | ||
|
|
5bc679d8e6 | ||
|
|
ae2b4a481d | ||
|
|
d90c403060 | ||
|
|
3a8fcaf099 | ||
|
|
473732b5ca | ||
|
|
8fa971c4e5 | ||
|
|
fd48f021e0 | ||
|
|
6868bfa7ca | ||
|
|
dcde49c7b3 | ||
|
|
21631f5cca | ||
|
|
89a75ba782 | ||
|
|
7893e804a4 | ||
|
|
f19d457209 | ||
|
|
2d94753690 | ||
|
|
37b4fd283a | ||
|
|
46b8bb037a | ||
|
|
073b15c5f8 | ||
|
|
b08fb11a78 | ||
|
|
f5c91c10e3 | ||
|
|
223fafcf1c | ||
|
|
cbdf629b49 | ||
|
|
614e86f38a | ||
|
|
1519fc1f1a | ||
|
|
9eb31ec872 | ||
|
|
5c568e6c33 | ||
|
|
b07c56247a | ||
|
|
ad82c96d8c | ||
|
|
2bca8b345f | ||
|
|
6c2ee1bfff | ||
|
|
83ead9a1d4 | ||
|
|
3b78de25a4 | ||
|
|
e36704b2b1 | ||
|
|
1fd253ff6b | ||
|
|
3ed69a048b | ||
|
|
43ed08e0e2 | ||
|
|
e89721130b | ||
|
|
7cbcce3404 | ||
|
|
708152ee19 | ||
|
|
26317d9ed2 | ||
|
|
d4de37fd15 | ||
|
|
88fdd2fec5 | ||
|
|
3493bbcf17 | ||
|
|
7ffa71d254 | ||
|
|
aa21efb86b | ||
|
|
54548564dd | ||
|
|
1f3dcc3332 | ||
|
|
dfb2de91f9 | ||
|
|
33c2fa07b8 | ||
|
|
3bf35c4d5d | ||
|
|
912dddaa6c | ||
|
|
bad0f85f6b | ||
|
|
b46dcb193f | ||
|
|
2c0aa31be7 | ||
|
|
01a672130c | ||
|
|
a1a37d33f9 | ||
|
|
48216e342b | ||
|
|
1a442ff002 | ||
|
|
dbe4aad8ea | ||
|
|
8d9571f5d8 | ||
|
|
93939d08bb | ||
|
|
219e342315 | ||
|
|
e11556bd9a | ||
|
|
917cacb18b | ||
|
|
b154c7b5aa | ||
|
|
c8ca8e55df | ||
|
|
39cecde560 | ||
|
|
c9c029f821 | ||
|
|
ecd40f5c43 | ||
|
|
d14236d502 | ||
|
|
5eecbc6718 | ||
|
|
09e4381ea7 | ||
|
|
cc991c6761 | ||
|
|
defec12c04 | ||
|
|
ef1c5fcfc5 | ||
|
|
0d12bf6b4a | ||
|
|
2e432967af | ||
|
|
8e53a6909f | ||
|
|
38b3e4ec94 | ||
|
|
6c00c1f497 | ||
|
|
121b3d6dc1 | ||
|
|
d2eed2b4fc | ||
|
|
5decbe9b86 | ||
|
|
91ba648095 | ||
|
|
919b4930b9 | ||
|
|
fb3c76184c | ||
|
|
d72a64ce67 | ||
|
|
07248bd28d | ||
|
|
37c948c9ac | ||
|
|
98b6e99743 | ||
|
|
0ffdf236a1 | ||
|
|
3f78aff86a | ||
|
|
601cca612c | ||
|
|
901cbda824 | ||
|
|
afb50f1bdd | ||
|
|
08877785aa | ||
|
|
71282eb65d | ||
|
|
edfb890638 | ||
|
|
e88fb78e9d | ||
|
|
93e52f3209 | ||
|
|
3af29314e7 | ||
|
|
8b18773da9 | ||
|
|
8d710fe6d7 | ||
|
|
010f3fdd7e | ||
|
|
0749d9e17d | ||
|
|
8a1ebd89ad | ||
|
|
594ebdd36a | ||
|
|
90c299da83 | ||
|
|
02a695056a | ||
|
|
50a3a7c422 | ||
|
|
3f699f40e3 | ||
|
|
b87ec9f348 | ||
|
|
79dda1d4fd | ||
|
|
5467bafaed | ||
|
|
ac3190111d | ||
|
|
298b402d5d | ||
|
|
a7b734b3bf | ||
|
|
3dd95e994f | ||
|
|
96e32fcc96 | ||
|
|
04a50e8152 | ||
|
|
e89853b6b5 | ||
|
|
c6bb9c9e28 | ||
|
|
d027ab9a02 | ||
|
|
13321cbc1a | ||
|
|
9a5af6437f | ||
|
|
a1967edb1d | ||
|
|
5900c51e70 | ||
|
|
6209727037 | ||
|
|
df15cb2231 | ||
|
|
eb2a44d2de | ||
|
|
e4fff8f638 | ||
|
|
80ec667f8b | ||
|
|
112c8c7c6c | ||
|
|
45338d00b8 | ||
|
|
04ed5d85e5 | ||
|
|
96ac5cd49f | ||
|
|
c70061995f | ||
|
|
501c5e20d8 | ||
|
|
5cc7d813a8 | ||
|
|
a0462ef502 | ||
|
|
1b1e29cbfe | ||
|
|
94855b7487 | ||
|
|
8ec0d58065 | ||
|
|
4476fe3061 | ||
|
|
4dbc75f540 | ||
|
|
a82c2a59f5 | ||
|
|
00b250c1b2 | ||
|
|
4ec9f0a5a6 | ||
|
|
5f82724039 | ||
|
|
6c65258439 | ||
|
|
f23493e3c8 | ||
|
|
de07e277f1 | ||
|
|
5c52810149 | ||
|
|
05a5ad56ea | ||
|
|
c51ffaa6e9 | ||
|
|
288b661611 | ||
|
|
32ab18f5f9 | ||
|
|
fddbd12820 | ||
|
|
563a7071ea | ||
|
|
d2c89ccb08 | ||
|
|
b5e8ce7639 | ||
|
|
6829c4c7f3 | ||
|
|
09bd970673 | ||
|
|
af61c83949 | ||
|
|
5ed24f85cf | ||
|
|
763a071488 | ||
|
|
bdb4d57d62 | ||
|
|
1be5fecf41 | ||
|
|
14dfb8b26a | ||
|
|
7284ce7f52 | ||
|
|
ac9f3c2a0d | ||
|
|
9dfab2223f | ||
|
|
c15da646fc | ||
|
|
2a47555987 | ||
|
|
ccf75bd45f | ||
|
|
d9b0b86cd5 | ||
|
|
d157b68384 | ||
|
|
0733381cd0 | ||
|
|
1870209878 | ||
|
|
565b3c3f69 | ||
|
|
7cdda79d67 | ||
|
|
a0f57ab4a3 | ||
|
|
edee7628d0 | ||
|
|
d06ad45423 | ||
|
|
9cf6a61e0f | ||
|
|
0ea4722dc8 | ||
|
|
39960dd755 | ||
|
|
8e5d3dea0a | ||
|
|
973b1a4963 | ||
|
|
dbd8632076 | ||
|
|
fffa7ebcb9 | ||
|
|
ded043db1d | ||
|
|
61ad64519b | ||
|
|
ef7f909d26 | ||
|
|
f2618fa940 | ||
|
|
363f885aea | ||
|
|
ed4a5adb16 | ||
|
|
82a3532e90 | ||
|
|
15d713191c | ||
|
|
575022139a | ||
|
|
b9686ac4ec | ||
|
|
43e4f8290e | ||
|
|
93387ebc57 | ||
|
|
54a9d7ce0d | ||
|
|
44b306ac20 | ||
|
|
14e1e0e3d3 | ||
|
|
136ba3c54f | ||
|
|
1a0c51c6d4 | ||
|
|
363018a43f | ||
|
|
3dcfaa94e9 | ||
|
|
05104e450e | ||
|
|
37f20e70bb | ||
|
|
e5a39fbe0d | ||
|
|
5c2f3e6f95 | ||
|
|
b3e831e3e6 | ||
|
|
31ff544379 | ||
|
|
7c4f62d16b | ||
|
|
f4b4623dab | ||
|
|
a32a86e15f | ||
|
|
6b64d3985d | ||
|
|
ed9c9ad6a6 | ||
|
|
bece957ea9 | ||
|
|
4e83e66a85 | ||
|
|
57d86a9723 | ||
|
|
8b6aae7bda | ||
|
|
2d204e48ab | ||
|
|
38a7b71fa8 | ||
|
|
95c94e3820 | ||
|
|
1920fdf35c | ||
|
|
9f3c46c366 | ||
|
|
221a2c2c6f | ||
|
|
bde65fa865 | ||
|
|
d52860e90a | ||
|
|
b85be454ce | ||
|
|
1f3dd72214 | ||
|
|
c4fcd986c0 | ||
|
|
ea21d37089 | ||
|
|
2f133720cc | ||
|
|
250c90fa02 | ||
|
|
7e2c5d2f45 | ||
|
|
9fed3fb192 | ||
|
|
0d85f933c7 | ||
|
|
f235ddf0f1 | ||
|
|
887cd45b4c | ||
|
|
aac2f220d6 | ||
|
|
90f15cc1e3 | ||
|
|
292b66af4d | ||
|
|
b6d835984c | ||
|
|
369b5ddacf | ||
|
|
6be29f49d7 | ||
|
|
8131140cb0 | ||
|
|
304314230c | ||
|
|
0ce605f122 | ||
|
|
d4aadd7dd4 | ||
|
|
3cf3e0a330 | ||
|
|
ff2cfc36b6 | ||
|
|
b118c66959 | ||
|
|
131e3536f1 | ||
|
|
b47b544065 | ||
|
|
b13c40e7e8 | ||
|
|
4e47fcef72 | ||
|
|
8acf618fd4 | ||
|
|
49e09f3f8b | ||
|
|
9bf8284d9f | ||
|
|
0f8aac81de | ||
|
|
abec73b868 | ||
|
|
86486c99f2 | ||
|
|
d9b7052e87 | ||
|
|
0efe105321 | ||
|
|
ed0dad960d | ||
|
|
2f58ed63de | ||
|
|
cc7e069f11 | ||
|
|
94a0eac58f | ||
|
|
9af0556d6c | ||
|
|
b14ca2c4ed | ||
|
|
89c1a5a614 | ||
|
|
3e32f611e8 | ||
|
|
07e65ce2bf | ||
|
|
f2a48487f1 | ||
|
|
c9d0cc7368 | ||
|
|
eecc2e8243 | ||
|
|
5c1896cd3b | ||
|
|
e0cde7fe0f | ||
|
|
2d4d0bc23a | ||
|
|
9a5bff3d37 | ||
|
|
28f212b7d6 | ||
|
|
bfad59fa7a | ||
|
|
f0e8f01d30 | ||
|
|
3ffd94e99d | ||
|
|
1be49d27ab | ||
|
|
4f43f64783 | ||
|
|
e7997a5272 | ||
|
|
507138364e | ||
|
|
0a4a1baeba | ||
|
|
14d111c4de | ||
|
|
db73d7e1cb | ||
|
|
825e9883d7 | ||
|
|
b2866c34df | ||
|
|
58e3ab9115 | ||
|
|
2b66b3c87f | ||
|
|
4505504732 | ||
|
|
567da9b0a3 | ||
|
|
7ccc36b121 | ||
|
|
559bf9d394 | ||
|
|
cee34dfb63 | ||
|
|
55995bd7a9 | ||
|
|
36edfddf74 | ||
|
|
188046e60a | ||
|
|
5338f3cae8 | ||
|
|
624146ecd7 | ||
|
|
8f711d1a9e | ||
|
|
b50090060b | ||
|
|
7db2321a82 | ||
|
|
def3aa3683 | ||
|
|
77d9a42c36 | ||
|
|
d395085064 | ||
|
|
56e5d60dae | ||
|
|
780cbf64b1 | ||
|
|
6b25d78ce6 | ||
|
|
53726e0e68 | ||
|
|
5e11e5d58b | ||
|
|
3e0417ce47 | ||
|
|
417bc843b0 | ||
|
|
6d6bdcca3e | ||
|
|
b4bfe39586 | ||
|
|
940cb6f38b | ||
|
|
59c6a39458 | ||
|
|
05ce19ec8c | ||
|
|
7b2bd59365 | ||
|
|
6a67883777 | ||
|
|
847e1c045a | ||
|
|
e918c5492e | ||
|
|
1aba3d4926 | ||
|
|
5ad51b6bf7 | ||
|
|
72cfe1168f | ||
|
|
5a96a0387b | ||
|
|
00a5b6377d | ||
|
|
f610aa8a0f | ||
|
|
c32342bca8 | ||
|
|
84af36f6bc | ||
|
|
f56465f54a | ||
|
|
2527657261 | ||
|
|
5414987ab6 | ||
|
|
327f0d5dd5 | ||
|
|
bd64aacbab | ||
|
|
c79b513470 | ||
|
|
bd3ca90514 | ||
|
|
88f88698a2 | ||
|
|
dcdf8d1854 | ||
|
|
fb717b3750 | ||
|
|
aff7b636f1 | ||
|
|
99a7de25d3 | ||
|
|
28d950ed9a | ||
|
|
1490470e91 | ||
|
|
236e0ff2e1 | ||
|
|
5cb9158077 | ||
|
|
941c7c1948 | ||
|
|
45e096c033 | ||
|
|
d37da0ef31 | ||
|
|
49abf56ec6 | ||
|
|
618a2485e1 | ||
|
|
cdeeeb6fa8 | ||
|
|
be833cc174 | ||
|
|
39955bcb3e | ||
|
|
e9b76a6867 | ||
|
|
89bce37dbd | ||
|
|
82a195c2f2 | ||
|
|
c48889cbbc | ||
|
|
dd9d5d2e72 | ||
|
|
7f7f15ea03 | ||
|
|
f502303426 | ||
|
|
2f2ed06d58 | ||
|
|
809167a872 | ||
|
|
5d3fd25098 | ||
|
|
6674fd0ad9 | ||
|
|
f874cb070d | ||
|
|
40230bfce8 | ||
|
|
3afa2b5f25 | ||
|
|
94ba1b8324 | ||
|
|
6dfacdfebd | ||
|
|
1ca7371103 | ||
|
|
1cb388d4af | ||
|
|
3bdd96c388 | ||
|
|
5bc5bf224f | ||
|
|
01815db1fe | ||
|
|
80cf43d3bf | ||
|
|
050f162c08 | ||
|
|
f5e03c9856 | ||
|
|
f763798683 | ||
|
|
46120e3431 | ||
|
|
829077883b | ||
|
|
8c928faa09 | ||
|
|
1654e9f1f5 | ||
|
|
f542331192 | ||
|
|
6830adb788 | ||
|
|
02e015371c | ||
|
|
80bdfa012c | ||
|
|
70326e9585 | ||
|
|
c0e1415b6e | ||
|
|
13a3402b58 | ||
|
|
73703412f8 | ||
|
|
ab226d95d4 | ||
|
|
de7a76bb3b | ||
|
|
379f58b4b8 | ||
|
|
3a04cd3db2 | ||
|
|
df0d3f080b | ||
|
|
04131d271a | ||
|
|
d66fe26634 | ||
|
|
8870f0621c | ||
|
|
e5250a7ae8 | ||
|
|
b2b6cedf2c | ||
|
|
e777c2c5ac | ||
|
|
7dcd8e1fbb | ||
|
|
37518cf88b | ||
|
|
ca0e22b8d0 | ||
|
|
074f5f9c7e | ||
|
|
0b40963c82 | ||
|
|
0b6b8a9968 | ||
|
|
47613454c7 | ||
|
|
96d063b4fd | ||
|
|
fec44fb0b5 | ||
|
|
58e7de5271 | ||
|
|
466b7a7503 | ||
|
|
50f9c84420 | ||
|
|
f07dae98ee | ||
|
|
1cc74f79b4 | ||
|
|
60c4f0518d | ||
|
|
f9fb05b194 | ||
|
|
d933f60b8b | ||
|
|
45bba6e2eb | ||
|
|
210aeedc25 | ||
|
|
acfb8e8883 |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
# Git will handle the files in whatever way it thinks is best.
|
||||
# Overwrites global core.autocrlf git setting
|
||||
* text=auto
|
||||
@@ -0,0 +1,23 @@
|
||||
name: CI
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Build client
|
||||
working-directory: ./FluentTerminal.Client
|
||||
run: |
|
||||
yarn
|
||||
yarn build
|
||||
|
||||
- name: Setup MSBuild.exe
|
||||
uses: warrenbuckley/Setup-MSBuild@v1
|
||||
|
||||
- name: MSBuild
|
||||
run: msbuild FluentTerminal.sln -t:build -p:Configuration=Debug -p:Platform=x64 -p:AppxPackage=false -m -restore
|
||||
@@ -1,5 +1,8 @@
|
||||
# Project specific
|
||||
FluentTerminal.App/Win32
|
||||
FluentTerminal.App/Client/
|
||||
FluentTerminal.Client/dist
|
||||
/.sonarqube
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
@@ -289,3 +292,5 @@ __pycache__/
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
!FluentTerminal.App/MoshExecutables/*
|
||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
reg add "HKCU\Software\Classes\Directory\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%1\"" /f
|
||||
reg add "HKCU\Software\Classes\Directory\Background\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
|
||||
reg add "HKCU\Software\Classes\LibraryFolder\Background\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
|
||||
@@ -0,0 +1,3 @@
|
||||
reg delete "HKCU\Software\Classes\Directory\shell\Open Fluent Terminal here" /f
|
||||
reg delete "HKCU\Software\Classes\Directory\Background\shell\Open Fluent Terminal here" /f
|
||||
reg delete "HKCU\Software\Classes\LibraryFolder\Background\shell\Open Fluent Terminal here" /f
|
||||
@@ -0,0 +1,157 @@
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class DefaultValueProviderTests
|
||||
{
|
||||
public static IEnumerable<object[]> Commands => System.Enum.GetValues(typeof(Command)).Cast<Command>().Select(x => new object[] { x });
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultApplicationSettings_Default_DoesNotReturnNull()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var applicationSettings = defaultValueProvider.GetDefaultApplicationSettings();
|
||||
|
||||
applicationSettings.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Commands))]
|
||||
public void GetDefaultKeyBindings_AllCommands_ReturnsANonEmptyList(Command command)
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var keyBindings = defaultValueProvider.GetDefaultKeyBindings(command);
|
||||
|
||||
keyBindings.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultShellProfileId_Default_DoesNotReturnEmptyGuid()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var defaultShellProfileId = defaultValueProvider.GetDefaultShellProfileId();
|
||||
|
||||
defaultShellProfileId.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultShellProfileId_Default_IdIsOneOfThePreInstalledShellProfiles()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
var shellProfiles = defaultValueProvider.GetPreinstalledShellProfiles();
|
||||
|
||||
var defaultShellProfileId = defaultValueProvider.GetDefaultShellProfileId();
|
||||
|
||||
shellProfiles.Select(x => x.Id).Should().Contain(defaultShellProfileId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultTerminalOptions_Default_DoesNotReturnNull()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var defaultTerminalOptions = defaultValueProvider.GetDefaultTerminalOptions();
|
||||
|
||||
defaultTerminalOptions.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultThemeId_Default_DoesNotReturnEmptyGuid()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var defaultThemeId = defaultValueProvider.GetDefaultThemeId();
|
||||
|
||||
defaultThemeId.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultThemeId_Default_IdIsOneOfThePreInstalledThemes()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
var themes = defaultValueProvider.GetPreInstalledThemes();
|
||||
|
||||
var defaultThemeId = defaultValueProvider.GetDefaultThemeId();
|
||||
|
||||
themes.Select(x => x.Id).Should().Contain(defaultThemeId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreinstalledShellProfiles_Default_ReturnsANonEmptyList()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var shellProfiles = defaultValueProvider.GetPreinstalledShellProfiles();
|
||||
|
||||
shellProfiles.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreinstalledShellProfiles_Default_HaveUniqueIds()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var shellProfiles = defaultValueProvider.GetPreinstalledShellProfiles();
|
||||
|
||||
shellProfiles.Select(x => x.Id).Should().OnlyHaveUniqueItems();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreinstalledShellProfiles_Default_HavePreInstalledSetToTrue()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var shellProfiles = defaultValueProvider.GetPreinstalledShellProfiles();
|
||||
|
||||
shellProfiles.Select(x => x.PreInstalled).Should().AllBeEquivalentTo(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreinstalledShellProfiles_Default_HaveNonEmptyLocations()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var shellProfiles = defaultValueProvider.GetPreinstalledShellProfiles();
|
||||
|
||||
shellProfiles.Select(x => x.Location).Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreInstalledThemes_Default_ReturnsANonEmptyList()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var themes = defaultValueProvider.GetPreInstalledThemes();
|
||||
|
||||
themes.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreinstalledThemes_Default_HaveUniqueIds()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var themes = defaultValueProvider.GetPreInstalledThemes();
|
||||
|
||||
themes.Select(x => x.Id).Should().OnlyHaveUniqueItems();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPreinstalledThemes_Default_HavePreInstalledSetToTrue()
|
||||
{
|
||||
var defaultValueProvider = new DefaultValueProvider();
|
||||
|
||||
var themes = defaultValueProvider.GetPreInstalledThemes();
|
||||
|
||||
themes.Select(x => x.PreInstalled).Should().AllBeEquivalentTo(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Dialogs;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class DialogServiceTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public DialogServiceTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowCreateKeyBindingDialog_Default_UsesCreateKeyBindingDialog()
|
||||
{
|
||||
var createKeyBindingDialog = new Mock<ICreateKeyBindingDialog>();
|
||||
var dialogService = new DialogService(Mock.Of<IMessageDialog>, () => createKeyBindingDialog.Object, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>, Mock.Of<ICustomCommandDialog>, Mock.Of<IAboutDialog>);
|
||||
|
||||
dialogService.ShowCreateKeyBindingDialog();
|
||||
|
||||
createKeyBindingDialog.Verify(x => x.CreateKeyBinding(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowMessageDialogAsnyc_TitleIsEmpty_ThrowsArgumentNullException()
|
||||
{
|
||||
var title = string.Empty;
|
||||
var content = _fixture.Create<string>();
|
||||
var buttons = _fixture.CreateMany<DialogButton>(2);
|
||||
var dialogService = new DialogService(Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>, Mock.Of<ICustomCommandDialog>, Mock.Of<IAboutDialog>);
|
||||
|
||||
Func<Task<DialogButton>> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1));
|
||||
|
||||
showMessageDialogAsnyc.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("title");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowMessageDialogAsnyc_ContentIsEmpty_ThrowsArgumentNullException()
|
||||
{
|
||||
var title = _fixture.Create<string>();
|
||||
var content = string.Empty;
|
||||
var buttons = _fixture.CreateMany<DialogButton>(2);
|
||||
var dialogService = new DialogService(Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>, Mock.Of<ICustomCommandDialog>, Mock.Of<IAboutDialog>);
|
||||
|
||||
Func<Task<DialogButton>> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1));
|
||||
|
||||
showMessageDialogAsnyc.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("content");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowMessageDialogAsnyc_NoButtonsPassed_ThrowsArgumentException()
|
||||
{
|
||||
var title = _fixture.Create<string>();
|
||||
var content = _fixture.Create<string>();
|
||||
var dialogService = new DialogService(Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>, Mock.Of<ICustomCommandDialog>, Mock.Of<IAboutDialog>);
|
||||
|
||||
Func<Task<DialogButton>> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content);
|
||||
|
||||
showMessageDialogAsnyc.Should().Throw<ArgumentException>().And.ParamName.Should().Be("buttons");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowMessageDialogAsnyc_Default_UsesMessageDialog()
|
||||
{
|
||||
var title = _fixture.Create<string>();
|
||||
var content = _fixture.Create<string>();
|
||||
var buttons = _fixture.CreateMany<DialogButton>(2);
|
||||
var messageDialog = new Mock<IMessageDialog>();
|
||||
var dialogService = new DialogService(() => messageDialog.Object, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>, Mock.Of<ICustomCommandDialog>, Mock.Of<IAboutDialog>);
|
||||
|
||||
dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1));
|
||||
|
||||
messageDialog.Verify(x => x.ShowAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowInputDialogAsync_UsesIInputDialogSetTitle()
|
||||
{
|
||||
var title = "title";
|
||||
var inputDialog = new Mock<IInputDialog>();
|
||||
var dialogService = new DialogService(Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, () => inputDialog.Object, Mock.Of<ISshConnectionInfoDialog>, Mock.Of<ICustomCommandDialog>, Mock.Of<IAboutDialog>);
|
||||
|
||||
dialogService.ShowInputDialogAsync(title);
|
||||
|
||||
inputDialog.Verify(x => x.SetTitle(title), Times.Once);
|
||||
inputDialog.Verify(x => x.GetInput(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="TestData\AdventureTime.itermcolors" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture" Version="4.11.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="5.10.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="Moq" Version="4.13.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="TestData\AdventureTime.itermcolors">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FluentTerminal.App.Services\FluentTerminal.App.Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows.Foundation.FoundationContract">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,80 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using FluentTerminal.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class FluentTerminalThemeParserTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public FluentTerminalThemeParserTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Parse_ValidFileStream_ReturnsTheme()
|
||||
{
|
||||
var theme = _fixture.Create<TerminalTheme>();
|
||||
var serialized = JsonConvert.SerializeObject(theme);
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(serialized));
|
||||
var parser = new FluentTerminalThemeParser();
|
||||
|
||||
var parsedTheme = await parser.Parse(theme.Name, stream);
|
||||
|
||||
parsedTheme.Name.Should().Be(theme.Name);
|
||||
parsedTheme.Author.Should().Be(theme.Author);
|
||||
parsedTheme.PreInstalled.Should().Be(false);
|
||||
parsedTheme.Colors.Should().BeEquivalentTo(theme.Colors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_InvalidFileStream_ThrowsException()
|
||||
{
|
||||
var fileName = _fixture.Create<string>();
|
||||
var serialized = _fixture.Create<string>();
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(serialized));
|
||||
var parser = new FluentTerminalThemeParser();
|
||||
|
||||
Func<Task<TerminalTheme>> parse = () => parser.Parse(fileName, stream);
|
||||
|
||||
parse.Should().Throw<Exception>();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Parse_InvalidFileName_ThrowsArgumentNullException(string fileName)
|
||||
{
|
||||
var theme = _fixture.Create<TerminalTheme>();
|
||||
var serialized = JsonConvert.SerializeObject(theme);
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(serialized));
|
||||
var parser = new FluentTerminalThemeParser();
|
||||
|
||||
Func<Task<TerminalTheme>> parse = () => parser.Parse(fileName, stream);
|
||||
|
||||
parse.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("fileName");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_FileStreamIsNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var fileName = _fixture.Create<string>();
|
||||
Stream stream = null;
|
||||
var parser = new FluentTerminalThemeParser();
|
||||
|
||||
Func<Task<TerminalTheme>> parse = () => parser.Parse(fileName, stream);
|
||||
|
||||
parse.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("fileContent");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using FluentTerminal.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class ITermThemeParserTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public ITermThemeParserTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Parse_InvalidFileName_ThrowsArgumentNullException(string fileName)
|
||||
{
|
||||
var stream = typeof(ITermThemeParserTests).Assembly.GetManifestResourceStream("FluentTerminal.App.Services.Test.TestData.AdventureTime.itermcolors");
|
||||
var parser = new ITermThemeParser();
|
||||
|
||||
Func<Task<TerminalTheme>> parse = () => parser.Parse(fileName, stream);
|
||||
|
||||
parse.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("fileName");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_FileStreamIsNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var fileName = _fixture.Create<string>();
|
||||
Stream stream = null;
|
||||
var parser = new ITermThemeParser();
|
||||
|
||||
Func<Task<TerminalTheme>> parse = () => parser.Parse(fileName, stream);
|
||||
|
||||
parse.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("fileContent");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_InvalidFileStream_ThrowsException()
|
||||
{
|
||||
var fileName = _fixture.Create<string>();
|
||||
var serialized = _fixture.Create<string>();
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(serialized));
|
||||
var parser = new ITermThemeParser();
|
||||
|
||||
Func<Task<TerminalTheme>> parse = () => parser.Parse(fileName, stream);
|
||||
|
||||
parse.Should().Throw<Exception>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Parse_ValidThemeFile_ParsesCorrectly()
|
||||
{
|
||||
var fileName = _fixture.Create<string>();
|
||||
var stream = typeof(ITermThemeParserTests).Assembly.GetManifestResourceStream("FluentTerminal.App.Services.Test.TestData.AdventureTime.itermcolors");
|
||||
var parser = new ITermThemeParser();
|
||||
|
||||
var theme = await parser.Parse(fileName, stream);
|
||||
|
||||
theme.Colors.Background.ToLower().Should().Be("#1f1d45");
|
||||
theme.Colors.Cursor.ToLower().Should().Be("#efbf38");
|
||||
theme.Colors.Foreground.ToLower().Should().Be("#f8dcc0");
|
||||
theme.Colors.Black.ToLower().Should().Be("#050404");
|
||||
theme.Colors.Red.ToLower().Should().Be("#bd0013");
|
||||
theme.Colors.Green.ToLower().Should().Be("#4ab118");
|
||||
theme.Colors.Yellow.ToLower().Should().Be("#e7741e");
|
||||
theme.Colors.Blue.ToLower().Should().Be("#0f4ac6");
|
||||
theme.Colors.Magenta.ToLower().Should().Be("#665993");
|
||||
theme.Colors.Cyan.ToLower().Should().Be("#70a598");
|
||||
theme.Colors.White.ToLower().Should().Be("#f8dcc0");
|
||||
theme.Colors.BrightBlack.ToLower().Should().Be("#4e7cbf");
|
||||
theme.Colors.BrightRed.ToLower().Should().Be("#fc5f5a");
|
||||
theme.Colors.BrightGreen.ToLower().Should().Be("#9eff6e");
|
||||
theme.Colors.BrightYellow.ToLower().Should().Be("#efc11a");
|
||||
theme.Colors.BrightBlue.ToLower().Should().Be("#1997c6");
|
||||
theme.Colors.BrightMagenta.ToLower().Should().Be("#9b5953");
|
||||
theme.Colors.BrightCyan.ToLower().Should().Be("#c8faf4");
|
||||
theme.Colors.BrightWhite.ToLower().Should().Be("#f6f5fb");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class KeyboardCommandServiceTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public KeyboardCommandServiceTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegisterCommandHandler_HandlerIsNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var command = ((Command)new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
|
||||
Action handler = null;
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
|
||||
Action invoke = () => keyboardCommandService.RegisterCommandHandler(command, handler);
|
||||
|
||||
invoke.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("handler");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegisterCommandHandler_CommandAlreadyRegisted_ThrowsInvalidOperationException()
|
||||
{
|
||||
var command = ((Command)new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
|
||||
var handler = _fixture.Create<Action>();
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
keyboardCommandService.RegisterCommandHandler(command, handler);
|
||||
|
||||
Action invoke = () => keyboardCommandService.RegisterCommandHandler(command, handler);
|
||||
|
||||
invoke.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeregisterCommandHandler_CommandIsNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
|
||||
Action invoke = () => keyboardCommandService.DeregisterCommandHandler(null);
|
||||
|
||||
invoke.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeregisterCommandHandler_CommandRegistered_HandlerGetsRemoved()
|
||||
{
|
||||
var command = ((Command)new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
|
||||
var handler = _fixture.Create<Action>();
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
|
||||
keyboardCommandService.RegisterCommandHandler(command, handler);
|
||||
|
||||
Action invoke = () => keyboardCommandService.DeregisterCommandHandler(command);
|
||||
|
||||
invoke.Should().NotThrow();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeregisterCommandHandler_CommandNotRegistered_ShouldNotThrow()
|
||||
{
|
||||
var command = ((Command)new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
|
||||
Action invoke = () => keyboardCommandService.DeregisterCommandHandler(command);
|
||||
|
||||
invoke.Should().NotThrow();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SendCommand_CommandIsRegistered_HandlerGetsInvoked()
|
||||
{
|
||||
var command = ((Command)new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
|
||||
var handlerCalled = false;
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
keyboardCommandService.RegisterCommandHandler(command, () => handlerCalled = true);
|
||||
|
||||
keyboardCommandService.SendCommand(command);
|
||||
|
||||
handlerCalled.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SendCommand_CommandIsNotRegisted_KeyNotFoundExceptionIsThrown()
|
||||
{
|
||||
var command = ((Command)new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
|
||||
Action invoke = () => keyboardCommandService.SendCommand(command);
|
||||
|
||||
invoke.Should().Throw<KeyNotFoundException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SendCommand_CommandIsToggleWindow_ShouldNotThrow()
|
||||
{
|
||||
var command = nameof(Command.ToggleWindow);
|
||||
var keyboardCommandService = new KeyboardCommandService();
|
||||
|
||||
Action invoke = () => keyboardCommandService.SendCommand(command);
|
||||
|
||||
invoke.Should().NotThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,793 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using FluentTerminal.Models.Messages;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class SettingsServiceTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public SettingsServiceTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_Default_WritesAllPreinstalledThemesInThemeContainer()
|
||||
{
|
||||
var themes = _fixture.CreateMany<TerminalTheme>(3);
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
defaultValueProvider.Setup(x => x.GetPreInstalledThemes()).Returns(themes);
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
|
||||
new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
defaultValueProvider.Verify(x => x.GetPreInstalledThemes(), Times.Once);
|
||||
foreach (var theme in themes)
|
||||
{
|
||||
themesContainer.Verify(x => x.WriteValueAsJson(theme.Id.ToString(), theme), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_Default_WritesAllPreinstalledShellProfilesInShellProfilesContainer()
|
||||
{
|
||||
var shellProfiles = _fixture.CreateMany<ShellProfile>(3);
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
defaultValueProvider.Setup(x => x.GetPreinstalledShellProfiles()).Returns(shellProfiles);
|
||||
var shellProfilesContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
ShellProfiles = shellProfilesContainer.Object,
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
|
||||
new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
defaultValueProvider.Verify(x => x.GetPreinstalledShellProfiles(), Times.Once);
|
||||
foreach (var shellProfile in shellProfiles)
|
||||
{
|
||||
shellProfilesContainer.Verify(x => x.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCurrentThemeId_ValueExistsInRoamingSettings_ReturnsCurrentThemeId()
|
||||
{
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var currentThemeId = (object)_fixture.Create<Guid>();
|
||||
roamingSettings.Setup(x => x.TryGetValue(SettingsService.CurrentThemeKey, out currentThemeId)).Returns(true);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetCurrentThemeId();
|
||||
|
||||
result.Should().Be((Guid)currentThemeId);
|
||||
roamingSettings.Verify(x => x.TryGetValue(SettingsService.CurrentThemeKey, out currentThemeId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCurrentThemeId_ValueDoesNotExistInRoamingSettings_ReturnsDefaultThemeIdFromDefaultValueProvider()
|
||||
{
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
var defaultThemeId = _fixture.Create<Guid>();
|
||||
defaultValueProvider.Setup(x => x.GetDefaultThemeId()).Returns(defaultThemeId);
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var currentThemeId = (object)_fixture.Create<Guid>();
|
||||
roamingSettings.Setup(x => x.TryGetValue(SettingsService.CurrentThemeKey, out currentThemeId)).Returns(false);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetCurrentThemeId();
|
||||
|
||||
result.Should().Be(defaultThemeId);
|
||||
defaultValueProvider.Verify(x => x.GetDefaultThemeId(), Times.Once);
|
||||
roamingSettings.Verify(x => x.TryGetValue(SettingsService.CurrentThemeKey, out currentThemeId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveCurrentThemeId_Default_SetsValueOnRoamingSettings()
|
||||
{
|
||||
var currentThemeId = _fixture.Create<Guid>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.SaveCurrentThemeId(currentThemeId);
|
||||
|
||||
roamingSettings.Verify(x => x.SetValue(SettingsService.CurrentThemeKey, currentThemeId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveCurrentThemeId_Default_InvokesCurrentThemeChangedEvent()
|
||||
{
|
||||
var currentThemeId = _fixture.Create<Guid>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var currentThemeChangedEventInvoked = false;
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
Messenger.Default.Register<CurrentThemeChangedMessage>(this,
|
||||
message => currentThemeChangedEventInvoked = true);
|
||||
|
||||
settingsService.SaveCurrentThemeId(currentThemeId);
|
||||
|
||||
currentThemeChangedEventInvoked.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveTheme_Default_WritesToThemesContainer()
|
||||
{
|
||||
var theme = _fixture.Create<TerminalTheme>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.SaveTheme(theme);
|
||||
|
||||
themesContainer.Verify(x => x.WriteValueAsJson(theme.Id.ToString(), theme), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveTheme_ThemeIsCurrentTheme_InvokesCurrentThemeChangedEvent()
|
||||
{
|
||||
var theme = _fixture.Create<TerminalTheme>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var currentThemeId = (object)theme.Id;
|
||||
roamingSettings.Setup(x => x.TryGetValue(SettingsService.CurrentThemeKey, out currentThemeId)).Returns(true);
|
||||
var currentThemeChangedEventInvoked = false;
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
Messenger.Default.Register<CurrentThemeChangedMessage>(this,
|
||||
message => currentThemeChangedEventInvoked = true);
|
||||
|
||||
settingsService.SaveTheme(theme);
|
||||
|
||||
currentThemeChangedEventInvoked.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteTheme_Default_CallsDeleteOnThemesContainer()
|
||||
{
|
||||
var themeId = _fixture.Create<Guid>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.DeleteTheme(themeId);
|
||||
|
||||
themesContainer.Verify(x => x.Delete(themeId.ToString()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetThemes_Default_CallsGetAllOnThemesContainer()
|
||||
{
|
||||
var themes = _fixture.CreateMany<TerminalTheme>(3);
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
themesContainer.Setup(x => x.GetAll()).Returns(themes.Select(JsonConvert.SerializeObject));
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetThemes();
|
||||
|
||||
result.Should().BeEquivalentTo(themes);
|
||||
themesContainer.Verify(x => x.GetAll(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTheme_ValidThemeId_ReturnsThemeFromThemesContainer()
|
||||
{
|
||||
var theme = _fixture.Create<TerminalTheme>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
themesContainer.Setup(x => x.ReadValueFromJson(theme.Id.ToString(), default(TerminalTheme))).Returns(theme);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetTheme(theme.Id);
|
||||
|
||||
result.Should().BeEquivalentTo(theme);
|
||||
themesContainer.Verify(x => x.ReadValueFromJson(theme.Id.ToString(), default(TerminalTheme)), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTheme_UnknownThemeId_ReturnsNull()
|
||||
{
|
||||
var themeId = _fixture.Create<Guid>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
themesContainer.Setup(x => x.ReadValueFromJson(themeId.ToString(), default(TerminalTheme))).Returns(value: null);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
Themes = themesContainer.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetTheme(themeId);
|
||||
|
||||
result.Should().BeNull();
|
||||
themesContainer.Verify(x => x.ReadValueFromJson(themeId.ToString(), default(TerminalTheme)), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTerminalOptions_Default_ReturnsTerminalOptionsFromRoamingSettings()
|
||||
{
|
||||
var terminalOptions = _fixture.Create<TerminalOptions>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
roamingSettings.Setup(x => x.ReadValueFromJson(nameof(TerminalOptions), It.IsAny<TerminalOptions>())).Returns(terminalOptions);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetTerminalOptions();
|
||||
|
||||
result.Should().BeEquivalentTo(terminalOptions);
|
||||
roamingSettings.Verify(x => x.ReadValueFromJson(nameof(TerminalOptions), It.IsAny<TerminalOptions>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveTerminalOptions_Default_WritesToRoamingSettings()
|
||||
{
|
||||
var terminalOptions = _fixture.Create<TerminalOptions>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.SaveTerminalOptions(terminalOptions);
|
||||
|
||||
roamingSettings.Verify(x => x.WriteValueAsJson(nameof(TerminalOptions), terminalOptions), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveTerminalOptions_Default_InvokesTerminalOptionsChangedEvent()
|
||||
{
|
||||
var terminalOptions = _fixture.Create<TerminalOptions>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var terminalOptionsChangedEventInvoked = false;
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
Messenger.Default.Register<TerminalOptionsChangedMessage>(this,
|
||||
message => terminalOptionsChangedEventInvoked = true);
|
||||
|
||||
settingsService.SaveTerminalOptions(terminalOptions);
|
||||
|
||||
terminalOptionsChangedEventInvoked.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetApplicationSettings_Default_ReturnsApplicationSettingsFromRoamingSettings()
|
||||
{
|
||||
var applicationSettings = _fixture.Create<ApplicationSettings>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
roamingSettings.Setup(x => x.ReadValueFromJson(nameof(ApplicationSettings), It.IsAny<ApplicationSettings>())).Returns(applicationSettings);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetApplicationSettings();
|
||||
|
||||
result.Should().BeEquivalentTo(applicationSettings);
|
||||
roamingSettings.Verify(x => x.ReadValueFromJson(nameof(ApplicationSettings), It.IsAny<ApplicationSettings>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveApplicationSettings_Default_WritesToRoamingSettings()
|
||||
{
|
||||
var applicationSettings = _fixture.Create<ApplicationSettings>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.SaveApplicationSettings(applicationSettings);
|
||||
|
||||
roamingSettings.Verify(x => x.WriteValueAsJson(nameof(ApplicationSettings), applicationSettings), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveApplicationSettings_Default_InvokesApplicationSettingsChangedEvent()
|
||||
{
|
||||
var applicationSettings = _fixture.Create<ApplicationSettings>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationSettingsChangedEventInvoked = false;
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
Messenger.Default.Register<ApplicationSettingsChangedMessage>(this,
|
||||
a => applicationSettingsChangedEventInvoked = true);
|
||||
|
||||
settingsService.SaveApplicationSettings(applicationSettings);
|
||||
|
||||
applicationSettingsChangedEventInvoked.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetKeyBindings_KeyBindingsInKeyBindingsContainer_ReturnsKeyBindingsFromKeyBindingsContainer()
|
||||
{
|
||||
var commands = _fixture.CreateMany<Command>(5);
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var keyBindingsContainer = new Mock<IApplicationDataContainer>();
|
||||
foreach (var command in commands)
|
||||
{
|
||||
keyBindingsContainer.Setup(x => x.ReadValueFromJson<Collection<KeyBinding>>(command.ToString(), null)).Returns(new Collection<KeyBinding> { });
|
||||
}
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
KeyBindings = keyBindingsContainer.Object,
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetCommandKeyBindings();
|
||||
|
||||
foreach (var command in commands)
|
||||
{
|
||||
keyBindingsContainer.Verify(x => x.ReadValueFromJson<Collection<KeyBinding>>(command.ToString(), null), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetKeyBindings_KeyBindingsNotInKeyBindingsContainer_ReturnsKeyBindingsFromDefaultValueProvider()
|
||||
{
|
||||
var commands = _fixture.CreateMany<Command>(5);
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
var keyBindingsContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
KeyBindings = keyBindingsContainer.Object,
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetCommandKeyBindings();
|
||||
|
||||
foreach (Command command in Enum.GetValues(typeof(Command)))
|
||||
{
|
||||
defaultValueProvider.Verify(x => x.GetDefaultKeyBindings(command), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveKeyBindings_Default_WritesToKeyBindingsContainer()
|
||||
{
|
||||
var command = _fixture.Create<Command>();
|
||||
var keyBindings = _fixture.Create<ICollection<KeyBinding>>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var keyBindingsContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
KeyBindings = keyBindingsContainer.Object,
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.SaveKeyBindings(command.ToString(), keyBindings);
|
||||
|
||||
keyBindingsContainer.Verify(x => x.WriteValueAsJson(command.ToString(), keyBindings), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveKeyBindings_Default_InvokesKeyBindingsChangedEvent()
|
||||
{
|
||||
var command = _fixture.Create<Command>();
|
||||
var keyBindings = _fixture.Create<Collection<KeyBinding>>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var keyBindingsContainer = new Mock<IApplicationDataContainer>();
|
||||
var keyBindingsChangedEventInvoked = false;
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
KeyBindings = keyBindingsContainer.Object,
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
Messenger.Default.Register<KeyBindingsChangedMessage>(this,
|
||||
message => keyBindingsChangedEventInvoked = true);
|
||||
|
||||
settingsService.SaveKeyBindings(command.ToString(), keyBindings);
|
||||
|
||||
keyBindingsChangedEventInvoked.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetKeyBindings_Default_WritesToKeyBindingsContainerFromDefaultValueProvider()
|
||||
{
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
var keyBindingsContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
KeyBindings = keyBindingsContainer.Object,
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
settingsService.ResetKeyBindings();
|
||||
|
||||
foreach (Command command in Enum.GetValues(typeof(Command)))
|
||||
{
|
||||
keyBindingsContainer.Verify(x => x.WriteValueAsJson(command.ToString(), It.IsAny<ICollection<KeyBinding>>()), Times.Once);
|
||||
defaultValueProvider.Verify(x => x.GetDefaultKeyBindings(command), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetKeyBindings_Default_InvokesKeyBindingsChangedEvent()
|
||||
{
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var keyBindingsContainer = new Mock<IApplicationDataContainer>();
|
||||
var keyBindingsChangedEventInvoked = false;
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
KeyBindings = keyBindingsContainer.Object,
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
Messenger.Default.Register<KeyBindingsChangedMessage>(this,
|
||||
message => keyBindingsChangedEventInvoked = true);
|
||||
|
||||
settingsService.ResetKeyBindings();
|
||||
|
||||
keyBindingsChangedEventInvoked.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultShellProfileId_ValueExistsInRoamingSettings_ReturnsDefaultShellProfileId()
|
||||
{
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var localSettings = new Mock<IApplicationDataContainer>();
|
||||
var defaultShellProfileId = (object)_fixture.Create<Guid>();
|
||||
localSettings.Setup(x => x.TryGetValue(SettingsService.DefaultShellProfileKey, out defaultShellProfileId)).Returns(true);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
LocalSettings = localSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetDefaultShellProfileId();
|
||||
|
||||
result.Should().Be((Guid)defaultShellProfileId);
|
||||
localSettings.Verify(x => x.TryGetValue(SettingsService.DefaultShellProfileKey, out defaultShellProfileId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultShellProfileId_ValueDoesNotExistInRoamingSettings_ReturnsDefaultShellProfileIdFromDefaultValueProvider()
|
||||
{
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
var defaultShellProfileId = _fixture.Create<Guid>();
|
||||
defaultValueProvider.Setup(x => x.GetDefaultShellProfileId()).Returns(defaultShellProfileId);
|
||||
var localSettings = new Mock<IApplicationDataContainer>();
|
||||
var currentDefaultShellProfileId = (object)_fixture.Create<Guid>();
|
||||
localSettings.Setup(x => x.TryGetValue(SettingsService.DefaultShellProfileKey, out currentDefaultShellProfileId)).Returns(false);
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
LocalSettings = localSettings.Object,
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetDefaultShellProfileId();
|
||||
|
||||
result.Should().Be(defaultShellProfileId);
|
||||
defaultValueProvider.Verify(x => x.GetDefaultShellProfileId(), Times.Once);
|
||||
localSettings.Verify(x => x.TryGetValue(SettingsService.DefaultShellProfileKey, out currentDefaultShellProfileId), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetShellProfiles_Default_CallsGetAllOnShellProfilesContainer()
|
||||
{
|
||||
var shellProfiles = _fixture.CreateMany<ShellProfile>(3);
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var shellProfilesContainer = new Mock<IApplicationDataContainer>();
|
||||
shellProfilesContainer.Setup(x => x.GetAll()).Returns(shellProfiles.Select(JsonConvert.SerializeObject));
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
ShellProfiles = shellProfilesContainer.Object,
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetShellProfiles();
|
||||
|
||||
result.Select(p => p.EqualTo(shellProfiles.FirstOrDefault(x => x.Id == p.Id)).Should().BeTrue());
|
||||
shellProfilesContainer.Verify(x => x.GetAll(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveShellProfile_Default_WritesToShellProfilesContainer()
|
||||
{
|
||||
var shellProfile = _fixture.Create<ShellProfile>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var shellProfilesContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
ShellProfiles = shellProfilesContainer.Object,
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.SaveShellProfile(shellProfile);
|
||||
|
||||
shellProfilesContainer.Verify(x => x.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteShellProfile_Default_CallsDeleteOnShellProfilesContainer()
|
||||
{
|
||||
var shellProfileId = _fixture.Create<Guid>();
|
||||
var defaultValueProvider = Mock.Of<IDefaultValueProvider>();
|
||||
var shellProfilesContainer = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
ShellProfiles = shellProfilesContainer.Object,
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers);
|
||||
|
||||
settingsService.DeleteShellProfile(shellProfileId);
|
||||
|
||||
shellProfilesContainer.Verify(x => x.Delete(shellProfileId.ToString()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultShellProfile_ProfileNotFound_DefaultShellProfileIdGetsResetToDefault()
|
||||
{
|
||||
var currentShellProfileId = (object)_fixture.Create<Guid>();
|
||||
var defaultShellProfile = _fixture.Create<ShellProfile>();
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
defaultValueProvider.Setup(x => x.GetDefaultShellProfileId()).Returns(defaultShellProfile.Id);
|
||||
var shellProfilesContainer = new Mock<IApplicationDataContainer>();
|
||||
var localSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
ShellProfiles = shellProfilesContainer.Object,
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = localSettings.Object,
|
||||
Themes = Mock.Of<IApplicationDataContainer>()
|
||||
};
|
||||
shellProfilesContainer.Setup(x => x.ReadValueFromJson(currentShellProfileId.ToString(), default(ShellProfile))).Returns(value: null);
|
||||
shellProfilesContainer.Setup(x => x.ReadValueFromJson(defaultShellProfile.Id.ToString(), default(ShellProfile))).Returns(defaultShellProfile);
|
||||
localSettings.Setup(x => x.TryGetValue(SettingsService.DefaultShellProfileKey, out currentShellProfileId)).Returns(true);
|
||||
var settingsService = new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetDefaultShellProfile();
|
||||
|
||||
result.Should().Be(defaultShellProfile);
|
||||
localSettings.Verify(x => x.SetValue(SettingsService.DefaultShellProfileKey, defaultShellProfile.Id), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCurrentTheme_ThemeNotFound_CurrentThemeIdGetsResetToDefault()
|
||||
{
|
||||
var currentThemeId = (object)_fixture.Create<Guid>();
|
||||
var defaultTheme = _fixture.Create<TerminalTheme>();
|
||||
var defaultValueProvider = new Mock<IDefaultValueProvider>();
|
||||
defaultValueProvider.Setup(x => x.GetDefaultThemeId()).Returns(defaultTheme.Id);
|
||||
var themesContainer = new Mock<IApplicationDataContainer>();
|
||||
var roamingSettings = new Mock<IApplicationDataContainer>();
|
||||
var applicationDataContainers = new ApplicationDataContainers
|
||||
{
|
||||
ShellProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
SshProfiles = Mock.Of<IApplicationDataContainer>(),
|
||||
KeyBindings = Mock.Of<IApplicationDataContainer>(),
|
||||
LocalSettings = Mock.Of<IApplicationDataContainer>(),
|
||||
RoamingSettings = roamingSettings.Object,
|
||||
Themes = themesContainer.Object
|
||||
};
|
||||
themesContainer.Setup(x => x.ReadValueFromJson(currentThemeId.ToString(), default(TerminalTheme))).Returns(value: null);
|
||||
themesContainer.Setup(x => x.ReadValueFromJson(defaultTheme.Id.ToString(), default(TerminalTheme))).Returns(defaultTheme);
|
||||
roamingSettings.Setup(x => x.TryGetValue(SettingsService.CurrentThemeKey, out currentThemeId)).Returns(true);
|
||||
var settingsService = new SettingsService(defaultValueProvider.Object, applicationDataContainers);
|
||||
|
||||
var result = settingsService.GetCurrentTheme();
|
||||
|
||||
result.Should().Be(defaultTheme);
|
||||
roamingSettings.Verify(x => x.SetValue(SettingsService.CurrentThemeKey, defaultTheme.Id), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Ansi 0 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.016337040811777115</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.016232240945100784</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.020433688536286354</real>
|
||||
</dict>
|
||||
<key>Ansi 1 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.075083047151565552</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.0</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.73976802825927734</real>
|
||||
</dict>
|
||||
<key>Ansi 10 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.43171143531799316</real>
|
||||
<key>Green Component</key>
|
||||
<real>1</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.61819148063659668</real>
|
||||
</dict>
|
||||
<key>Ansi 11 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.10242157429456711</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.7578997015953064</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.93761706352233887</real>
|
||||
</dict>
|
||||
<key>Ansi 12 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.77801346778869629</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.59102588891983032</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.096501544117927551</real>
|
||||
</dict>
|
||||
<key>Ansi 13 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.32394066452980042</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.34950375556945801</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.60686224699020386</real>
|
||||
</dict>
|
||||
<key>Ansi 14 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.95550096035003662</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.97915208339691162</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.78500419855117798</real>
|
||||
</dict>
|
||||
<key>Ansi 15 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.98438382148742676</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.96043074131011963</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.96449893712997437</real>
|
||||
</dict>
|
||||
<key>Ansi 2 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.092498354613780975</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.6950421929359436</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.28945007920265198</real>
|
||||
</dict>
|
||||
<key>Ansi 3 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.1164485365152359</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.45553147792816162</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.90543299913406372</real>
|
||||
</dict>
|
||||
<key>Ansi 4 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.77829605340957642</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.28880593180656433</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.059818677604198456</real>
|
||||
</dict>
|
||||
<key>Ansi 5 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.57602518796920776</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.35004982352256775</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.40191537141799927</real>
|
||||
</dict>
|
||||
<key>Ansi 6 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.59465551376342773</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.64633101224899292</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.43781715631484985</real>
|
||||
</dict>
|
||||
<key>Ansi 7 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.75428962707519531</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.86175870895385742</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.97308963537216187</real>
|
||||
</dict>
|
||||
<key>Ansi 8 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.7491685152053833</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.48549851775169373</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.30726605653762817</real>
|
||||
</dict>
|
||||
<key>Ansi 9 Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.35247993469238281</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.37095117568969727</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.98876720666885376</real>
|
||||
</dict>
|
||||
<key>Background Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.27054747939109802</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.11274909973144531</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.12003477662801743</real>
|
||||
</dict>
|
||||
<key>Bold Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.075083047151565552</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.0</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.73976802825927734</real>
|
||||
</dict>
|
||||
<key>Cursor Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.21945112943649292</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.74987590312957764</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.93704277276992798</real>
|
||||
</dict>
|
||||
<key>Cursor Text Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.037519864737987518</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.032785907387733459</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.02988031692802906</real>
|
||||
</dict>
|
||||
<key>Foreground Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.75428962707519531</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.86175870895385742</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.97308963537216187</real>
|
||||
</dict>
|
||||
<key>Selected Text Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.767447829246521</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.85237473249435425</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.95287787914276123</real>
|
||||
</dict>
|
||||
<key>Selection Color</key>
|
||||
<dict>
|
||||
<key>Blue Component</key>
|
||||
<real>0.30699285864830017</real>
|
||||
<key>Green Component</key>
|
||||
<real>0.41871801018714905</real>
|
||||
<key>Red Component</key>
|
||||
<real>0.43789717555046082</real>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,45 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class ThemeParserFactoryTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public ThemeParserFactoryTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetParser_SupportedFileType_ReturnsParser()
|
||||
{
|
||||
var supportedFileType = _fixture.Create<string>();
|
||||
var parser = new Mock<IThemeParser>();
|
||||
parser.Setup(x => x.SupportedFileTypes).Returns(new string[] { supportedFileType });
|
||||
var themeParserFactory = new ThemeParserFactory(new IThemeParser[] { parser.Object });
|
||||
|
||||
var result = themeParserFactory.GetParser(supportedFileType);
|
||||
|
||||
parser.Should().Be(parser);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetParser_UnsupportedFileType_ReturnsNull()
|
||||
{
|
||||
var unSupportedFileType = _fixture.Create<string>();
|
||||
var supportedFileType = _fixture.Create<string>();
|
||||
var parser = new Mock<IThemeParser>();
|
||||
parser.Setup(x => x.SupportedFileTypes).Returns(new string[] { supportedFileType });
|
||||
var themeParserFactory = new ThemeParserFactory(new IThemeParser[] { parser.Object });
|
||||
|
||||
var result = themeParserFactory.GetParser(unSupportedFileType);
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentTerminal.App.Services.Implementation;
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using FluentTerminal.Models.Requests;
|
||||
using FluentTerminal.Models.Responses;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation.Collections;
|
||||
using Xunit;
|
||||
|
||||
namespace FluentTerminal.App.Services.Test
|
||||
{
|
||||
public class TrayProcessCommunicationServiceTests
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
public TrayProcessCommunicationServiceTests()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateTerminal_Default_ReturnsResponseFromAppServiceConnection()
|
||||
{
|
||||
var settingsService = new Mock<ISettingsService>();
|
||||
var keyBindings = _fixture.CreateMany<KeyBinding>(3);
|
||||
settingsService.Setup(x => x.GetCommandKeyBindings()).Returns(new Dictionary<string, ICollection<KeyBinding>>
|
||||
{
|
||||
[nameof(Command.ToggleWindow)] = keyBindings.ToList()
|
||||
});
|
||||
var appServiceConnection = new Mock<IAppServiceConnection>();
|
||||
var response = _fixture.Create<CreateTerminalResponse>();
|
||||
var responseMessage = new ValueSet
|
||||
{
|
||||
[MessageKeys.Type] = _fixture.Create<string>(),
|
||||
[MessageKeys.Content] = JsonConvert.SerializeObject(response)
|
||||
};
|
||||
appServiceConnection.Setup(x => x.SendMessageAsync(It.IsAny<ValueSet>())).Returns(Task.FromResult(responseMessage));
|
||||
var terminalSize = _fixture.Create<TerminalSize>();
|
||||
var shellProfile = _fixture.Create<ShellProfile>();
|
||||
var sessionType = _fixture.Create<SessionType>();
|
||||
var id = _fixture.Create<byte>();
|
||||
var trayProcessCommunicationService = new TrayProcessCommunicationService(settingsService.Object);
|
||||
trayProcessCommunicationService.Initialize(appServiceConnection.Object);
|
||||
|
||||
var result = await trayProcessCommunicationService.CreateTerminalAsync(id, terminalSize, shellProfile, sessionType);
|
||||
|
||||
result.Should().BeEquivalentTo(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResizeTerminal_Default_SendsResizeTerminalRequest()
|
||||
{
|
||||
var terminalId = _fixture.Create<byte>();
|
||||
var terminalSize = _fixture.Create<TerminalSize>();
|
||||
var settingsService = new Mock<ISettingsService>();
|
||||
var keyBindings = _fixture.CreateMany<KeyBinding>(3);
|
||||
settingsService.Setup(x => x.GetCommandKeyBindings()).Returns(new Dictionary<string, ICollection<KeyBinding>>
|
||||
{
|
||||
[nameof(Command.ToggleWindow)] = keyBindings.ToList()
|
||||
});
|
||||
var appServiceConnection = new Mock<IAppServiceConnection>();
|
||||
var trayProcessCommunicationService = new TrayProcessCommunicationService(settingsService.Object);
|
||||
trayProcessCommunicationService.Initialize(appServiceConnection.Object);
|
||||
|
||||
await trayProcessCommunicationService.ResizeTerminalAsync(terminalId, terminalSize);
|
||||
|
||||
appServiceConnection.Verify(x => x.SendMessageAsync(It.Is<ValueSet>(d => (byte)d[MessageKeys.Type] == (byte)MessageIdentifiers.ResizeTerminalRequest)), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Write_Default_SendsWriteDataRequest()
|
||||
{
|
||||
var terminalId = _fixture.Create<byte>();
|
||||
var data = _fixture.Create<byte[]>();
|
||||
var settingsService = new Mock<ISettingsService>();
|
||||
var keyBindings = _fixture.CreateMany<KeyBinding>(3);
|
||||
settingsService.Setup(x => x.GetCommandKeyBindings()).Returns(new Dictionary<string, ICollection<KeyBinding>>
|
||||
{
|
||||
[nameof(Command.ToggleWindow)] = keyBindings.ToList()
|
||||
});
|
||||
var appServiceConnection = new Mock<IAppServiceConnection>();
|
||||
var trayProcessCommunicationService = new TrayProcessCommunicationService(settingsService.Object);
|
||||
trayProcessCommunicationService.Initialize(appServiceConnection.Object);
|
||||
|
||||
await trayProcessCommunicationService.WriteAsync(terminalId, data);
|
||||
|
||||
appServiceConnection.Verify(x => x.SendMessageAsync(It.Is<ValueSet>(d => (byte)d[MessageKeys.Type] == Constants.TerminalBufferRequestIdentifier)), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CloseTerminal_Default_SendsTerminalExitedRequest()
|
||||
{
|
||||
var terminalId = _fixture.Create<byte>();
|
||||
var settingsService = new Mock<ISettingsService>();
|
||||
var keyBindings = _fixture.CreateMany<KeyBinding>(3);
|
||||
settingsService.Setup(x => x.GetCommandKeyBindings()).Returns(new Dictionary<string, ICollection<KeyBinding>>
|
||||
{
|
||||
[nameof(Command.ToggleWindow)] = keyBindings.ToList()
|
||||
});
|
||||
var appServiceConnection = new Mock<IAppServiceConnection>();
|
||||
var trayProcessCommunicationService = new TrayProcessCommunicationService(settingsService.Object);
|
||||
trayProcessCommunicationService.Initialize(appServiceConnection.Object);
|
||||
|
||||
await trayProcessCommunicationService.CloseTerminalAsync(terminalId);
|
||||
|
||||
appServiceConnection.Verify(x => x.SendMessageAsync(It.Is<ValueSet>(d => (byte)d[MessageKeys.Type] == (byte)MessageIdentifiers.TerminalExitedRequest)), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnMessageReceived_TerminalExitedRequest_InvokesTerminalExitedEvent()
|
||||
{
|
||||
var request = new TerminalExitedRequest(_fixture.Create<byte>(), _fixture.Create<int>());
|
||||
|
||||
var receivedExitStatus = (TerminalExitStatus) null;
|
||||
|
||||
var message = new ValueSet
|
||||
{
|
||||
[MessageKeys.Type] = (byte) MessageIdentifiers.TerminalExitedRequest,
|
||||
[MessageKeys.Content] = JsonConvert.SerializeObject(request)
|
||||
};
|
||||
var settingsService = new Mock<ISettingsService>();
|
||||
var keyBindings = _fixture.CreateMany<KeyBinding>(3);
|
||||
settingsService.Setup(x => x.GetCommandKeyBindings()).Returns(new Dictionary<string, ICollection<KeyBinding>>
|
||||
{
|
||||
[nameof(Command.ToggleWindow)] = keyBindings.ToList()
|
||||
});
|
||||
var trayProcessCommunicationService = new TrayProcessCommunicationService(settingsService.Object);
|
||||
var appServiceConnection = new Mock<IAppServiceConnection>();
|
||||
trayProcessCommunicationService.Initialize(appServiceConnection.Object);
|
||||
trayProcessCommunicationService.TerminalExited += (s, status) =>
|
||||
{
|
||||
receivedExitStatus = status;
|
||||
};
|
||||
|
||||
appServiceConnection.Raise(x => x.MessageReceived += null, null, message);
|
||||
|
||||
receivedExitStatus.Should().NotBeNull();
|
||||
receivedExitStatus.TerminalId.Should().Be(request.TerminalId);
|
||||
receivedExitStatus.ExitCode.Should().Be(request.ExitCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnMessageReceived_DisplayTerminalOutputRequest_InvokesCorrectOutputHandler()
|
||||
{
|
||||
var terminalId = _fixture.Create<byte>();
|
||||
var output = _fixture.Create<byte[]>();
|
||||
var receivedOutput = default(byte[]);
|
||||
var message = new ValueSet
|
||||
{
|
||||
[MessageKeys.Type] = Constants.TerminalBufferRequestIdentifier,
|
||||
[MessageKeys.TerminalId] = terminalId,
|
||||
[MessageKeys.Content] = output
|
||||
};
|
||||
var settingsService = new Mock<ISettingsService>();
|
||||
var keyBindings = _fixture.CreateMany<KeyBinding>(3);
|
||||
settingsService.Setup(x => x.GetCommandKeyBindings()).Returns(new Dictionary<string, ICollection<KeyBinding>>
|
||||
{
|
||||
[nameof(Command.ToggleWindow)] = keyBindings.ToList()
|
||||
});
|
||||
var trayProcessCommunicationService = new TrayProcessCommunicationService(settingsService.Object);
|
||||
var appServiceConnection = new Mock<IAppServiceConnection>();
|
||||
trayProcessCommunicationService.Initialize(appServiceConnection.Object);
|
||||
trayProcessCommunicationService.SubscribeForTerminalOutput(terminalId, o =>
|
||||
{
|
||||
receivedOutput = o;
|
||||
});
|
||||
|
||||
appServiceConnection.Raise(x => x.MessageReceived += null, null, message);
|
||||
|
||||
receivedOutput.Should().BeEquivalentTo(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Windows.Storage;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
|
||||
namespace FluentTerminal.App.Services.Adapters
|
||||
{
|
||||
public class ApplicationDataContainerAdapter : IApplicationDataContainer
|
||||
{
|
||||
private readonly ApplicationDataContainer _applicationDataContainer;
|
||||
|
||||
public ApplicationDataContainerAdapter(ApplicationDataContainer applicationDataContainer)
|
||||
{
|
||||
_applicationDataContainer = applicationDataContainer;
|
||||
}
|
||||
|
||||
public void Delete(string key)
|
||||
{
|
||||
_applicationDataContainer.Values.Remove(key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_applicationDataContainer.Values.Clear();
|
||||
}
|
||||
|
||||
public IEnumerable<object> GetAll()
|
||||
{
|
||||
return _applicationDataContainer.Values.Select(x => x.Value);
|
||||
}
|
||||
|
||||
public T ReadValueFromJson<T>(string name, T fallbackValue)
|
||||
{
|
||||
if (_applicationDataContainer.Values.TryGetValue(name, out object value))
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(fallbackValue, default))
|
||||
{
|
||||
fallbackValue = Activator.CreateInstance<T>();
|
||||
}
|
||||
|
||||
JsonConvert.PopulateObject((string)value, fallbackValue);
|
||||
}
|
||||
return fallbackValue;
|
||||
}
|
||||
|
||||
public void SetValue(string key, object value)
|
||||
{
|
||||
_applicationDataContainer.Values[key] = value;
|
||||
}
|
||||
|
||||
public bool TryGetValue(string key, out object value)
|
||||
{
|
||||
return _applicationDataContainer.Values.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public void WriteValueAsJson<T>(string name, T value)
|
||||
{
|
||||
_applicationDataContainer.Values[name] = JsonConvert.SerializeObject(value,
|
||||
PreserveDictionaryKeyCaseContractResolver.SerializerSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public class ApplicationDataContainers
|
||||
{
|
||||
public IApplicationDataContainer LocalSettings { get; set; }
|
||||
public IApplicationDataContainer RoamingSettings { get; set; }
|
||||
public IApplicationDataContainer Themes { get; set; }
|
||||
public IApplicationDataContainer KeyBindings { get; set; }
|
||||
public IApplicationDataContainer ShellProfiles { get; set; }
|
||||
public IApplicationDataContainer SshProfiles { get; set; }
|
||||
public IApplicationDataContainer HistoryContainer { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string ThemesContainerName = "Themes";
|
||||
public const string KeyBindingsContainerName = "KeyBindings";
|
||||
public const string ShellProfilesContainerName = "ShellProfiles";
|
||||
public const string SshProfilesContainerName = "SshProfiles";
|
||||
public const byte TerminalBufferRequestIdentifier = 0;
|
||||
public const string SshCommandName = "ssh";
|
||||
public const string MoshCommandName = "mosh";
|
||||
public const string ExecutedCommandsContainerName = "HistoryContainer";
|
||||
public const string TerminalViewModelStateId = "TerminalViewModelState";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Dialogs
|
||||
{
|
||||
public interface IAboutDialog
|
||||
{
|
||||
Task ShowAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Dialogs
|
||||
{
|
||||
public interface ICreateKeyBindingDialog
|
||||
{
|
||||
Task<KeyBinding> CreateKeyBinding();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using FluentTerminal.Models;
|
||||
|
||||
namespace FluentTerminal.App.Services.Dialogs
|
||||
{
|
||||
public interface ICustomCommandDialog
|
||||
{
|
||||
Task<ShellProfile> GetCustomCommandAsync(ShellProfile input = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Dialogs
|
||||
{
|
||||
public interface IInputDialog
|
||||
{
|
||||
void SetTitle(string title);
|
||||
Task<string> GetInput();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Dialogs
|
||||
{
|
||||
public interface IMessageDialog
|
||||
{
|
||||
string Title { get; set; }
|
||||
string Content { get; set; }
|
||||
|
||||
void AddButton(DialogButton button);
|
||||
|
||||
Task<DialogButton> ShowAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Dialogs
|
||||
{
|
||||
public interface ISshConnectionInfoDialog
|
||||
{
|
||||
Task<SshProfile> GetSshConnectionInfoAsync(SshProfile input = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FluentTerminal.App.Services.EventArgs
|
||||
{
|
||||
public class CancelableEventArgs : System.EventArgs
|
||||
{
|
||||
public bool Cancelled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace FluentTerminal.App.Services.EventArgs
|
||||
{
|
||||
public class NewTabRequestedEventArgs : System.EventArgs
|
||||
{
|
||||
public DragEventArgs DragEventArgs { get; set; }
|
||||
public int Position { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using FluentTerminal.Models;
|
||||
|
||||
namespace FluentTerminal.App.Services.EventArgs
|
||||
{
|
||||
public class NewWindowRequestedEventArgs : System.EventArgs
|
||||
{
|
||||
public ShellProfile Profile { get; }
|
||||
|
||||
public NewWindowRequestedEventArgs(ShellProfile profile) =>
|
||||
Profile = profile ?? throw new ArgumentNullException(nameof(profile));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.Services.Exceptions
|
||||
{
|
||||
public class ParseThemeException : Exception
|
||||
{
|
||||
public ParseThemeException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ParseThemeException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public ParseThemeException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected ParseThemeException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FluentTerminal.App.Services.Exceptions
|
||||
{
|
||||
public class SaveTextFileException : Exception
|
||||
{
|
||||
public SaveTextFileException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public SaveTextFileException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public SaveTextFileException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected SaveTextFileException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="PListNet" Version="3.0.0" />
|
||||
<PackageReference Include="RestSharp" Version="106.10.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
|
||||
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FluentTerminal.Models\FluentTerminal.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows.Foundation.FoundationContract">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Windows.Foundation.UniversalApiContract">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
using FluentTerminal.Models.Enums;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
// This validator is needed because accelerator key has to be member of VirtualKey enum.
|
||||
public interface IAcceleratorKeyValidator
|
||||
{
|
||||
bool Valid(int key);
|
||||
|
||||
bool Valid(ExtendedVirtualKey key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation.Collections;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IAppServiceConnection
|
||||
{
|
||||
event EventHandler<ValueSet> MessageReceived;
|
||||
|
||||
Task<ValueSet> SendMessageAsync(ValueSet message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IApplicationDataContainer
|
||||
{
|
||||
T ReadValueFromJson<T>(string name, T fallbackValue);
|
||||
|
||||
void WriteValueAsJson<T>(string name, T value);
|
||||
|
||||
bool TryGetValue(string key, out object value);
|
||||
|
||||
void SetValue(string key, object value);
|
||||
|
||||
void Delete(string key);
|
||||
|
||||
void Clear();
|
||||
|
||||
IEnumerable<object> GetAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IApplicationLanguageService
|
||||
{
|
||||
IEnumerable<string> Languages { get; }
|
||||
|
||||
void SetLanguage(string language);
|
||||
|
||||
string GetCurrentLanguage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using FluentTerminal.App.Services.EventArgs;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public delegate Task CloseRequestedHandler(object sender, CancelableEventArgs args);
|
||||
|
||||
public interface IApplicationView
|
||||
{
|
||||
event CloseRequestedHandler CloseRequested;
|
||||
event EventHandler Closed;
|
||||
|
||||
int Id { get; }
|
||||
string Title { get; set; }
|
||||
|
||||
Task ExecuteOnUiThreadAsync(Action action, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal,
|
||||
bool enforceNewSchedule = false);
|
||||
|
||||
Task<T> ExecuteOnUiThreadAsync<T>(Func<T> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal,
|
||||
bool enforceNewSchedule = false);
|
||||
|
||||
Task<bool> TryCloseAsync();
|
||||
|
||||
bool ToggleFullScreen();
|
||||
bool IsApiContractPresent(string api, ushort version);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IClipboardService
|
||||
{
|
||||
Task<string> GetTextAsync();
|
||||
|
||||
void SetText(string text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentTerminal.Models;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface ICommandHistoryService
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the most recent <paramref name="top"/> commands from history.
|
||||
/// </summary>
|
||||
/// <param name="includeProfiles">Indicates if never used saved profiles should also be returned.</param>
|
||||
/// <param name="top">Maximal number of items to return.</param>
|
||||
/// <param name="profilesProvider">List of all saved profiles. If this argument isn't specified, the method will
|
||||
/// get the list from <see cref="ISettingsService"/>. The purpose of this argument is to avoid loading the
|
||||
/// profiles from settings again (since it includes file system access and JSON deserialization), if we
|
||||
/// already have them loaded.</param>
|
||||
List<ExecutedCommand> GetHistoryRecentFirst(bool includeProfiles = false, int top = int.MaxValue,
|
||||
Func<List<ShellProfile>> profilesProvider = null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the most used <paramref name="top"/> commands from history.
|
||||
/// </summary>
|
||||
/// <param name="includeProfiles">Indicates if never used saved profiles should also be returned.</param>
|
||||
/// <param name="top">Maximal number of items to return.</param>
|
||||
/// <param name="profilesProvider">List of all saved profiles. If this argument isn't specified, the method will
|
||||
/// get the list from <see cref="ISettingsService"/>. The purpose of this argument is to avoid loading the
|
||||
/// profiles from settings again (since it includes file system access and JSON deserialization), if we
|
||||
/// already have them loaded.</param>
|
||||
List<ExecutedCommand> GetHistoryMostUsedFirst(bool includeProfiles = false, int top = int.MaxValue,
|
||||
Func<List<ShellProfile>> profilesProvider = null);
|
||||
|
||||
void MarkUsed(ShellProfile profile);
|
||||
|
||||
void Delete(ExecutedCommand executedCommand);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IDefaultValueProvider
|
||||
{
|
||||
ApplicationSettings GetDefaultApplicationSettings();
|
||||
|
||||
ICollection<KeyBinding> GetDefaultKeyBindings(Command command);
|
||||
|
||||
Guid GetDefaultShellProfileId();
|
||||
|
||||
IEnumerable<TabTheme> GetDefaultTabThemes();
|
||||
|
||||
TerminalOptions GetDefaultTerminalOptions();
|
||||
|
||||
Guid GetDefaultThemeId();
|
||||
|
||||
IEnumerable<ShellProfile> GetPreinstalledShellProfiles();
|
||||
|
||||
IEnumerable<TerminalTheme> GetPreInstalledThemes();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public enum DialogButton
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
OK,
|
||||
Cancel
|
||||
}
|
||||
|
||||
public interface IDialogService
|
||||
{
|
||||
Task<DialogButton> ShowMessageDialogAsync(string title, string content, params DialogButton[] buttons);
|
||||
|
||||
Task<KeyBinding> ShowCreateKeyBindingDialog();
|
||||
|
||||
Task<string> ShowInputDialogAsync(string title);
|
||||
|
||||
Task<SshProfile> ShowSshConnectionInfoDialogAsync(SshProfile input = null);
|
||||
|
||||
Task<ShellProfile> ShowCustomCommandDialogAsync(ShellProfile input = null);
|
||||
|
||||
Task ShowAboutDialogAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IFileSystemService
|
||||
{
|
||||
Task<File> OpenFileAsync(IEnumerable<string> fileTypes);
|
||||
|
||||
Task<string> BrowseForDirectoryAsync();
|
||||
|
||||
Task SaveTextFileAsync(string name, string fileTypeDescription, string fileType, string content);
|
||||
|
||||
Task<ImageFile> SaveImageInRoamingAsync(ImageFile imageFile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IImageFileSystemService
|
||||
{
|
||||
Task<ImageFile> ImportTemporaryImageFileAsync(IEnumerable<string> fileTypes);
|
||||
|
||||
Task RemoveTemporaryBackgroundThemeImageAsync();
|
||||
|
||||
Task RemoveImportedImageAsync(string fileName);
|
||||
|
||||
string EncodeImage(ImageFile imageFile);
|
||||
|
||||
Task<ImageFile> ImportThemeImageAsync(ImageFile backgroundImage, string encodedImage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IKeyboardCommandService
|
||||
{
|
||||
void RegisterCommandHandler(string command, Action handler);
|
||||
|
||||
void SendCommand(string command);
|
||||
void DeregisterCommandHandler(string command);
|
||||
void ClearCommandHandlers();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface INotificationService
|
||||
{
|
||||
void ShowNotification(string title, string content, string url = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using FluentTerminal.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface ISettingsService
|
||||
{
|
||||
void DeleteShellProfile(Guid id);
|
||||
void DeleteSshProfile(Guid id);
|
||||
void DeleteTheme(Guid id);
|
||||
ApplicationSettings GetApplicationSettings();
|
||||
TerminalTheme GetCurrentTheme();
|
||||
Guid GetCurrentThemeId();
|
||||
ShellProfile GetDefaultShellProfile();
|
||||
Guid GetDefaultShellProfileId();
|
||||
IDictionary<string, ICollection<KeyBinding>> GetCommandKeyBindings();
|
||||
IEnumerable<ShellProfile> GetShellProfiles();
|
||||
IEnumerable<SshProfile> GetSshProfiles();
|
||||
/// <summary>
|
||||
/// Returns union of <see cref="GetShellProfiles"/> and <see cref="GetSshProfiles"/>.
|
||||
/// </summary>
|
||||
IEnumerable<ShellProfile> GetAllProfiles();
|
||||
IEnumerable<TabTheme> GetTabThemes();
|
||||
TerminalOptions GetTerminalOptions();
|
||||
TerminalTheme GetTheme(Guid id);
|
||||
IEnumerable<TerminalTheme> GetThemes();
|
||||
void ResetKeyBindings();
|
||||
void SaveApplicationSettings(ApplicationSettings applicationSettings);
|
||||
void NotifyApplicationSettingsChanged(ApplicationSettings applicationSettings);
|
||||
void SaveCurrentThemeId(Guid id);
|
||||
void SaveDefaultShellProfileId(Guid id);
|
||||
void SaveKeyBindings(string command, ICollection<KeyBinding> keyBindings);
|
||||
void SaveShellProfile(ShellProfile shellProfile, bool newShell = false);
|
||||
void SaveSshProfile(SshProfile sshProfile, bool newShell = false);
|
||||
void SaveTerminalOptions(TerminalOptions terminalOptions);
|
||||
void SaveTheme(TerminalTheme theme, bool newTheme = false);
|
||||
ShellProfile GetShellProfile(Guid id);
|
||||
SshProfile GetSshProfile(Guid id);
|
||||
string ExportSettings();
|
||||
void ImportSettings(string serializedSettings);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using FluentTerminal.Models;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IShellProfileMigrationService
|
||||
{
|
||||
void Migrate(ShellProfile profile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using FluentTerminal.Models.Enums;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IStartupTaskService
|
||||
{
|
||||
Task DisableStartupTaskAsync();
|
||||
Task<StartupTaskStatus> EnableStartupTaskAsync();
|
||||
Task<StartupTaskStatus> GetStatusAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface ISystemFontService
|
||||
{
|
||||
IEnumerable<FontInfo> GetSystemFontFamilies();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using FluentTerminal.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IThemeParser
|
||||
{
|
||||
IEnumerable<string> SupportedFileTypes { get; }
|
||||
|
||||
Task<TerminalTheme> Parse(string fileName, Stream fileContent);
|
||||
|
||||
Task<ExportedTerminalTheme> Import(string fileName, Stream fileContent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IThemeParserFactory
|
||||
{
|
||||
IEnumerable<string> SupportedFileTypes { get; }
|
||||
|
||||
IThemeParser GetParser(string fileType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using FluentTerminal.Models.Responses;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface ITrayProcessCommunicationService
|
||||
{
|
||||
event EventHandler<TerminalExitStatus> TerminalExited;
|
||||
|
||||
void Initialize(IAppServiceConnection appServiceConnection);
|
||||
|
||||
Task<CreateTerminalResponse> CreateTerminalAsync(byte id, TerminalSize size, ShellProfile shellProfile,
|
||||
SessionType sessionType);
|
||||
|
||||
Task<PauseTerminalOutputResponse> PauseTerminalOutputAsync(byte id, bool pause);
|
||||
|
||||
Task ResizeTerminalAsync(byte id, TerminalSize size);
|
||||
|
||||
Task UpdateToggleWindowKeyBindingsAsync();
|
||||
|
||||
Task WriteAsync(byte terminalId, byte[] data);
|
||||
|
||||
void SubscribeForTerminalOutput(byte terminalId, Action<byte[]> callback);
|
||||
|
||||
void UnsubscribeFromTerminalOutput(byte terminalId);
|
||||
|
||||
Task CloseTerminalAsync(byte terminalId);
|
||||
|
||||
byte GetNextTerminalId();
|
||||
|
||||
Task<string> GetUserNameAsync();
|
||||
|
||||
Task SaveTextFileAsync(string path, string content);
|
||||
|
||||
Task<string> GetSshConfigDirAsync();
|
||||
|
||||
Task<string[]> GetFilesFromSshConfigDirAsync();
|
||||
|
||||
Task<bool> CheckFileExistsAsync(string path);
|
||||
|
||||
Task MuteTerminalAsync(bool mute);
|
||||
|
||||
void UpdateSettings(ApplicationSettings settings);
|
||||
|
||||
Task<string> GetCommandPathAsync(string command);
|
||||
|
||||
Task QuitApplicationAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public interface IUpdateService
|
||||
{
|
||||
Task CheckForUpdateAsync(bool notifyNoUpdate = false);
|
||||
Version GetCurrentVersion();
|
||||
Task<Version> GetLatestVersionAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,672 @@
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Windows.Foundation.Metadata;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class DefaultValueProvider : IDefaultValueProvider
|
||||
{
|
||||
public ApplicationSettings GetDefaultApplicationSettings()
|
||||
{
|
||||
var logDirectoryPath = string.Empty;
|
||||
try
|
||||
{
|
||||
// Accessing ApplicationData.Current during run of unit tests causes
|
||||
// "System.InvalidOperationException : The process has no package identity" exception.
|
||||
logDirectoryPath = ApplicationData.Current.LocalCacheFolder.Path;
|
||||
} catch (InvalidOperationException) { }
|
||||
|
||||
return new ApplicationSettings
|
||||
{
|
||||
ConfirmClosingTabs = false,
|
||||
ConfirmClosingWindows = false,
|
||||
UnderlineSelectedTab = false,
|
||||
InactiveTabColorMode = InactiveTabColorMode.Background,
|
||||
NewTerminalLocation = NewTerminalLocation.Tab,
|
||||
TabWindowCascadingAppMenu = true,
|
||||
TabsPosition = TabsPosition.Top,
|
||||
CopyOnSelect = false,
|
||||
MouseMiddleClickAction = MouseAction.None,
|
||||
MouseRightClickAction = MouseAction.ContextMenu,
|
||||
ShowNewOutputIndicator = false,
|
||||
EnableTrayIcon = true,
|
||||
ShowCustomTitleInTitlebar = true,
|
||||
UseMoshByDefault = true,
|
||||
AutoFallbackToWindowsUsernameInLinks = true,
|
||||
RTrimCopiedLines = true,
|
||||
MuteTerminalBeeps = true,
|
||||
EnableLogging = false,
|
||||
PrintableOutputOnly = true,
|
||||
LogDirectoryPath = logDirectoryPath,
|
||||
UseConPty = true,
|
||||
ShowTextCopied = false
|
||||
};
|
||||
}
|
||||
|
||||
public ICollection<KeyBinding> GetDefaultKeyBindings(Command command)
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case Command.ToggleWindow:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.ToggleWindow),
|
||||
Key = (int)ExtendedVirtualKey.Scroll
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NextTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NextTab),
|
||||
Ctrl = true,
|
||||
Key = (int)ExtendedVirtualKey.Tab
|
||||
}
|
||||
};
|
||||
|
||||
case Command.PreviousTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.PreviousTab),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.Tab
|
||||
}
|
||||
};
|
||||
|
||||
case Command.SwitchToTerm1:
|
||||
case Command.SwitchToTerm2:
|
||||
case Command.SwitchToTerm3:
|
||||
case Command.SwitchToTerm4:
|
||||
case Command.SwitchToTerm5:
|
||||
case Command.SwitchToTerm6:
|
||||
case Command.SwitchToTerm7:
|
||||
case Command.SwitchToTerm8:
|
||||
case Command.SwitchToTerm9:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = command.ToString(),
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.Number1 + (command - Command.SwitchToTerm1)
|
||||
}
|
||||
};
|
||||
|
||||
case Command.DuplicateTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.DuplicateTab),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.D
|
||||
}
|
||||
};
|
||||
|
||||
case Command.ReconnectTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.ReconnectTab),
|
||||
Ctrl = true,
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.R
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NewTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NewTab),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.T
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NewSshTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NewSshTab),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.Y
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NewSshWindow:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NewSshWindow),
|
||||
Ctrl = true,
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.Y
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NewCustomCommandTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NewCustomCommandTab),
|
||||
Ctrl = true,
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.T
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NewCustomCommandWindow:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NewCustomCommandWindow),
|
||||
Ctrl = true,
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.N
|
||||
}
|
||||
};
|
||||
|
||||
case Command.ChangeTabTitle:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.ChangeTabTitle),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.R
|
||||
}
|
||||
};
|
||||
|
||||
case Command.CloseTab:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.CloseTab),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.W
|
||||
}
|
||||
};
|
||||
|
||||
case Command.NewWindow:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.NewWindow),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.N
|
||||
}
|
||||
};
|
||||
|
||||
case Command.ShowSettings:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.ShowSettings),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
// I've had to replace ExtendedVirtualKey.Comma because it isn't a member of VirtualKey enum, thus cannot be shown in menu.
|
||||
Key = (int)ExtendedVirtualKey.S
|
||||
}
|
||||
};
|
||||
|
||||
case Command.Copy:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.Copy),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.C
|
||||
}
|
||||
};
|
||||
|
||||
case Command.Paste:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.Paste),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.V
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
case Command.PasteWithoutNewlines:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.PasteWithoutNewlines),
|
||||
Ctrl = true,
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.V
|
||||
}
|
||||
};
|
||||
|
||||
case Command.Search:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.Search),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.F
|
||||
}
|
||||
};
|
||||
|
||||
case Command.ToggleFullScreen:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.ToggleFullScreen),
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.Enter
|
||||
},
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.ToggleFullScreen),
|
||||
Key = (int)ExtendedVirtualKey.F11
|
||||
}
|
||||
};
|
||||
|
||||
case Command.SelectAll:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.SelectAll),
|
||||
Ctrl = true,
|
||||
Shift = true,
|
||||
Key = (int)ExtendedVirtualKey.A
|
||||
}
|
||||
};
|
||||
|
||||
case Command.Clear:
|
||||
return new List<KeyBinding>
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = nameof(Command.Clear),
|
||||
Ctrl = true,
|
||||
Alt = true,
|
||||
Key = (int)ExtendedVirtualKey.L
|
||||
}
|
||||
};
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Default keybindings for Command '{command}' are missing");
|
||||
}
|
||||
}
|
||||
|
||||
public Guid GetDefaultShellProfileId()
|
||||
{
|
||||
return Guid.Parse("813f2298-210a-481a-bdbf-c17bc637a3e2");
|
||||
}
|
||||
|
||||
public IEnumerable<TabTheme> GetDefaultTabThemes()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new TabTheme
|
||||
{
|
||||
Id = 0,
|
||||
Name = I18N.Translate("TabTheme.None"),
|
||||
BackgroundOpacity = double.NaN,
|
||||
BackgroundPointerOverOpacity = double.NaN,
|
||||
BackgroundPressedOpacity = double.NaN,
|
||||
BackgroundSelectedOpacity = double.NaN,
|
||||
BackgroundSelectedPointerOverOpacity = double.NaN,
|
||||
BackgroundSelectedPressedOpacity = double.NaN
|
||||
},
|
||||
new TabTheme
|
||||
{
|
||||
Id = 1,
|
||||
Name = I18N.Translate("TabTheme.Red"),
|
||||
Color = "#E81123"
|
||||
},
|
||||
new TabTheme
|
||||
{
|
||||
Id = 2,
|
||||
Name = I18N.Translate("TabTheme.Green"),
|
||||
Color = "#10893E"
|
||||
},
|
||||
new TabTheme
|
||||
{
|
||||
Id = 3,
|
||||
Name = I18N.Translate("TabTheme.Blue"),
|
||||
Color = "#0078D7"
|
||||
},
|
||||
new TabTheme
|
||||
{
|
||||
Id = 4,
|
||||
Name = I18N.Translate("TabTheme.Purple"),
|
||||
Color = "#881798"
|
||||
},
|
||||
new TabTheme
|
||||
{
|
||||
Id = 5,
|
||||
Name = I18N.Translate("TabTheme.Orange"),
|
||||
Color = "#FF8C00"
|
||||
},
|
||||
new TabTheme
|
||||
{
|
||||
Id = 6,
|
||||
Name = I18N.Translate("TabTheme.Teal"),
|
||||
Color = "#00B7C3"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public TerminalOptions GetDefaultTerminalOptions()
|
||||
{
|
||||
return new TerminalOptions
|
||||
{
|
||||
BellStyle = BellStyle.None,
|
||||
CursorBlink = true,
|
||||
CursorStyle = CursorStyle.Block,
|
||||
ScrollBarStyle = ScrollBarStyle.Hidden,
|
||||
FontFamily = "Consolas",
|
||||
FontSize = 13,
|
||||
FontWeight = 400,
|
||||
BackgroundOpacity = 0.8,
|
||||
Padding = 12,
|
||||
ScrollBackLimit = 1000,
|
||||
WordSeparator = " ()[]{}:;|│!&*<>@"&squo;",
|
||||
UseAcrylicBackground = true
|
||||
};
|
||||
}
|
||||
|
||||
public Guid GetDefaultThemeId()
|
||||
{
|
||||
return Guid.Parse("281e4352-bb50-47b7-a691-2b13830df95e");
|
||||
}
|
||||
|
||||
public IEnumerable<ShellProfile> GetPreinstalledShellProfiles()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new ShellProfile
|
||||
{
|
||||
Id = GetDefaultShellProfileId(),
|
||||
Name = "Powershell",
|
||||
MigrationVersion = ShellProfile.CurrentMigrationVersion,
|
||||
Arguments = string.Empty,
|
||||
Location = @"C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe",
|
||||
PreInstalled = true,
|
||||
WorkingDirectory = string.Empty,
|
||||
UseConPty = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8), // Windows 10 1903+
|
||||
UseBuffer = false,
|
||||
EnvironmentVariables = new Dictionary<string, string>
|
||||
{
|
||||
["TERM"] = "xterm-256color"
|
||||
},
|
||||
KeyBindings = new []
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = GetDefaultShellProfileId().ToString(),
|
||||
Ctrl=true,
|
||||
Alt=true,
|
||||
Shift=false,
|
||||
Meta=false,
|
||||
Key=(int)ExtendedVirtualKey.Number1
|
||||
}
|
||||
}
|
||||
},
|
||||
new ShellProfile
|
||||
{
|
||||
Id = Guid.Parse("ab942a61-7673-4755-9bd8-765aff91d9a3"),
|
||||
Name = "CMD",
|
||||
MigrationVersion = ShellProfile.CurrentMigrationVersion,
|
||||
Arguments = string.Empty,
|
||||
Location = @"C:\Windows\System32\cmd.exe",
|
||||
PreInstalled = true,
|
||||
WorkingDirectory = string.Empty,
|
||||
UseConPty = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7), // Windows 10 1809+
|
||||
UseBuffer = true,
|
||||
EnvironmentVariables = new Dictionary<string, string>
|
||||
{
|
||||
["TERM"] = "xterm-256color"
|
||||
},
|
||||
KeyBindings = new []
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = "ab942a61-7673-4755-9bd8-765aff91d9a3",
|
||||
Ctrl=true,
|
||||
Alt=true,
|
||||
Shift=false,
|
||||
Meta=false,
|
||||
Key=(int)ExtendedVirtualKey.Number2
|
||||
}
|
||||
}
|
||||
},
|
||||
new ShellProfile
|
||||
{
|
||||
Id= Guid.Parse("e5785ad6-584f-40cb-bdcd-d5b3b3953e7f"),
|
||||
Name = "WSL",
|
||||
MigrationVersion = ShellProfile.CurrentMigrationVersion,
|
||||
Arguments = string.Empty,
|
||||
Location = @"C:\windows\system32\wsl.exe",
|
||||
PreInstalled = true,
|
||||
WorkingDirectory = string.Empty,
|
||||
UseConPty = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7), // Windows 10 1809+
|
||||
UseBuffer = true, //TODO: Set to false if the buffer causes issues with WSL.
|
||||
EnvironmentVariables = new Dictionary<string, string>
|
||||
{
|
||||
["TERM"] = "xterm-256color"
|
||||
},
|
||||
KeyBindings = new []
|
||||
{
|
||||
new KeyBinding
|
||||
{
|
||||
Command = "e5785ad6-584f-40cb-bdcd-d5b3b3953e7f",
|
||||
Ctrl=true,
|
||||
Alt=true,
|
||||
Shift=false,
|
||||
Meta=false,
|
||||
Key=(int)ExtendedVirtualKey.Number3
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public IEnumerable<TerminalTheme> GetPreInstalledThemes()
|
||||
{
|
||||
var defaultXterm = new TerminalTheme
|
||||
{
|
||||
Id = GetDefaultThemeId(),
|
||||
Author = "xterm.js",
|
||||
Name = "Xterm.js Default",
|
||||
PreInstalled = true,
|
||||
Colors = new TerminalColors
|
||||
{
|
||||
Black = "#2e3436",
|
||||
Red = "#cc0000",
|
||||
Green = "#4e9a06",
|
||||
Yellow = "#c4a000",
|
||||
Blue = "#3465a4",
|
||||
Magenta = "#75507b",
|
||||
Cyan = "#06989a",
|
||||
White = "#d3d7cf",
|
||||
BrightBlack = "#555753",
|
||||
BrightRed = "#ef2929",
|
||||
BrightGreen = "#8ae234",
|
||||
BrightYellow = "#fce94f",
|
||||
BrightBlue = "#729fcf",
|
||||
BrightMagenta = "#ad7fa8",
|
||||
BrightCyan = "#34e2e2",
|
||||
BrightWhite = "#eeeeec",
|
||||
Foreground = "#ffffff",
|
||||
Background = "#000000",
|
||||
Cursor = "#ffffff",
|
||||
CursorAccent = "#000000",
|
||||
Selection = "rgba(255, 255, 255, 0.3)"
|
||||
}
|
||||
};
|
||||
|
||||
var powerShell = new TerminalTheme
|
||||
{
|
||||
Id = Guid.Parse("3571ce1b-31ce-4cf7-ae15-e0bff70c3eea"),
|
||||
Author = "Microsoft",
|
||||
Name = "PowerShell",
|
||||
PreInstalled = true,
|
||||
Colors = new TerminalColors
|
||||
{
|
||||
Black = "#000000",
|
||||
Red = "#800000",
|
||||
Green = "#008000",
|
||||
Yellow = "#EEEDF0",
|
||||
Blue = "#000080",
|
||||
Magenta = "#012456",
|
||||
Cyan = "#008080",
|
||||
White = "#c0c0c0",
|
||||
BrightBlack = "#808080",
|
||||
BrightRed = "#ff0000",
|
||||
BrightGreen = "#00ff00",
|
||||
BrightYellow = "#ffff00",
|
||||
BrightBlue = "#0000ff",
|
||||
BrightMagenta = "#ff00ff",
|
||||
BrightCyan = "#00ffff",
|
||||
BrightWhite = "#ffffff",
|
||||
Foreground = "#ffffff",
|
||||
Background = "#012456",
|
||||
Cursor = "#fedba9",
|
||||
CursorAccent = "#000000",
|
||||
Selection = "rgba(254, 219, 169, 0.3)"
|
||||
}
|
||||
};
|
||||
|
||||
var homebrew = new TerminalTheme
|
||||
{
|
||||
Id = Guid.Parse("5f034210-067b-40e2-b9c9-6a25eb6fb8e6"),
|
||||
Author = "Hans Kokx",
|
||||
Name = "Homebrew",
|
||||
PreInstalled = true,
|
||||
Colors = new TerminalColors
|
||||
{
|
||||
Black = "#000000",
|
||||
Red = "#A0160B",
|
||||
Green = "#00AF21",
|
||||
Yellow = "#A1A222",
|
||||
Blue = "#192AB7",
|
||||
Magenta = "#AA2FAE",
|
||||
Cyan = "#12B1BC",
|
||||
White = "#BBB5AF",
|
||||
BrightBlack = "#747876",
|
||||
BrightRed = "#E52213",
|
||||
BrightGreen = "#00D92B",
|
||||
BrightYellow = "#E6E435",
|
||||
BrightBlue = "#283EF9",
|
||||
BrightMagenta = "#EB43E6",
|
||||
BrightCyan = "#15E7E8",
|
||||
BrightWhite = "#E9E9E9",
|
||||
Foreground = "#00D92B",
|
||||
Background = "#000000",
|
||||
Cursor = "#00D92B",
|
||||
CursorAccent = "#000000",
|
||||
Selection = "#4CFFFFFF"
|
||||
}
|
||||
};
|
||||
|
||||
var tomorrow = new TerminalTheme
|
||||
{
|
||||
Id = Guid.Parse("0cbbf805-fa86-4be5-ac51-75f3054dcc3a"),
|
||||
Author = "Chris Kempson",
|
||||
Name = "Tomorrow",
|
||||
PreInstalled = true,
|
||||
Colors = new TerminalColors
|
||||
{
|
||||
Foreground = "#4D4D4C",
|
||||
Background = "#FFFFFF",
|
||||
Cursor = "#4D4D4C",
|
||||
CursorAccent = "#FFFFFF",
|
||||
Selection = "rgba(214, 214, 214, 0.5)",
|
||||
Black = "#000000",
|
||||
Red = "#C82829",
|
||||
Green = "#718C00",
|
||||
Yellow = "#EAB700",
|
||||
Blue = "#4271AE",
|
||||
Magenta = "#8959A8",
|
||||
Cyan = "#3E999F",
|
||||
White = "#FFFFFF",
|
||||
BrightBlack = "#000000",
|
||||
BrightRed = "#C82829",
|
||||
BrightGreen = "#718C00",
|
||||
BrightYellow = "#EAB700",
|
||||
BrightBlue = "#4271AE",
|
||||
BrightMagenta = "#8959A8",
|
||||
BrightCyan = "#3E999F",
|
||||
BrightWhite = "#FFFFFF"
|
||||
}
|
||||
};
|
||||
|
||||
var ubuntu = new TerminalTheme
|
||||
{
|
||||
Id = Guid.Parse("32519543-bf94-4db6-92a1-7bcec3966c82"),
|
||||
Author = "Canonical",
|
||||
Name = "Ubuntu Bash",
|
||||
PreInstalled = true,
|
||||
Colors = new TerminalColors
|
||||
{
|
||||
Foreground = "#EEEEEE",
|
||||
Background = "#300A24",
|
||||
Cursor = "#CFF5DB",
|
||||
CursorAccent = "#000000",
|
||||
Selection = "#4DABEDC1",
|
||||
Black = "#300A24",
|
||||
Red = "#CC0000",
|
||||
Green = "#4E9A06",
|
||||
Yellow = "#C4A000",
|
||||
Blue = "#3465A4",
|
||||
Magenta = "#75507B",
|
||||
Cyan = "#06989A",
|
||||
White = "#D3D7CF",
|
||||
BrightBlack = "#554E53",
|
||||
BrightRed = "#EF2929",
|
||||
BrightGreen = "#8AE234",
|
||||
BrightYellow = "#FCE94F",
|
||||
BrightBlue = "#729FCF",
|
||||
BrightMagenta = "#AD7FA8",
|
||||
BrightCyan = "#34E2E2",
|
||||
BrightWhite = "#EEEEEE"
|
||||
}
|
||||
};
|
||||
|
||||
return new[] { defaultXterm, powerShell, homebrew, tomorrow, ubuntu };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using FluentTerminal.App.Services.Dialogs;
|
||||
using FluentTerminal.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
private readonly Func<IMessageDialog> _messageDialogFactory;
|
||||
private readonly Func<ICreateKeyBindingDialog> _createKeyBindingDialogFactory;
|
||||
private readonly Func<IInputDialog> _inputDialogFactory;
|
||||
private readonly Func<ISshConnectionInfoDialog> _sshConnectionInfoDialogFactory;
|
||||
private readonly Func<ICustomCommandDialog> _customCommandDialogFactory;
|
||||
private readonly Func<IAboutDialog> _aboutDialogFactory;
|
||||
|
||||
public DialogService(Func<IMessageDialog> messageDialogFactory, Func<ICreateKeyBindingDialog> createKeyBindingDialogFactory,
|
||||
Func<IInputDialog> inputDialogFactory, Func<ISshConnectionInfoDialog> sshConnectionInfoDialogFactory,
|
||||
Func<ICustomCommandDialog> customCommandDialogFactory,
|
||||
Func<IAboutDialog> aboutDialogFactory)
|
||||
{
|
||||
_messageDialogFactory = messageDialogFactory;
|
||||
_createKeyBindingDialogFactory = createKeyBindingDialogFactory;
|
||||
_inputDialogFactory = inputDialogFactory;
|
||||
_sshConnectionInfoDialogFactory = sshConnectionInfoDialogFactory;
|
||||
_customCommandDialogFactory = customCommandDialogFactory;
|
||||
_aboutDialogFactory = aboutDialogFactory;
|
||||
}
|
||||
|
||||
public Task<KeyBinding> ShowCreateKeyBindingDialog()
|
||||
{
|
||||
var dialog = _createKeyBindingDialogFactory();
|
||||
|
||||
return dialog.CreateKeyBinding();
|
||||
}
|
||||
|
||||
public Task<DialogButton> ShowMessageDialogAsync(string title, string content, params DialogButton[] buttons)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(title));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(content))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
|
||||
if (buttons.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("Must not be empty", nameof(buttons));
|
||||
}
|
||||
|
||||
var dialog = _messageDialogFactory();
|
||||
dialog.Content = content;
|
||||
dialog.Title = title;
|
||||
|
||||
foreach (var button in buttons)
|
||||
{
|
||||
dialog.AddButton(button);
|
||||
}
|
||||
|
||||
return dialog.ShowAsync();
|
||||
}
|
||||
|
||||
public Task<string> ShowInputDialogAsync(string title)
|
||||
{
|
||||
var dialog = _inputDialogFactory.Invoke();
|
||||
dialog.SetTitle(title);
|
||||
|
||||
return dialog.GetInput();
|
||||
}
|
||||
|
||||
public Task<SshProfile> ShowSshConnectionInfoDialogAsync(SshProfile input = null) =>
|
||||
_sshConnectionInfoDialogFactory().GetSshConnectionInfoAsync(input);
|
||||
|
||||
public Task<ShellProfile> ShowCustomCommandDialogAsync(ShellProfile input = null) =>
|
||||
_customCommandDialogFactory().GetCustomCommandAsync(input);
|
||||
|
||||
public Task ShowAboutDialogAsync()
|
||||
{
|
||||
var dialog = _aboutDialogFactory();
|
||||
|
||||
return dialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using FluentTerminal.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class FluentTerminalThemeParser : IThemeParser
|
||||
{
|
||||
public IEnumerable<string> SupportedFileTypes { get; } = new[] { ".flutecolors" };
|
||||
|
||||
public Task<ExportedTerminalTheme> Import(string fileName, Stream fileContent)
|
||||
{
|
||||
return DeserializeThemeAsync<ExportedTerminalTheme>(fileName, fileContent);
|
||||
}
|
||||
|
||||
public Task<TerminalTheme> Parse(string fileName, Stream fileContent)
|
||||
{
|
||||
return DeserializeThemeAsync<TerminalTheme>(fileName, fileContent);
|
||||
}
|
||||
|
||||
private async Task<T> DeserializeThemeAsync<T>(string fileName, Stream fileContent)
|
||||
where T : TerminalTheme
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
|
||||
if (fileContent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileContent));
|
||||
}
|
||||
|
||||
using (var streamReader = new StreamReader(fileContent))
|
||||
{
|
||||
var content = await streamReader.ReadToEndAsync().ConfigureAwait(false);
|
||||
var theme = JsonConvert.DeserializeObject<T>(content);
|
||||
|
||||
theme.PreInstalled = false;
|
||||
theme.Id = Guid.NewGuid();
|
||||
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
using FluentTerminal.App.Services.Exceptions;
|
||||
using FluentTerminal.Models;
|
||||
using PListNet;
|
||||
using PListNet.Nodes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class ITermThemeParser : IThemeParser
|
||||
{
|
||||
private const byte Opacity30Percent = 77;
|
||||
|
||||
public IEnumerable<string> SupportedFileTypes { get; } = new[] { ".itermcolors" };
|
||||
|
||||
private static class ITermThemeKeys
|
||||
{
|
||||
public const string Ansi0Color = "Ansi 0 Color";
|
||||
public const string Ansi1Color = "Ansi 1 Color";
|
||||
public const string Ansi2Color = "Ansi 2 Color";
|
||||
public const string Ansi3Color = "Ansi 3 Color";
|
||||
public const string Ansi4Color = "Ansi 4 Color";
|
||||
public const string Ansi5Color = "Ansi 5 Color";
|
||||
public const string Ansi6Color = "Ansi 6 Color";
|
||||
public const string Ansi7Color = "Ansi 7 Color";
|
||||
public const string Ansi8Color = "Ansi 8 Color";
|
||||
public const string Ansi9Color = "Ansi 9 Color";
|
||||
public const string Ansi10Color = "Ansi 10 Color";
|
||||
public const string Ansi11Color = "Ansi 11 Color";
|
||||
public const string Ansi12Color = "Ansi 12 Color";
|
||||
public const string Ansi13Color = "Ansi 13 Color";
|
||||
public const string Ansi14Color = "Ansi 14 Color";
|
||||
public const string Ansi15Color = "Ansi 15 Color";
|
||||
|
||||
public const string BackgroundColor = "Background Color";
|
||||
//public const string BoldColor = "Bold Color";
|
||||
public const string CursorColor = "Cursor Color";
|
||||
public const string CursorTextColor = "Cursor Text Color";
|
||||
public const string ForegroundColor = "Foreground Color";
|
||||
public const string SelectedTextColor = "Selected Text Color";
|
||||
public const string SelectionColor = "Selection Color";
|
||||
}
|
||||
|
||||
private static class ITermThemeColorKeys
|
||||
{
|
||||
public const string BlueComponent = "Blue Component";
|
||||
public const string GreenComponent = "Green Component";
|
||||
public const string RedComponent = "Red Component";
|
||||
}
|
||||
|
||||
public Task<TerminalTheme> Parse(string fileName, Stream fileContent)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
|
||||
if (fileContent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileContent));
|
||||
}
|
||||
|
||||
var node = PList.Load(fileContent) as DictionaryNode ?? throw new ParseThemeException("Root node was not a dictionary.");
|
||||
|
||||
return Task.FromResult(new TerminalTheme
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(fileName),
|
||||
Colors = GetColors(node),
|
||||
Id = Guid.NewGuid(),
|
||||
PreInstalled = false
|
||||
});
|
||||
}
|
||||
|
||||
private TerminalColors GetColors(DictionaryNode themeDictionary)
|
||||
{
|
||||
return new TerminalColors
|
||||
{
|
||||
Background = GetColorString(themeDictionary[ITermThemeKeys.BackgroundColor]),
|
||||
Foreground = GetColorString(themeDictionary[ITermThemeKeys.ForegroundColor]),
|
||||
Cursor = GetColorString(themeDictionary[ITermThemeKeys.CursorColor]),
|
||||
CursorAccent = GetColorString(themeDictionary[ITermThemeKeys.CursorTextColor]),
|
||||
Selection = GetColorString(themeDictionary[ITermThemeKeys.SelectionColor], Opacity30Percent),
|
||||
SelectionForeground = GetColorString(themeDictionary[ITermThemeKeys.SelectedTextColor]),
|
||||
SelectionBackground = GetColorString(themeDictionary[ITermThemeKeys.SelectionColor]),
|
||||
Black = GetColorString(themeDictionary[ITermThemeKeys.Ansi0Color]),
|
||||
Red = GetColorString(themeDictionary[ITermThemeKeys.Ansi1Color]),
|
||||
Green = GetColorString(themeDictionary[ITermThemeKeys.Ansi2Color]),
|
||||
Yellow = GetColorString(themeDictionary[ITermThemeKeys.Ansi3Color]),
|
||||
Blue = GetColorString(themeDictionary[ITermThemeKeys.Ansi4Color]),
|
||||
Magenta = GetColorString(themeDictionary[ITermThemeKeys.Ansi5Color]),
|
||||
Cyan = GetColorString(themeDictionary[ITermThemeKeys.Ansi6Color]),
|
||||
White = GetColorString(themeDictionary[ITermThemeKeys.Ansi7Color]),
|
||||
BrightBlack = GetColorString(themeDictionary[ITermThemeKeys.Ansi8Color]),
|
||||
BrightRed = GetColorString(themeDictionary[ITermThemeKeys.Ansi9Color]),
|
||||
BrightGreen = GetColorString(themeDictionary[ITermThemeKeys.Ansi10Color]),
|
||||
BrightYellow = GetColorString(themeDictionary[ITermThemeKeys.Ansi11Color]),
|
||||
BrightBlue = GetColorString(themeDictionary[ITermThemeKeys.Ansi12Color]),
|
||||
BrightMagenta = GetColorString(themeDictionary[ITermThemeKeys.Ansi13Color]),
|
||||
BrightCyan = GetColorString(themeDictionary[ITermThemeKeys.Ansi14Color]),
|
||||
BrightWhite = GetColorString(themeDictionary[ITermThemeKeys.Ansi15Color]),
|
||||
};
|
||||
}
|
||||
|
||||
private string GetColorString(PNode colorNode, byte alpha = Byte.MaxValue)
|
||||
{
|
||||
var dictionaryNode = colorNode as DictionaryNode ?? throw new ParseThemeException("Color node was not a dictionary");
|
||||
|
||||
var red = dictionaryNode[ITermThemeColorKeys.RedComponent] as RealNode ?? throw new ParseThemeException("Red node value was not a real number");
|
||||
var green = dictionaryNode[ITermThemeColorKeys.GreenComponent] as RealNode ?? throw new ParseThemeException("Green node value was not a real number");
|
||||
var blue = dictionaryNode[ITermThemeColorKeys.BlueComponent] as RealNode ?? throw new ParseThemeException("Blue node value was not a real number");
|
||||
|
||||
if (alpha == byte.MaxValue)
|
||||
{
|
||||
return $"#{GetByteValue(red):X2}{GetByteValue(green):X2}{GetByteValue(blue):X2}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"rgba({GetByteValue(red):G}, {GetByteValue(green):G}, {GetByteValue(blue):G}, {ToDoubleString(alpha)})";
|
||||
}
|
||||
}
|
||||
|
||||
private byte GetByteValue(RealNode node)
|
||||
{
|
||||
var doubleValue = node.Value * Byte.MaxValue;
|
||||
|
||||
return Convert.ToByte(doubleValue);
|
||||
}
|
||||
|
||||
private static string ToDoubleString(byte alpha)
|
||||
{
|
||||
return (alpha / 256.0).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public Task<ExportedTerminalTheme> Import(string fileName, Stream fileContent)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
|
||||
if (fileContent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileContent));
|
||||
}
|
||||
|
||||
var node = PList.Load(fileContent) as DictionaryNode ?? throw new ParseThemeException("Root node was not a dictionary.");
|
||||
|
||||
var terminalTheme = new TerminalTheme
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(fileName),
|
||||
Colors = GetColors(node),
|
||||
Id = Guid.NewGuid(),
|
||||
PreInstalled = false
|
||||
};
|
||||
|
||||
return Task.FromResult(new ExportedTerminalTheme(terminalTheme, string.Empty));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using FluentTerminal.Models.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class KeyboardCommandService : IKeyboardCommandService
|
||||
{
|
||||
private readonly Dictionary<string, Action> _commandHandlers = new Dictionary<string, Action>();
|
||||
|
||||
public void RegisterCommandHandler(string command, Action handler)
|
||||
{
|
||||
if (_commandHandlers.ContainsKey(command))
|
||||
{
|
||||
throw new InvalidOperationException("command already registered");
|
||||
}
|
||||
|
||||
_commandHandlers[command] = handler ?? throw new ArgumentNullException(nameof(handler));
|
||||
}
|
||||
|
||||
public void DeregisterCommandHandler(string command)
|
||||
{
|
||||
if (_commandHandlers.ContainsKey(command))
|
||||
{
|
||||
_commandHandlers.Remove(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendCommand(string command)
|
||||
{
|
||||
if (_commandHandlers.TryGetValue(command, out Action handler))
|
||||
{
|
||||
handler.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
// already registered by SystemTray's ToggleWindowService
|
||||
if (command == nameof(Command.ToggleWindow))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw new KeyNotFoundException($"No handler registered for command: {command}");
|
||||
}
|
||||
|
||||
public void ClearCommandHandlers()
|
||||
{
|
||||
_commandHandlers.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentTerminal.Models;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
// The purpose of this class is to ensure backward compatibility of mosh profiles and command history
|
||||
// TODO: This class should be probably deleted in few months or so
|
||||
public static class MoshBackwardCompatibility
|
||||
{
|
||||
private static readonly string MoshCommandExe = $"{Constants.MoshCommandName}.exe";
|
||||
|
||||
private static readonly Regex OldFormatRx = new Regex(@".+\s(?<ports>\d{1,5}:\d{1,5})$", RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex TargetRx =
|
||||
new Regex(@"(^|\s+)(?<user>[^\s@;]+)@(?<host>[^\s@:]+)(:(?<port>\d{1,5}))?\s+", RegexOptions.Compiled);
|
||||
|
||||
private static bool IsMoshProfile(ShellProfile profile) =>
|
||||
Constants.MoshCommandName.Equals(profile.Location, StringComparison.OrdinalIgnoreCase) ||
|
||||
MoshCommandExe.Equals(profile.Location, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the profile contains obsolete mosh syntax, and changes it if it does.
|
||||
/// </summary>
|
||||
/// <param name="profile">The profile. Note that the method doesn't change the input profile at all, but creates and
|
||||
/// returns its clone if there's something to change.</param>
|
||||
/// <remarks>
|
||||
/// The method actually checks if <see cref="ShellProfile.Arguments"/> of the input <paramref name="profile"/> is in
|
||||
/// obsolete <c>mosh</c> format <c>[ssh_arguments] [target] [mosh_port_range]</c>, and if it is changes it to the new
|
||||
/// format <c>--ssh="[ssh_arguments]" -p [mosh_ports] [target]</c>.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// If the method detected that the input profile is obsolete mosh profile, it will create its clone with the updated
|
||||
/// command line arguments, and return it. Otherwise it will simply return unchanged input profile (the same reference
|
||||
/// as the input profile). It allows us to simply check if anything is changed by comparing the input and output
|
||||
/// profiles for reference equality.
|
||||
/// </returns>
|
||||
public static ShellProfile FixProfile(ShellProfile profile)
|
||||
{
|
||||
// If there aren't any arguments, or if the profile isn't a mosh profile, there's nothing to do. Just return.
|
||||
if (string.IsNullOrWhiteSpace(profile.Arguments) || !IsMoshProfile(profile)) return profile;
|
||||
|
||||
var arguments = profile.Arguments.Trim();
|
||||
|
||||
var moshPortsMatch = OldFormatRx.Match(arguments);
|
||||
|
||||
if (!moshPortsMatch.Success) return profile;// Arguments don't end with mosh ports (i.e. 60000:61000), so it isn't an obsolete format.
|
||||
|
||||
var targetMatches = TargetRx.Matches(arguments);
|
||||
|
||||
if (targetMatches.Count != 1) return profile;// Target part (user@host:port) not found or found multiple times. Cannot reliably determine the target, so don't change.
|
||||
|
||||
var targetMatch = targetMatches[0];
|
||||
|
||||
// Removing [mosh_ports] from the original arguments
|
||||
arguments = arguments.Substring(0, arguments.Length - moshPortsMatch.Groups["ports"].Length).Trim();
|
||||
|
||||
var newProfile = profile.Clone();
|
||||
|
||||
// Removing [target] from the original arguments, thus getting "pure" ssh arguments
|
||||
var sshArguments = targetMatch.Index > 0 ? arguments.Substring(0, targetMatch.Index).Trim() : string.Empty;
|
||||
|
||||
if (targetMatch.Index + targetMatch.Length < arguments.Length)
|
||||
{
|
||||
sshArguments += $" {arguments.Substring(targetMatch.Index + targetMatch.Length).Trim()}";
|
||||
}
|
||||
|
||||
// If the ssh port is defined in the original target (i.e. user@host:port), which was allowed in the obsolete mosh, extracting the port part into a separate ssh argument
|
||||
if (targetMatch.Groups["port"].Success && uint.TryParse(targetMatch.Groups["port"].Value, out var port) &&
|
||||
port != SshProfile.DefaultSshPort)
|
||||
{
|
||||
sshArguments += $" -p {targetMatch.Groups["port"].Value}";
|
||||
}
|
||||
|
||||
// Replacing any double quotes in ssh arguments with single quotes, since ssh arguments will be double-quoted as a whole
|
||||
sshArguments = sshArguments.Replace("\"", "'").Trim();
|
||||
|
||||
arguments = $"-p {moshPortsMatch.Groups["ports"].Value}";
|
||||
|
||||
if (!string.IsNullOrEmpty(sshArguments))
|
||||
{
|
||||
// If there were some ssh arguments, add them as defined in the new format
|
||||
arguments += $" --ssh=\"ssh {sshArguments}\"";
|
||||
}
|
||||
|
||||
// Finally append the target to the arguments
|
||||
arguments += $" {targetMatch.Groups["user"]}@{targetMatch.Groups["host"]}";
|
||||
|
||||
newProfile.Arguments = arguments;
|
||||
|
||||
return newProfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Diagnostics;
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.UI.Notifications;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class NotificationService : INotificationService
|
||||
{
|
||||
public void ShowNotification(string title, string content, string url = null)
|
||||
{
|
||||
string xml = $@"<toast>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<text>{title}</text>
|
||||
<text>{content}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>";
|
||||
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(xml);
|
||||
|
||||
var toast = new ToastNotification(doc);
|
||||
if (url != null)
|
||||
{
|
||||
toast.Activated += (n, o) => Process.Start(url);
|
||||
}
|
||||
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,412 @@
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.Models.Messages;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class SettingsService : ISettingsService
|
||||
{
|
||||
public const string CurrentThemeKey = "CurrentTheme";
|
||||
public const string DefaultShellProfileKey = "DefaultShellProfile";
|
||||
public const string DefaultSshProfileKey = "DefaultSshProfile";
|
||||
|
||||
private readonly IDefaultValueProvider _defaultValueProvider;
|
||||
private readonly IApplicationDataContainer _keyBindings;
|
||||
private readonly IApplicationDataContainer _localSettings;
|
||||
private readonly IApplicationDataContainer _roamingSettings;
|
||||
private readonly IApplicationDataContainer _shellProfiles;
|
||||
private readonly IApplicationDataContainer _sshProfiles;
|
||||
private readonly IApplicationDataContainer _themes;
|
||||
|
||||
public SettingsService(IDefaultValueProvider defaultValueProvider, ApplicationDataContainers containers)
|
||||
{
|
||||
_defaultValueProvider = defaultValueProvider;
|
||||
_localSettings = containers.LocalSettings;
|
||||
_roamingSettings = containers.RoamingSettings;
|
||||
|
||||
_themes = containers.Themes;
|
||||
_keyBindings = containers.KeyBindings;
|
||||
_shellProfiles = containers.ShellProfiles;
|
||||
_sshProfiles = containers.SshProfiles;
|
||||
|
||||
|
||||
foreach (var theme in _defaultValueProvider.GetPreInstalledThemes())
|
||||
{
|
||||
if (GetTheme(theme.Id) == null)
|
||||
{
|
||||
_themes.WriteValueAsJson(theme.Id.ToString(), theme);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var shellProfile in _defaultValueProvider.GetPreinstalledShellProfiles())
|
||||
{
|
||||
if (GetShellProfile(shellProfile.Id) == null)
|
||||
{
|
||||
_shellProfiles.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ExportSettings()
|
||||
{
|
||||
var config = new
|
||||
{
|
||||
App = GetApplicationSettings(),
|
||||
KeyBindings = GetCommandKeyBindings(),
|
||||
TerminalOptions = GetTerminalOptions(),
|
||||
Themes = new List<TerminalTheme>(),
|
||||
Profiles = new List<ShellProfile>(),
|
||||
SshProfiles = new List<SshProfile>()
|
||||
};
|
||||
|
||||
foreach (var theme in GetThemes().Where(x => !x.PreInstalled))
|
||||
{
|
||||
config.Themes.Add(theme);
|
||||
}
|
||||
|
||||
foreach (var profile in GetShellProfiles().Where(x => !x.PreInstalled))
|
||||
{
|
||||
config.Profiles.Add(profile);
|
||||
}
|
||||
|
||||
foreach (var profile in GetSshProfiles())
|
||||
{
|
||||
config.SshProfiles.Add(profile);
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(config, PreserveDictionaryKeyCaseContractResolver.SerializerSettings);
|
||||
}
|
||||
|
||||
public void ImportSettings(string serializedSettings)
|
||||
{
|
||||
var config = new
|
||||
{
|
||||
App = GetApplicationSettings(),
|
||||
KeyBindings = new Dictionary<string, ICollection<KeyBinding>>(),
|
||||
Themes = new List<TerminalTheme>(),
|
||||
Profiles = new List<ShellProfile>(),
|
||||
SshProfiles = new List<SshProfile>(),
|
||||
TerminalOptions = GetTerminalOptions()
|
||||
};
|
||||
|
||||
JsonConvert.PopulateObject(serializedSettings, config);
|
||||
|
||||
SaveApplicationSettings(config.App);
|
||||
|
||||
// Since we set each command sepaartely, we don't need all existing settings
|
||||
foreach (var pair in config.KeyBindings)
|
||||
{
|
||||
SaveKeyBindings(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
// Can't create/modify pre-installed themes
|
||||
foreach (var theme in config.Themes.Where(x => !x.PreInstalled))
|
||||
{
|
||||
var existingTheme = GetTheme(theme.Id);
|
||||
if (existingTheme?.PreInstalled == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
SaveTheme(theme, existingTheme != null);
|
||||
}
|
||||
|
||||
// Can't create pre-installed profiles
|
||||
foreach (var profile in config.Profiles.Where(x => !x.PreInstalled))
|
||||
{
|
||||
var existingProfile = GetShellProfile(profile.Id);
|
||||
var isNew = existingProfile.EqualTo(default);
|
||||
|
||||
// You can only edit certain parts of preinstalled profiles
|
||||
if (!isNew && existingProfile.PreInstalled)
|
||||
{
|
||||
existingProfile.WorkingDirectory = profile.WorkingDirectory;
|
||||
existingProfile.Arguments = profile.Arguments;
|
||||
existingProfile.TabThemeId = profile.TabThemeId;
|
||||
existingProfile.TerminalThemeId = profile.TerminalThemeId;
|
||||
existingProfile.KeyBindings = profile.KeyBindings;
|
||||
SaveShellProfile(profile, isNew);
|
||||
continue;
|
||||
}
|
||||
SaveShellProfile(profile, isNew);
|
||||
}
|
||||
|
||||
foreach (var profile in config.SshProfiles)
|
||||
{
|
||||
var existingProfile = GetSshProfile(profile.Id);
|
||||
var isNew = existingProfile.EqualTo(default(SshProfile));
|
||||
|
||||
SaveSshProfile(profile, isNew);
|
||||
}
|
||||
|
||||
SaveTerminalOptions(config.TerminalOptions);
|
||||
}
|
||||
|
||||
public void DeleteShellProfile(Guid id)
|
||||
{
|
||||
_shellProfiles.Delete(id.ToString());
|
||||
Messenger.Default.Send(new ShellProfileDeletedMessage(id));
|
||||
}
|
||||
|
||||
public void DeleteSshProfile(Guid id)
|
||||
{
|
||||
_sshProfiles.Delete(id.ToString());
|
||||
Messenger.Default.Send(new ShellProfileDeletedMessage(id));
|
||||
Messenger.Default.Send(new KeyBindingsChangedMessage());
|
||||
}
|
||||
|
||||
|
||||
public void DeleteTheme(Guid id)
|
||||
{
|
||||
_themes.Delete(id.ToString());
|
||||
|
||||
foreach (var profile in GetShellProfiles())
|
||||
{
|
||||
if (profile.TerminalThemeId == id)
|
||||
{
|
||||
profile.TerminalThemeId = Guid.Empty;
|
||||
SaveShellProfile(profile);
|
||||
}
|
||||
}
|
||||
|
||||
Messenger.Default.Send(new ThemeDeletedMessage(id));
|
||||
}
|
||||
|
||||
public ApplicationSettings GetApplicationSettings()
|
||||
{
|
||||
return _roamingSettings.ReadValueFromJson(nameof(ApplicationSettings), _defaultValueProvider.GetDefaultApplicationSettings());
|
||||
}
|
||||
|
||||
public TerminalTheme GetCurrentTheme()
|
||||
{
|
||||
var id = GetCurrentThemeId();
|
||||
var theme = GetTheme(id);
|
||||
if (theme == null)
|
||||
{
|
||||
id = _defaultValueProvider.GetDefaultThemeId();
|
||||
SaveCurrentThemeId(id);
|
||||
theme = GetTheme(id);
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
public Guid GetCurrentThemeId()
|
||||
{
|
||||
if (_roamingSettings.TryGetValue(CurrentThemeKey, out object value))
|
||||
{
|
||||
return (Guid)value;
|
||||
}
|
||||
return _defaultValueProvider.GetDefaultThemeId();
|
||||
}
|
||||
|
||||
public ShellProfile GetDefaultShellProfile()
|
||||
{
|
||||
var id = GetDefaultShellProfileId();
|
||||
var profile = _shellProfiles.ReadValueFromJson(id.ToString(), default(ShellProfile));
|
||||
if (profile == null)
|
||||
{
|
||||
id = _defaultValueProvider.GetDefaultShellProfileId();
|
||||
SaveDefaultShellProfileId(id);
|
||||
profile = _shellProfiles.ReadValueFromJson(id.ToString(), default(ShellProfile));
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
public ShellProfile GetShellProfile(Guid id)
|
||||
{
|
||||
return _shellProfiles.ReadValueFromJson(id.ToString(), default(ShellProfile));
|
||||
}
|
||||
public SshProfile GetSshProfile(Guid id)
|
||||
{
|
||||
return _sshProfiles.ReadValueFromJson(id.ToString(), default(SshProfile));
|
||||
}
|
||||
|
||||
public Guid GetDefaultShellProfileId()
|
||||
{
|
||||
if (_localSettings.TryGetValue(DefaultShellProfileKey, out object value))
|
||||
{
|
||||
return (Guid)value;
|
||||
}
|
||||
return _defaultValueProvider.GetDefaultShellProfileId();
|
||||
}
|
||||
|
||||
public IDictionary<string, ICollection<KeyBinding>> GetCommandKeyBindings()
|
||||
{
|
||||
var keyBindings = new Dictionary<string, ICollection<KeyBinding>>();
|
||||
|
||||
foreach (Command command in Enum.GetValues(typeof(Command)))
|
||||
{
|
||||
keyBindings.Add(command.ToString(), _keyBindings.ReadValueFromJson<Collection<KeyBinding>>(command.ToString(), null) ?? _defaultValueProvider.GetDefaultKeyBindings(command));
|
||||
}
|
||||
return keyBindings;
|
||||
}
|
||||
|
||||
public IEnumerable<ShellProfile> GetShellProfiles()
|
||||
{
|
||||
return _shellProfiles.GetAll().Select(x => JsonConvert.DeserializeObject<ShellProfile>((string) x))
|
||||
.Select(MoshBackwardCompatibilityFixProfile);
|
||||
}
|
||||
|
||||
public IEnumerable<SshProfile> GetSshProfiles()
|
||||
{
|
||||
return _sshProfiles.GetAll().Select(x => JsonConvert.DeserializeObject<SshProfile>((string) x))
|
||||
.Select(MoshBackwardCompatibilityFixProfile).Cast<SshProfile>();
|
||||
}
|
||||
|
||||
public IEnumerable<ShellProfile> GetAllProfiles()
|
||||
{
|
||||
return GetShellProfiles().Union(GetSshProfiles());
|
||||
}
|
||||
|
||||
private ShellProfile MoshBackwardCompatibilityFixProfile(ShellProfile profile)
|
||||
{
|
||||
var fixedProfile = MoshBackwardCompatibility.FixProfile(profile);
|
||||
|
||||
if (ReferenceEquals(fixedProfile, profile))
|
||||
{
|
||||
// Nothing changed
|
||||
return fixedProfile;
|
||||
}
|
||||
|
||||
if (fixedProfile is SshProfile sshProfile)
|
||||
{
|
||||
DeleteSshProfile(profile.Id);
|
||||
SaveSshProfile(sshProfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteShellProfile(profile.Id);
|
||||
SaveShellProfile(fixedProfile);
|
||||
}
|
||||
|
||||
return fixedProfile;
|
||||
}
|
||||
|
||||
public IEnumerable<TabTheme> GetTabThemes()
|
||||
{
|
||||
return _defaultValueProvider.GetDefaultTabThemes();
|
||||
}
|
||||
|
||||
public TerminalOptions GetTerminalOptions()
|
||||
{
|
||||
return _roamingSettings.ReadValueFromJson(nameof(TerminalOptions), _defaultValueProvider.GetDefaultTerminalOptions());
|
||||
}
|
||||
|
||||
public TerminalTheme GetTheme(Guid id)
|
||||
{
|
||||
return _themes.ReadValueFromJson(id.ToString(), default(TerminalTheme));
|
||||
}
|
||||
|
||||
public IEnumerable<TerminalTheme> GetThemes()
|
||||
{
|
||||
return _themes.GetAll().Select(x => JsonConvert.DeserializeObject<TerminalTheme>((string)x)).ToList();
|
||||
}
|
||||
|
||||
public void ResetKeyBindings()
|
||||
{
|
||||
foreach (Command command in Enum.GetValues(typeof(Command)))
|
||||
{
|
||||
_keyBindings.WriteValueAsJson(command.ToString(), _defaultValueProvider.GetDefaultKeyBindings(command));
|
||||
}
|
||||
|
||||
Messenger.Default.Send(new KeyBindingsChangedMessage());
|
||||
}
|
||||
|
||||
public void SaveApplicationSettings(ApplicationSettings applicationSettings)
|
||||
{
|
||||
_roamingSettings.WriteValueAsJson(nameof(ApplicationSettings), applicationSettings);
|
||||
Messenger.Default.Send(new ApplicationSettingsChangedMessage(applicationSettings.Clone()));
|
||||
}
|
||||
|
||||
public void NotifyApplicationSettingsChanged(ApplicationSettings applicationSettings)
|
||||
{
|
||||
Messenger.Default.Send(new ApplicationSettingsChangedMessage(applicationSettings.Clone()));
|
||||
}
|
||||
|
||||
public void SaveCurrentThemeId(Guid id)
|
||||
{
|
||||
_roamingSettings.SetValue(CurrentThemeKey, id);
|
||||
|
||||
Messenger.Default.Send(new CurrentThemeChangedMessage(id));
|
||||
}
|
||||
|
||||
public void SaveDefaultShellProfileId(Guid id)
|
||||
{
|
||||
_localSettings.SetValue(DefaultShellProfileKey, id);
|
||||
|
||||
Messenger.Default.Send(new DefaultShellProfileChangedMessage(id));
|
||||
}
|
||||
|
||||
public void SaveKeyBindings(string command, ICollection<KeyBinding> keyBindings)
|
||||
{
|
||||
if (!Enum.TryParse<Command>(command, true, out var enumValue))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
_keyBindings.WriteValueAsJson(enumValue.ToString(), keyBindings);
|
||||
Messenger.Default.Send(new KeyBindingsChangedMessage());
|
||||
}
|
||||
|
||||
public void SaveShellProfile(ShellProfile shellProfile, bool newShell = false)
|
||||
{
|
||||
_shellProfiles.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile);
|
||||
|
||||
// When saving the shell profile, we also need to update keybindings for everywhere.
|
||||
Messenger.Default.Send(new KeyBindingsChangedMessage());
|
||||
|
||||
if (newShell)
|
||||
{
|
||||
Messenger.Default.Send(new ShellProfileAddedMessage(shellProfile));
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.Default.Send(new ShellProfileChangedMessage(shellProfile));
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveSshProfile(SshProfile sshProfile, bool newShell = false)
|
||||
{
|
||||
_sshProfiles.WriteValueAsJson(sshProfile.Id.ToString(), sshProfile);
|
||||
|
||||
// When saving the shell profile, we also need to update keybindings for everywhere.
|
||||
Messenger.Default.Send(new KeyBindingsChangedMessage());
|
||||
|
||||
if (newShell)
|
||||
{
|
||||
Messenger.Default.Send(new ShellProfileAddedMessage(sshProfile));
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.Default.Send(new ShellProfileChangedMessage(sshProfile));
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveTerminalOptions(TerminalOptions terminalOptions)
|
||||
{
|
||||
_roamingSettings.WriteValueAsJson(nameof(TerminalOptions), terminalOptions);
|
||||
Messenger.Default.Send(new TerminalOptionsChangedMessage(terminalOptions));
|
||||
}
|
||||
|
||||
public void SaveTheme(TerminalTheme theme, bool newTheme = false)
|
||||
{
|
||||
_themes.WriteValueAsJson(theme.Id.ToString(), theme);
|
||||
|
||||
if (theme.Id == GetCurrentThemeId())
|
||||
{
|
||||
Messenger.Default.Send(new CurrentThemeChangedMessage(theme.Id));
|
||||
}
|
||||
|
||||
if (newTheme)
|
||||
{
|
||||
Messenger.Default.Send(new ThemeAddedMessage(theme));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using FluentTerminal.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class ShellProfileMigrationService : IShellProfileMigrationService
|
||||
{
|
||||
private readonly Dictionary<int, Action<ShellProfile>> _migrationSteps = new Dictionary<int, Action<ShellProfile>>
|
||||
{
|
||||
[1] = new Action<ShellProfile>(profile =>
|
||||
{
|
||||
profile.EnvironmentVariables["TERM"] = "xterm-256color";
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
public void Migrate(ShellProfile profile)
|
||||
{
|
||||
while(profile.MigrationVersion < ShellProfile.CurrentMigrationVersion)
|
||||
{
|
||||
ApplyMigrationStep(profile, profile.MigrationVersion + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyMigrationStep(ShellProfile profile, int targetVersion)
|
||||
{
|
||||
_migrationSteps[targetVersion](profile);
|
||||
profile.MigrationVersion = targetVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class ThemeParserFactory : IThemeParserFactory
|
||||
{
|
||||
private readonly IEnumerable<IThemeParser> _parsers;
|
||||
|
||||
public IEnumerable<string> SupportedFileTypes { get; }
|
||||
|
||||
public ThemeParserFactory(IEnumerable<IThemeParser> parsers)
|
||||
{
|
||||
_parsers = parsers;
|
||||
SupportedFileTypes = _parsers.SelectMany(p => p.SupportedFileTypes);
|
||||
}
|
||||
|
||||
public IThemeParser GetParser(string fileType)
|
||||
{
|
||||
return _parsers.FirstOrDefault(p => p.SupportedFileTypes.Contains(fileType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
using FluentTerminal.App.Services.Exceptions;
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using FluentTerminal.Models.Requests;
|
||||
using FluentTerminal.Models.Responses;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation.Collections;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class TrayProcessCommunicationService : ITrayProcessCommunicationService
|
||||
{
|
||||
#region Static
|
||||
|
||||
private static string _userName;
|
||||
private static string _sshConfigDir;
|
||||
private static readonly Dictionary<string, string> CommandPaths = new Dictionary<string, string>();
|
||||
private static readonly Dictionary<string, string> CommandErrors = new Dictionary<string, string>();
|
||||
|
||||
private static ValueSet CreateMessage(IMessage content)
|
||||
{
|
||||
return new ValueSet
|
||||
{
|
||||
[MessageKeys.Type] = content.Identifier,
|
||||
[MessageKeys.Content] = JsonConvert.SerializeObject(content,
|
||||
PreserveDictionaryKeyCaseContractResolver.SerializerSettings)
|
||||
};
|
||||
}
|
||||
|
||||
#endregion Static
|
||||
|
||||
private readonly ISettingsService _settingsService;
|
||||
private IAppServiceConnection _appServiceConnection;
|
||||
private readonly Dictionary<byte, Action<byte[]>> _terminalOutputHandlers;
|
||||
// ReSharper disable once RedundantDefaultMemberInitializer
|
||||
private byte _nextTerminalId = 0;
|
||||
|
||||
public event EventHandler<TerminalExitStatus> TerminalExited;
|
||||
|
||||
public TrayProcessCommunicationService(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
_terminalOutputHandlers = new Dictionary<byte, Action<byte[]>>();
|
||||
}
|
||||
|
||||
public byte GetNextTerminalId()
|
||||
{
|
||||
return _nextTerminalId++;
|
||||
}
|
||||
|
||||
public async Task<string> GetUserNameAsync()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_userName))
|
||||
{
|
||||
// Returning the username from cache
|
||||
return _userName;
|
||||
}
|
||||
|
||||
var response = await GetResponseAsync<StringValueResponse>(new GetUserNameRequest()).ConfigureAwait(false);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
_userName = response.Value;
|
||||
}
|
||||
|
||||
return _userName;
|
||||
}
|
||||
|
||||
public async Task SaveTextFileAsync(string path, string content)
|
||||
{
|
||||
var response =
|
||||
await GetResponseAsync<CommonResponse>(new SaveTextFileRequest {Path = path, Content = content})
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
throw new SaveTextFileException(string.IsNullOrEmpty(response.Error)
|
||||
? "Failed to save the file."
|
||||
: response.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GetSshConfigDirAsync()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_sshConfigDir))
|
||||
{
|
||||
return _sshConfigDir;
|
||||
}
|
||||
|
||||
var response =
|
||||
await GetResponseAsync<GetSshConfigFolderResponse>(new GetSshConfigFolderRequest
|
||||
{ IncludeContent = false }).ConfigureAwait(false);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
_sshConfigDir = response.Path;
|
||||
}
|
||||
|
||||
return _sshConfigDir;
|
||||
}
|
||||
|
||||
public async Task<string[]> GetFilesFromSshConfigDirAsync()
|
||||
{
|
||||
var response =
|
||||
await GetResponseAsync<GetSshConfigFolderResponse>(new GetSshConfigFolderRequest
|
||||
{IncludeContent = true}).ConfigureAwait(false);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
_sshConfigDir = response.Path;
|
||||
|
||||
return response.Files;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckFileExistsAsync(string path)
|
||||
{
|
||||
var response = await GetResponseAsync<CommonResponse>(new CheckFileExistsRequest {Path = path})
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return response.Success;
|
||||
}
|
||||
|
||||
public Task MuteTerminalAsync(bool mute)
|
||||
{
|
||||
return _appServiceConnection.SendMessageAsync(CreateMessage(new MuteTerminalRequest {Mute = mute}));
|
||||
}
|
||||
|
||||
public void UpdateSettings(ApplicationSettings settings)
|
||||
{
|
||||
_appServiceConnection.SendMessageAsync(CreateMessage(new UpdateSettingsRequest { Settings = settings }));
|
||||
}
|
||||
|
||||
public async Task<CreateTerminalResponse> CreateTerminalAsync(byte id, TerminalSize size, ShellProfile shellProfile,
|
||||
SessionType sessionType)
|
||||
{
|
||||
var request = new CreateTerminalRequest
|
||||
{
|
||||
Id = id,
|
||||
Size = size,
|
||||
Profile = shellProfile,
|
||||
SessionType = sessionType
|
||||
};
|
||||
|
||||
Logger.Instance.Debug("Sending CreateTerminalRequest: {@request}", request);
|
||||
|
||||
var response = await GetResponseAsync<CreateTerminalResponse>(request).ConfigureAwait(false);
|
||||
|
||||
Logger.Instance.Debug("Received CreateTerminalResponse: {@response}", response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public Task<PauseTerminalOutputResponse> PauseTerminalOutputAsync(byte id, bool pause)
|
||||
{
|
||||
return GetResponseAsync<PauseTerminalOutputResponse>(
|
||||
new PauseTerminalOutputRequest {Id = id, Pause = pause});
|
||||
}
|
||||
|
||||
public void Initialize(IAppServiceConnection appServiceConnection)
|
||||
{
|
||||
_appServiceConnection = appServiceConnection;
|
||||
_appServiceConnection.MessageReceived += OnMessageReceived;
|
||||
}
|
||||
|
||||
private void OnMessageReceived(object sender, IDictionary<string, object> e)
|
||||
{
|
||||
var messageType = (byte)e[MessageKeys.Type];
|
||||
var messageContent = e[MessageKeys.Content];
|
||||
|
||||
switch (messageType)
|
||||
{
|
||||
case Constants.TerminalBufferRequestIdentifier:
|
||||
var terminalId = (byte)e[MessageKeys.TerminalId];
|
||||
|
||||
if (_terminalOutputHandlers.ContainsKey(terminalId))
|
||||
{
|
||||
_terminalOutputHandlers[terminalId].Invoke((byte[])messageContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Instance.Error("Received output for unknown terminal Id {id}", terminalId);
|
||||
}
|
||||
break;
|
||||
case (byte) MessageIdentifiers.TerminalExitedRequest:
|
||||
var request = JsonConvert.DeserializeObject<TerminalExitedRequest>((string)messageContent);
|
||||
Logger.Instance.Debug("Received TerminalExitedRequest: {@request}", request);
|
||||
|
||||
TerminalExited?.Invoke(this, request.ToStatus());
|
||||
break;
|
||||
default:
|
||||
Logger.Instance.Error("Received unknown message type: {messageType}", messageType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Task ResizeTerminalAsync(byte id, TerminalSize size)
|
||||
{
|
||||
return _appServiceConnection.SendMessageAsync(CreateMessage(new ResizeTerminalRequest
|
||||
{TerminalId = id, NewSize = size}));
|
||||
}
|
||||
|
||||
public void SubscribeForTerminalOutput(byte terminalId, Action<byte[]> callback)
|
||||
{
|
||||
_terminalOutputHandlers[terminalId] = callback;
|
||||
}
|
||||
|
||||
public void UnsubscribeFromTerminalOutput(byte id)
|
||||
{
|
||||
if (_terminalOutputHandlers.ContainsKey(id))
|
||||
{
|
||||
_terminalOutputHandlers.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Task UpdateToggleWindowKeyBindingsAsync()
|
||||
{
|
||||
var keyBindings = _settingsService.GetCommandKeyBindings()[nameof(Command.ToggleWindow)];
|
||||
|
||||
return _appServiceConnection.SendMessageAsync(CreateMessage(new SetToggleWindowKeyBindingsRequest
|
||||
{KeyBindings = keyBindings}));
|
||||
}
|
||||
|
||||
public Task WriteAsync(byte id, byte[] data)
|
||||
{
|
||||
var message = new ValueSet
|
||||
{
|
||||
[MessageKeys.Type] = Constants.TerminalBufferRequestIdentifier,
|
||||
[MessageKeys.TerminalId] = id,
|
||||
[MessageKeys.Content] = data
|
||||
};
|
||||
|
||||
return _appServiceConnection.SendMessageAsync(message);
|
||||
}
|
||||
|
||||
public Task CloseTerminalAsync(byte terminalId)
|
||||
{
|
||||
var request = new TerminalExitedRequest(terminalId, -1);
|
||||
|
||||
Logger.Instance.Debug("Sending TerminalExitedRequest: {@request}", request);
|
||||
|
||||
return _appServiceConnection.SendMessageAsync(CreateMessage(request));
|
||||
}
|
||||
|
||||
public async Task<string> GetCommandPathAsync(string command)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(command))
|
||||
{
|
||||
throw new ArgumentException("Input value is null or empty.", nameof(command));
|
||||
}
|
||||
|
||||
command = command.Trim();
|
||||
|
||||
var commandLower = command.ToLowerInvariant();
|
||||
|
||||
if (CommandPaths.TryGetValue(commandLower, out var path))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
if (CommandErrors.TryGetValue(commandLower, out var error))
|
||||
{
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
var response = await GetResponseAsync<StringValueResponse>(new GetCommandPathRequest {Command = command})
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
CommandPaths[commandLower] = response.Value;
|
||||
|
||||
return response.Value;
|
||||
}
|
||||
|
||||
CommandErrors[commandLower] = response.Error;
|
||||
|
||||
throw new Exception(response.Error);
|
||||
}
|
||||
|
||||
public Task QuitApplicationAsync()
|
||||
{
|
||||
return _appServiceConnection.SendMessageAsync(CreateMessage(new QuitApplicationRequest()));
|
||||
}
|
||||
|
||||
private async Task<T> GetResponseAsync<T>(IMessage request)
|
||||
{
|
||||
var messageResponse =
|
||||
await _appServiceConnection.SendMessageAsync(CreateMessage(request)).ConfigureAwait(false);
|
||||
|
||||
return JsonConvert.DeserializeObject<T>((string)messageResponse[MessageKeys.Content]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using Windows.ApplicationModel;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services.Implementation
|
||||
{
|
||||
public class UpdateService : IUpdateService
|
||||
{
|
||||
private const string apiEndpoint = "https://api.github.com";
|
||||
|
||||
private readonly INotificationService _notificationService;
|
||||
|
||||
public UpdateService(INotificationService notificationService)
|
||||
{
|
||||
_notificationService = notificationService;
|
||||
}
|
||||
|
||||
public async Task CheckForUpdateAsync(bool notifyNoUpdate = false)
|
||||
{
|
||||
var latest = await GetLatestVersionAsync().ConfigureAwait(false);
|
||||
if (latest > GetCurrentVersion())
|
||||
{
|
||||
_notificationService.ShowNotification("Update available",
|
||||
"Click to open the releases page.", "https://github.com/felixse/FluentTerminal/releases");
|
||||
}
|
||||
else if (notifyNoUpdate)
|
||||
{
|
||||
_notificationService.ShowNotification("No update available", "You're up to date!");
|
||||
}
|
||||
}
|
||||
|
||||
public Version GetCurrentVersion()
|
||||
{
|
||||
var currentVersion = Package.Current.Id.Version;
|
||||
return new Version(currentVersion.Major, currentVersion.Minor, currentVersion.Build, currentVersion.Revision);
|
||||
}
|
||||
|
||||
public async Task<Version> GetLatestVersionAsync()
|
||||
{
|
||||
var restClient = new RestClient(apiEndpoint);
|
||||
var restRequest = new RestRequest("/repos/felixse/fluentterminal/releases", Method.GET);
|
||||
|
||||
var restResponse = await restClient.ExecuteAsync(restRequest).ConfigureAwait(false);
|
||||
if (restResponse.IsSuccessful)
|
||||
{
|
||||
dynamic restResponseData = JsonConvert.DeserializeObject(restResponse.Content);
|
||||
string tag = restResponseData[0].tag_name;
|
||||
var latestVersion = new Version(tag);
|
||||
return new Version(latestVersion.Major, latestVersion.Minor, latestVersion.Build, latestVersion.Revision);
|
||||
}
|
||||
return new Version(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public sealed class Logger
|
||||
{
|
||||
public enum LogLevel
|
||||
{
|
||||
Verbose = 0,
|
||||
Debug = 1,
|
||||
Information = 2,
|
||||
Warning = 3,
|
||||
Error = 4,
|
||||
Fatal = 5
|
||||
}
|
||||
|
||||
public class Configuration
|
||||
{
|
||||
public LogLevel LogLevel { get; set; } = LogLevel.Error;
|
||||
}
|
||||
|
||||
public static Logger Instance { get; } = new Logger();
|
||||
|
||||
private Logger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Initialize(string filePath, Configuration configuration)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Async(a => a.File(filePath, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7))
|
||||
.MinimumLevel.Is((LogEventLevel)configuration.LogLevel)
|
||||
.CreateLogger();
|
||||
|
||||
// Log file is not created during unhandled exception processing.
|
||||
// Force log file creation with the highest severity initialization record.
|
||||
Log.Fatal("Initialized");
|
||||
}
|
||||
|
||||
public void Debug(string text, params object[] propertyValues)
|
||||
{
|
||||
Log.Debug(text, propertyValues, propertyValues);
|
||||
}
|
||||
|
||||
public void Information(string text, params object[] propertyValues)
|
||||
{
|
||||
Log.Information(text, propertyValues);
|
||||
}
|
||||
|
||||
public void Warning(string text, params object[] propertyValues)
|
||||
{
|
||||
Log.Warning(text, propertyValues);
|
||||
}
|
||||
|
||||
public void Error(string text, params object[] propertyValues)
|
||||
{
|
||||
Log.Error(text, propertyValues);
|
||||
}
|
||||
|
||||
public void Error(Exception exception, string text, params object[] propertyValues)
|
||||
{
|
||||
Log.Error(exception, text, propertyValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using FluentTerminal.Models.Responses;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.Services
|
||||
{
|
||||
public class Terminal
|
||||
{
|
||||
private readonly ITrayProcessCommunicationService _trayProcessCommunicationService;
|
||||
private Func<Task<string>> _selectedTextCallback;
|
||||
private bool _closingFromUi;
|
||||
private bool _exited;
|
||||
private readonly bool _requireShellProcessStart;
|
||||
private string _fallbackTitle;
|
||||
|
||||
public Terminal(ITrayProcessCommunicationService trayProcessCommunicationService, byte? terminalId = null)
|
||||
{
|
||||
_trayProcessCommunicationService = trayProcessCommunicationService;
|
||||
_trayProcessCommunicationService.TerminalExited += OnTerminalExited;
|
||||
Id = terminalId ?? trayProcessCommunicationService.GetNextTerminalId();
|
||||
_requireShellProcessStart = !terminalId.HasValue;
|
||||
}
|
||||
|
||||
public void Reconnect()
|
||||
{
|
||||
_exited = false;
|
||||
_trayProcessCommunicationService.TerminalExited += OnTerminalExited;
|
||||
}
|
||||
|
||||
private void OnTerminalExited(object sender, TerminalExitStatus status)
|
||||
{
|
||||
if (status.TerminalId != Id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_exited = true;
|
||||
Exited?.Invoke(this, status.ExitCode);
|
||||
|
||||
if (_closingFromUi || status.ExitCode <= 0)
|
||||
{
|
||||
Closed?.Invoke(this, System.EventArgs.Empty);
|
||||
}
|
||||
|
||||
_trayProcessCommunicationService.TerminalExited -= OnTerminalExited;
|
||||
}
|
||||
|
||||
public event EventHandler<int> Exited;
|
||||
|
||||
/// <summary>
|
||||
/// To be observed by both view and viewmodel
|
||||
/// </summary>
|
||||
public event EventHandler Closed;
|
||||
|
||||
/// <summary>
|
||||
/// to be observed by viewmodel
|
||||
/// </summary>
|
||||
public event EventHandler<string> KeyboardCommandReceived;
|
||||
|
||||
/// <summary>
|
||||
/// to be observed by view
|
||||
/// </summary>
|
||||
public event EventHandler<byte[]> OutputReceived;
|
||||
|
||||
/// <summary>
|
||||
/// to be observed by viewmodel
|
||||
/// </summary>
|
||||
public event EventHandler<TerminalSize> SizeChanged;
|
||||
|
||||
/// <summary>
|
||||
/// to be observed by viewmodel
|
||||
/// </summary>
|
||||
public event EventHandler<string> TitleChanged;
|
||||
|
||||
public byte Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// To be called by either view or viewmodel
|
||||
/// </summary>
|
||||
public Task CloseAsync()
|
||||
{
|
||||
if (_exited)
|
||||
{
|
||||
Closed?.Invoke(this, System.EventArgs.Empty);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
_closingFromUi = true;
|
||||
_trayProcessCommunicationService.UnsubscribeFromTerminalOutput(Id);
|
||||
return _trayProcessCommunicationService.CloseTerminalAsync(Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to be called by viewmodel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<string> GetSelectedText()
|
||||
{
|
||||
return _selectedTextCallback?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to be called by view
|
||||
/// </summary>
|
||||
public void ProcessKeyboardCommand(string command)
|
||||
{
|
||||
KeyboardCommandReceived?.Invoke(this, command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To be set by view
|
||||
/// </summary>
|
||||
public void RegisterSelectedTextCallback(Func<Task<string>> selectedTextCallback)
|
||||
{
|
||||
_selectedTextCallback = selectedTextCallback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To be called by view
|
||||
/// </summary>
|
||||
public async Task SetSizeAsync(TerminalSize size)
|
||||
{
|
||||
await _trayProcessCommunicationService.ResizeTerminalAsync(Id, size).ConfigureAwait(false);
|
||||
SizeChanged?.Invoke(this, size);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to be called by view
|
||||
/// </summary>
|
||||
public void SetTitle(string title)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
{
|
||||
title = _fallbackTitle;
|
||||
}
|
||||
TitleChanged?.Invoke(this, title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To be called by view when ready
|
||||
/// </summary>
|
||||
public async Task<TerminalResponse> StartShellProcessAsync(ShellProfile shellProfile, TerminalSize size, SessionType sessionType, string termState)
|
||||
{
|
||||
if (!_requireShellProcessStart && !string.IsNullOrEmpty(termState))
|
||||
{
|
||||
OutputReceived?.Invoke(this, Encoding.UTF8.GetBytes(termState));
|
||||
}
|
||||
|
||||
_trayProcessCommunicationService.SubscribeForTerminalOutput(Id, t => OutputReceived?.Invoke(this, t));
|
||||
|
||||
if (_requireShellProcessStart)
|
||||
{
|
||||
var response = await _trayProcessCommunicationService
|
||||
.CreateTerminalAsync(Id, size, shellProfile, sessionType).ConfigureAwait(false);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
_fallbackTitle = response.Name;
|
||||
SetTitle(_fallbackTitle);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
else
|
||||
{
|
||||
return await _trayProcessCommunicationService.PauseTerminalOutputAsync(Id, false);
|
||||
}
|
||||
}
|
||||
|
||||
public Task Write(byte[] data)
|
||||
{
|
||||
return _trayProcessCommunicationService.WriteAsync(Id, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tells the ViewModel that this view failed to launch and can be closed.
|
||||
/// </summary>
|
||||
public void ReportLauchFailed()
|
||||
{
|
||||
Closed?.Invoke(this, System.EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FluentTerminal.App.Services.Utilities
|
||||
{
|
||||
public static class EnumHelper
|
||||
{
|
||||
public static string GetEnumDescription(Enum value)
|
||||
{
|
||||
var fieldInfo = value.GetType().GetField(value.ToString());
|
||||
|
||||
var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
|
||||
if (attributes?.Length > 0)
|
||||
{
|
||||
return attributes[0].Description;
|
||||
}
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Windows.ApplicationModel.Resources;
|
||||
|
||||
namespace FluentTerminal.App.Services.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Get strings in different languages.
|
||||
/// Author: Zuozishi
|
||||
/// </summary>
|
||||
public static class I18N
|
||||
{
|
||||
private static readonly ResourceLoader ResourceLoader = ResourceLoader.GetForViewIndependentUse();
|
||||
|
||||
public static string Translate(string resource)
|
||||
{
|
||||
return ResourceLoader.GetString(resource.Replace('.', '/'));
|
||||
}
|
||||
|
||||
public static string TranslateWithFallback(string resource, string fallback)
|
||||
{
|
||||
var result = Translate(resource);
|
||||
|
||||
return string.IsNullOrEmpty(result) ? fallback : result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace FluentTerminal.App.Services.Utilities
|
||||
{
|
||||
public class PreserveDictionaryKeyCaseContractResolver : DefaultContractResolver
|
||||
{
|
||||
public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
|
||||
{ ContractResolver = new PreserveDictionaryKeyCaseContractResolver() };
|
||||
|
||||
protected override JsonDictionaryContract CreateDictionaryContract(Type objectType)
|
||||
{
|
||||
var contract = base.CreateDictionaryContract(objectType);
|
||||
|
||||
contract.DictionaryKeyResolver = key => key;
|
||||
|
||||
return contract;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FluentTerminal.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace FluentTerminal.App.Services.Utilities
|
||||
{
|
||||
public class TerminalThemeContractResolver : PreserveDictionaryKeyCaseContractResolver
|
||||
{
|
||||
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
|
||||
{
|
||||
JsonProperty property = base.CreateProperty(member, memberSerialization);
|
||||
|
||||
if (property.DeclaringType == typeof(TerminalTheme) && property.PropertyName == nameof(TerminalTheme.PreInstalled))
|
||||
{
|
||||
property.ShouldSerialize = (_) => false;
|
||||
}
|
||||
|
||||
if (property.DeclaringType == typeof(TerminalTheme) && property.PropertyName == nameof(TerminalTheme.Id))
|
||||
{
|
||||
property.ShouldSerialize = (_) => false;
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
internal class DelayedHistorySaver : ISessionSuccessTracker
|
||||
{
|
||||
private const int DelayMilliseconds = 5000;
|
||||
|
||||
private readonly Action _saveAction;
|
||||
|
||||
private readonly object _lock = new object();
|
||||
|
||||
private CancellationTokenSource _cts;
|
||||
|
||||
private bool _sessionStarted;
|
||||
private bool _outputReceived;
|
||||
|
||||
private bool _toSave = true;
|
||||
|
||||
internal DelayedHistorySaver(Action saveAction)
|
||||
{
|
||||
_saveAction = saveAction;
|
||||
}
|
||||
|
||||
public void SetSuccessfulSessionStart()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_toSave || _sessionStarted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_sessionStarted = true;
|
||||
|
||||
if (_outputReceived)
|
||||
{
|
||||
InitiateSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOutputReceived()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_toSave || _outputReceived)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_outputReceived = true;
|
||||
|
||||
if (_sessionStarted)
|
||||
{
|
||||
InitiateSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInvalid()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_toSave || !(_cts is CancellationTokenSource cts))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_toSave = false;
|
||||
|
||||
cts.Cancel();
|
||||
cts.Dispose();
|
||||
_cts = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitiateSave()
|
||||
{
|
||||
_cts = new CancellationTokenSource();
|
||||
|
||||
Task.Delay(DelayMilliseconds, _cts.Token).ContinueWith(t =>
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_toSave)
|
||||
{
|
||||
_saveAction.Invoke();
|
||||
}
|
||||
|
||||
_toSave = false;
|
||||
|
||||
_cts?.Dispose();
|
||||
_cts = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
public class EnvironmentVariableViewModel : ViewModelBase
|
||||
{
|
||||
private string _name;
|
||||
private string _value;
|
||||
|
||||
public Guid Id { get; } = Guid.NewGuid();
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => Set(ref _name, value);
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get => _value;
|
||||
set => Set(ref _value, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FluentTerminal.App.Services\FluentTerminal.App.Services.csproj" />
|
||||
<ProjectReference Include="..\FluentTerminal.Models\FluentTerminal.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows.Foundation.UniversalApiContract">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
public interface ISessionSuccessTracker
|
||||
{
|
||||
void SetSuccessfulSessionStart();
|
||||
|
||||
void SetOutputReceived();
|
||||
|
||||
void SetInvalid();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using FluentTerminal.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
public interface ITerminalView : IDisposable
|
||||
{
|
||||
Task ChangeThemeAsync(TerminalTheme theme);
|
||||
Task ChangeKeyBindingsAsync();
|
||||
Task ChangeOptionsAsync(TerminalOptions options);
|
||||
Task InitializeAsync(TerminalViewModel viewModel);
|
||||
Task ReconnectAsync();
|
||||
void DisposalPrepare();
|
||||
Task FindNextAsync(SearchRequest request);
|
||||
Task FindPreviousAsync(SearchRequest request);
|
||||
Task FocusTerminalAsync();
|
||||
Task<string> SerializeXtermStateAsync();
|
||||
void Paste(string text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using FluentTerminal.App.ViewModels.Utilities;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Infrastructure
|
||||
{
|
||||
public class AsyncCommand : IAsyncCommand
|
||||
{
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
private bool _isExecuting;
|
||||
private readonly Func<Task> _execute;
|
||||
private readonly Func<bool> _canExecute;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public AsyncCommand(
|
||||
Func<Task> execute,
|
||||
Func<bool> canExecute = null,
|
||||
IErrorHandler errorHandler = null)
|
||||
{
|
||||
_execute = execute;
|
||||
_canExecute = canExecute;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public bool CanExecute()
|
||||
{
|
||||
return !_isExecuting && (_canExecute?.Invoke() ?? true);
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync()
|
||||
{
|
||||
if (CanExecute())
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: If we're using class field _isExecuting, maybe we should introduce some locking?
|
||||
_isExecuting = true;
|
||||
await _execute();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isExecuting = false;
|
||||
}
|
||||
}
|
||||
|
||||
RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region Explicit implementations
|
||||
bool ICommand.CanExecute(object parameter)
|
||||
{
|
||||
return CanExecute();
|
||||
}
|
||||
|
||||
void ICommand.Execute(object parameter)
|
||||
{
|
||||
ExecuteAsync().FireAndForgetSafeAsync(_errorHandler);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class AsyncCommand<T> : IAsyncCommand<T>
|
||||
{
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
private bool _isExecuting;
|
||||
private readonly Func<T, Task> _execute;
|
||||
private readonly Func<T, bool> _canExecute;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public AsyncCommand(Func<T, Task> execute, Func<T, bool> canExecute = null, IErrorHandler errorHandler = null)
|
||||
{
|
||||
_execute = execute;
|
||||
_canExecute = canExecute;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public bool CanExecute(T parameter)
|
||||
{
|
||||
return !_isExecuting && (_canExecute?.Invoke(parameter) ?? true);
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync(T parameter)
|
||||
{
|
||||
if (CanExecute(parameter))
|
||||
{
|
||||
try
|
||||
{
|
||||
_isExecuting = true;
|
||||
await _execute(parameter);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isExecuting = false;
|
||||
}
|
||||
}
|
||||
|
||||
RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region Explicit implementations
|
||||
bool ICommand.CanExecute(object parameter)
|
||||
{
|
||||
return CanExecute((T)parameter);
|
||||
}
|
||||
|
||||
void ICommand.Execute(object parameter)
|
||||
{
|
||||
ExecuteAsync((T)parameter).FireAndForgetSafeAsync(_errorHandler);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// based on: https://github.com/johnthiriet/AsyncVoid
|
||||
/// </summary>
|
||||
public interface IAsyncCommand : ICommand
|
||||
{
|
||||
Task ExecuteAsync();
|
||||
bool CanExecute();
|
||||
}
|
||||
|
||||
public interface IAsyncCommand<in T> : ICommand
|
||||
{
|
||||
Task ExecuteAsync(T parameter);
|
||||
bool CanExecute(T parameter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Infrastructure
|
||||
{
|
||||
public interface IErrorHandler
|
||||
{
|
||||
void HandleError(Exception ex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,821 @@
|
||||
using FluentTerminal.App.Services;
|
||||
using FluentTerminal.App.Services.EventArgs;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.Models;
|
||||
using FluentTerminal.Models.Enums;
|
||||
using GalaSoft.MvvmLight;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Core;
|
||||
using FluentTerminal.App.ViewModels.Menu;
|
||||
using FluentTerminal.Models.Messages;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using FluentTerminal.App.ViewModels.Infrastructure;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IClipboardService _clipboardService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IKeyboardCommandService _keyboardCommandService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly ITrayProcessCommunicationService _trayProcessCommunicationService;
|
||||
private readonly ICommandHistoryService _commandHistoryService;
|
||||
private readonly IAcceleratorKeyValidator _acceleratorKeyValidator;
|
||||
private ApplicationSettings _applicationSettings;
|
||||
private bool _useAcrylicBackground;
|
||||
private double _backgroundOpacity;
|
||||
private TerminalViewModel _selectedTerminal;
|
||||
private TabsPosition _tabsPosition;
|
||||
private string _windowTitle;
|
||||
private IDictionary<string, ICollection<KeyBinding>> _keyBindings;
|
||||
|
||||
public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
|
||||
IApplicationView applicationView, IClipboardService clipboardService, ICommandHistoryService commandHistoryService, IAcceleratorKeyValidator acceleratorKeyValidator)
|
||||
{
|
||||
MessengerInstance.Register<ApplicationSettingsChangedMessage>(this, OnApplicationSettingsChanged);
|
||||
MessengerInstance.Register<ShellProfileAddedMessage>(this, OnShellProfileAdded);
|
||||
MessengerInstance.Register<ShellProfileDeletedMessage>(this, OnShellProfileDeleted);
|
||||
MessengerInstance.Register<ShellProfileChangedMessage>(this, OnShellProfileChanged);
|
||||
MessengerInstance.Register<DefaultShellProfileChangedMessage>(this, OnDefaultShellProfileChanged);
|
||||
MessengerInstance.Register<TerminalOptionsChangedMessage>(this, OnTerminalOptionsChanged);
|
||||
MessengerInstance.Register<CommandHistoryChangedMessage>(this, OnCommandHistoryChanged);
|
||||
MessengerInstance.Register<KeyBindingsChangedMessage>(this, OnKeyBindingChanged);
|
||||
|
||||
_settingsService = settingsService;
|
||||
|
||||
_trayProcessCommunicationService = trayProcessCommunicationService;
|
||||
_dialogService = dialogService;
|
||||
ApplicationView = applicationView;
|
||||
_clipboardService = clipboardService;
|
||||
_keyboardCommandService = keyboardCommandService;
|
||||
_commandHistoryService = commandHistoryService;
|
||||
_acceleratorKeyValidator = acceleratorKeyValidator;
|
||||
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), async () => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), async () => await AddDefaultProfileAsync(NewTerminalLocation.Window));
|
||||
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshTab), async () => await AddSshProfileAsync(NewTerminalLocation.Tab));
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshWindow), async () => await AddSshProfileAsync(NewTerminalLocation.Window));
|
||||
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandTab), async () => await AddQuickLaunchProfileAsync(NewTerminalLocation.Tab));
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandWindow), async () => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window));
|
||||
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), async () => await SelectedTerminal.EditTitleAsync());
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.DuplicateTab), async () => await AddTabAsync(SelectedTerminal.ShellProfile.Clone()));
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ReconnectTab), async () => { if (SelectedTerminal.ReconnectTabCommand.CanExecute()) await SelectedTerminal.ReconnectTabAsync(); });
|
||||
|
||||
// Add all of the commands for switching to a tab of a given ID, if there's one open there
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
var switchCmd = Command.SwitchToTerm1 + i;
|
||||
int tabNumber = i;
|
||||
// ReSharper disable once InconsistentNaming
|
||||
void handler() => SelectTabNumber(tabNumber);
|
||||
_keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
|
||||
}
|
||||
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);
|
||||
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ShowSettings), ShowSettings);
|
||||
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ToggleFullScreen), ToggleFullScreen);
|
||||
|
||||
foreach (ShellProfile profile in _settingsService.GetShellProfiles())
|
||||
{
|
||||
_keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async () => await AddProfileByGuidAsync(profile.Id));
|
||||
}
|
||||
|
||||
foreach (SshProfile profile in _settingsService.GetSshProfiles())
|
||||
{
|
||||
_keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async () => await AddProfileByGuidAsync(profile.Id));
|
||||
}
|
||||
|
||||
var currentTheme = _settingsService.GetCurrentTheme();
|
||||
var options = _settingsService.GetTerminalOptions();
|
||||
UseAcrylicBackground = options.UseAcrylicBackground;
|
||||
BackgroundOpacity = options.BackgroundOpacity;
|
||||
_applicationSettings = _settingsService.GetApplicationSettings();
|
||||
TabsPosition = _applicationSettings.TabsPosition;
|
||||
|
||||
AddDefaultTabCommand = new RelayCommand(async () => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
|
||||
|
||||
ApplicationView.CloseRequested += OnCloseRequest;
|
||||
ApplicationView.Closed += OnClosed;
|
||||
Terminals.CollectionChanged += OnTerminalsCollectionChanged;
|
||||
|
||||
LoadKeyBindings();
|
||||
|
||||
_newDefaultTabCommand = new RelayCommand(async () => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
|
||||
_newDefaultWindowCommand = new RelayCommand(async () => await AddDefaultProfileAsync(NewTerminalLocation.Window));
|
||||
_newRemoteTabCommand = new RelayCommand(async () => await AddSshProfileAsync(NewTerminalLocation.Tab));
|
||||
_newRemoteWindowCommand = new RelayCommand(async () => await AddSshProfileAsync(NewTerminalLocation.Window));
|
||||
_newQuickLaunchTabCommand = new RelayCommand(async () => await AddQuickLaunchProfileAsync(NewTerminalLocation.Tab));
|
||||
_newQuickLaunchWindowCommand = new RelayCommand(async () => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window));
|
||||
|
||||
_settingsCommand = new RelayCommand(ShowSettings);
|
||||
_aboutCommand = new RelayCommand(async () => await _dialogService.ShowAboutDialogAsync());
|
||||
_quitCommand = new AsyncCommand(() => _trayProcessCommunicationService.QuitApplicationAsync());
|
||||
|
||||
_defaultProfile = _settingsService.GetDefaultShellProfile();
|
||||
|
||||
CreateMenuViewModel();
|
||||
}
|
||||
|
||||
private ShellProfile _defaultProfile;
|
||||
|
||||
private void UpdateDefaultShellProfile()
|
||||
{
|
||||
var defaultProfile = _settingsService.GetDefaultShellProfile();
|
||||
|
||||
// We need to rebuild the menu only if default profile Id or Name is changed
|
||||
var changeMenu = _defaultProfile == null || !_defaultProfile.Id.Equals(defaultProfile.Id) ||
|
||||
!string.Equals(_defaultProfile.Name, defaultProfile.Name, StringComparison.Ordinal);
|
||||
|
||||
_defaultProfile = defaultProfile;
|
||||
|
||||
if (changeMenu)
|
||||
{
|
||||
ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadKeyBindings() => _keyBindings = _settingsService.GetCommandKeyBindings();
|
||||
|
||||
private void OnClosed(object sender, EventArgs e)
|
||||
{
|
||||
MessengerInstance.Unregister(this);
|
||||
|
||||
ApplicationView.CloseRequested -= OnCloseRequest;
|
||||
ApplicationView.Closed -= OnClosed;
|
||||
Terminals.CollectionChanged -= OnTerminalsCollectionChanged;
|
||||
|
||||
_keyboardCommandService.ClearCommandHandlers();
|
||||
|
||||
_applicationSettings = null;
|
||||
|
||||
AddDefaultTabCommand = null;
|
||||
|
||||
Closed?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void OnShellProfileDeleted(ShellProfileDeletedMessage message)
|
||||
{
|
||||
_keyboardCommandService.DeregisterCommandHandler(message.ProfileId.ToString());
|
||||
|
||||
UpdateDefaultShellProfile();
|
||||
}
|
||||
|
||||
private void OnShellProfileChanged(ShellProfileChangedMessage message)
|
||||
{
|
||||
UpdateDefaultShellProfile();
|
||||
}
|
||||
|
||||
private void OnShellProfileAdded(ShellProfileAddedMessage message)
|
||||
{
|
||||
_keyboardCommandService.RegisterCommandHandler(message.ShellProfile.Id.ToString(),
|
||||
async () => await AddProfileByGuidAsync(message.ShellProfile.Id));
|
||||
|
||||
UpdateDefaultShellProfile();
|
||||
}
|
||||
|
||||
private void OnDefaultShellProfileChanged(DefaultShellProfileChangedMessage message)
|
||||
{
|
||||
UpdateDefaultShellProfile();
|
||||
}
|
||||
|
||||
private void OnTerminalsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
RaisePropertyChanged(nameof(ShowTabsOnTop));
|
||||
RaisePropertyChanged(nameof(ShowTabsOnBottom));
|
||||
}
|
||||
|
||||
public event EventHandler Closed;
|
||||
|
||||
public event EventHandler<NewWindowRequestedEventArgs> NewWindowRequested;
|
||||
|
||||
public event EventHandler ShowSettingsRequested;
|
||||
|
||||
public event EventHandler ActivatedMv;
|
||||
|
||||
public event EventHandler<TerminalViewModel> TabTearedOff;
|
||||
|
||||
public void TearOffTab(TerminalViewModel model)
|
||||
{
|
||||
TabTearedOff?.Invoke(this, model);
|
||||
}
|
||||
|
||||
public void FocusWindow()
|
||||
{
|
||||
ActivatedMv?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public RelayCommand AddDefaultTabCommand { get; private set; }
|
||||
|
||||
public string WindowTitle
|
||||
{
|
||||
get => _windowTitle;
|
||||
set
|
||||
{
|
||||
if (Set(ref _windowTitle, value))
|
||||
{
|
||||
ApplicationView.Title = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowTabsOnTop
|
||||
{
|
||||
get => TabsPosition == TabsPosition.Top;
|
||||
}
|
||||
|
||||
public bool ShowTabsOnBottom
|
||||
{
|
||||
get => TabsPosition == TabsPosition.Bottom;
|
||||
}
|
||||
|
||||
public bool UseAcrylicBackground
|
||||
{
|
||||
get => _useAcrylicBackground;
|
||||
set => Set(ref _useAcrylicBackground, value);
|
||||
}
|
||||
|
||||
public double BackgroundOpacity
|
||||
{
|
||||
get => _backgroundOpacity;
|
||||
set => Set(ref _backgroundOpacity, value);
|
||||
}
|
||||
|
||||
public TerminalViewModel SelectedTerminal
|
||||
{
|
||||
get => _selectedTerminal;
|
||||
set
|
||||
{
|
||||
var oldValue = _selectedTerminal;
|
||||
|
||||
if (Set(ref _selectedTerminal, value))
|
||||
{
|
||||
if (oldValue != null)
|
||||
{
|
||||
oldValue.IsSelected = false;
|
||||
}
|
||||
|
||||
if (_selectedTerminal != null)
|
||||
{
|
||||
_selectedTerminal.IsSelected = true;
|
||||
_selectedTerminal.FocusTerminal();
|
||||
|
||||
SetWindowTitle(_selectedTerminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TabsPosition TabsPosition
|
||||
{
|
||||
get => _tabsPosition;
|
||||
set => Set(ref _tabsPosition, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<TerminalViewModel> Terminals { get; } = new ObservableCollection<TerminalViewModel>();
|
||||
|
||||
public IApplicationView ApplicationView { get; }
|
||||
|
||||
#region Launching terminal sessions
|
||||
|
||||
public Task AddDefaultProfileAsync(NewTerminalLocation location)
|
||||
{
|
||||
var profile = _settingsService.GetDefaultShellProfile();
|
||||
|
||||
return AddProfileAsync(profile, location);
|
||||
}
|
||||
|
||||
private async Task AddSshProfileAsync(NewTerminalLocation location)
|
||||
{
|
||||
var profile = await _dialogService.ShowSshConnectionInfoDialogAsync().ConfigureAwait(true);
|
||||
|
||||
await AddProfileAsync(profile, location).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task AddQuickLaunchProfileAsync(NewTerminalLocation location)
|
||||
{
|
||||
var profile = await _dialogService.ShowCustomCommandDialogAsync().ConfigureAwait(true);
|
||||
|
||||
await AddProfileAsync(profile, location).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task AddProfileByGuidAsync(Guid profileId) =>
|
||||
AddProfileByGuidAsync(profileId, _applicationSettings.NewTerminalLocation);
|
||||
|
||||
private async Task AddProfileByGuidAsync(Guid profileId, NewTerminalLocation location)
|
||||
{
|
||||
var profile = _settingsService.GetShellProfile(profileId) ?? _settingsService.GetSshProfile(profileId);
|
||||
|
||||
await AddProfileAsync(profile, location).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// For serialization
|
||||
public Task AddTabAsync(string terminalState, int position)
|
||||
{
|
||||
return AddTabAsync(new ShellProfile(), terminalState, position);
|
||||
}
|
||||
|
||||
private Task AddProfileAsync(ShellProfile profile) =>
|
||||
AddProfileAsync(profile, _applicationSettings.NewTerminalLocation);
|
||||
|
||||
private Task AddProfileAsync(ShellProfile profile, NewTerminalLocation location)
|
||||
{
|
||||
if (profile == null)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (location == NewTerminalLocation.Tab)
|
||||
{
|
||||
return AddTabAsync(profile);
|
||||
}
|
||||
|
||||
NewWindowRequested?.Invoke(this, new NewWindowRequestedEventArgs(profile));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task AddTabAsync(ShellProfile profile) => AddTabAsync(profile, string.Empty, Terminals.Count);
|
||||
|
||||
private Task AddTabAsync(ShellProfile profile, string terminalState, int position)
|
||||
{
|
||||
profile.Tag = new DelayedHistorySaver(() => _commandHistoryService.MarkUsed(profile));
|
||||
|
||||
return ApplicationView.ExecuteOnUiThreadAsync(() =>
|
||||
{
|
||||
var terminal = new TerminalViewModel(_settingsService, _trayProcessCommunicationService, _dialogService, _keyboardCommandService,
|
||||
_applicationSettings, profile, ApplicationView, _clipboardService, terminalState);
|
||||
|
||||
terminal.PropertyChanged += Terminal_PropertyChanged;
|
||||
terminal.Closed += OnTerminalClosed;
|
||||
terminal.CloseLeftTabsRequested += Terminal_CloseLeftTabsRequested;
|
||||
terminal.CloseRightTabsRequested += Terminal_CloseRightTabsRequested;
|
||||
terminal.CloseOtherTabsRequested += Terminal_CloseOtherTabsRequested;
|
||||
terminal.DuplicateTabRequested += Terminal_DuplicateTabRequested;
|
||||
Terminals.Insert(Math.Min(position, Terminals.Count), terminal);
|
||||
|
||||
SelectedTerminal = terminal;
|
||||
});
|
||||
}
|
||||
|
||||
#endregion Launching terminal sessions
|
||||
|
||||
private void Terminal_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(sender is TerminalViewModel terminalViewModel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(TerminalViewModel.ShellTitle):
|
||||
case nameof(TerminalViewModel.TabTitle):
|
||||
|
||||
SetWindowTitle(terminalViewModel);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Local
|
||||
private Task SetWindowTitle(TerminalViewModel terminalViewModel)
|
||||
{
|
||||
return ApplicationView.ExecuteOnUiThreadAsync(() =>
|
||||
{
|
||||
WindowTitle = !_applicationSettings.ShowCustomTitleInTitlebar ||
|
||||
string.IsNullOrEmpty(terminalViewModel?.TabTitle)
|
||||
? terminalViewModel?.ShellTitle
|
||||
: terminalViewModel.TabTitle;
|
||||
}, CoreDispatcherPriority.Low);
|
||||
}
|
||||
|
||||
private async void Terminal_DuplicateTabRequested(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is TerminalViewModel terminal)
|
||||
{
|
||||
await AddTabAsync(terminal.ShellProfile.Clone()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Terminal_CloseOtherTabsRequested(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is TerminalViewModel terminal)
|
||||
{
|
||||
await Task.WhenAll(Terminals.Where(t => t != terminal).Select(t =>
|
||||
{
|
||||
Logger.Instance.Debug("Terminal with Id: {@id} closed.", t.Terminal.Id);
|
||||
return t.CloseCommand.ExecuteAsync();
|
||||
})).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Terminal_CloseRightTabsRequested(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is TerminalViewModel terminal)
|
||||
{
|
||||
var toRemove = Terminals.Skip(Terminals.IndexOf(terminal) + 1).ToList();
|
||||
|
||||
await Task.WhenAll(toRemove.Select(t =>
|
||||
{
|
||||
Logger.Instance.Debug("Terminal with Id: {@id} closed.", t.Terminal.Id);
|
||||
return t.CloseCommand.ExecuteAsync();
|
||||
})).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Terminal_CloseLeftTabsRequested(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is TerminalViewModel terminal)
|
||||
{
|
||||
var toRemove = Terminals.Take(Terminals.IndexOf(terminal)).ToList();
|
||||
|
||||
await Task.WhenAll(toRemove.Select(t =>
|
||||
{
|
||||
Logger.Instance.Debug("Terminal with Id: {@id} closed.", t.Terminal.Id);
|
||||
return t.CloseCommand.ExecuteAsync();
|
||||
})).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Task CloseAllTerminalsAsync()
|
||||
{
|
||||
return Task.WhenAll(Terminals.Select(terminal =>
|
||||
{
|
||||
terminal.PropertyChanged -= Terminal_PropertyChanged;
|
||||
terminal.Closed -= OnTerminalClosed;
|
||||
terminal.CloseLeftTabsRequested -= Terminal_CloseLeftTabsRequested;
|
||||
terminal.CloseRightTabsRequested -= Terminal_CloseRightTabsRequested;
|
||||
terminal.CloseOtherTabsRequested -= Terminal_CloseOtherTabsRequested;
|
||||
terminal.DuplicateTabRequested -= Terminal_DuplicateTabRequested;
|
||||
return terminal.CloseAsync();
|
||||
}));
|
||||
}
|
||||
|
||||
private void CloseCurrentTab()
|
||||
{
|
||||
SelectedTerminal?.CloseCommand.ExecuteAsync();
|
||||
}
|
||||
|
||||
private void OnApplicationSettingsChanged(ApplicationSettingsChangedMessage message)
|
||||
{
|
||||
var updateMenu = _applicationSettings != null &&
|
||||
(_applicationSettings.TabWindowCascadingAppMenu !=
|
||||
message.ApplicationSettings.TabWindowCascadingAppMenu ||
|
||||
!message.ApplicationSettings.TabWindowCascadingAppMenu &&
|
||||
_applicationSettings.NewTerminalLocation !=
|
||||
message.ApplicationSettings.NewTerminalLocation);
|
||||
|
||||
_applicationSettings = message.ApplicationSettings;
|
||||
|
||||
SetWindowTitle(SelectedTerminal);
|
||||
|
||||
ApplicationView.ExecuteOnUiThreadAsync(() =>
|
||||
{
|
||||
TabsPosition = message.ApplicationSettings.TabsPosition;
|
||||
RaisePropertyChanged(nameof(ShowTabsOnTop));
|
||||
RaisePropertyChanged(nameof(ShowTabsOnBottom));
|
||||
});
|
||||
|
||||
if (updateMenu)
|
||||
{
|
||||
ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnCloseRequest(object sender, CancelableEventArgs e)
|
||||
{
|
||||
if (_applicationSettings.ConfirmClosingWindows)
|
||||
{
|
||||
var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"),
|
||||
I18N.Translate("ConfirmCloseWindow"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(false);
|
||||
|
||||
if (result == DialogButton.OK)
|
||||
{
|
||||
await CloseAllTerminalsAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancelled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await CloseAllTerminalsAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTerminalClosed(object sender, EventArgs e)
|
||||
{
|
||||
if (!(sender is TerminalViewModel terminal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Instance.Debug("Terminal with Id: {@id} closed.", terminal.Terminal.Id);
|
||||
|
||||
terminal.PropertyChanged -= Terminal_PropertyChanged;
|
||||
terminal.Closed -= OnTerminalClosed;
|
||||
terminal.CloseLeftTabsRequested -= Terminal_CloseLeftTabsRequested;
|
||||
terminal.CloseRightTabsRequested -= Terminal_CloseRightTabsRequested;
|
||||
terminal.CloseOtherTabsRequested -= Terminal_CloseOtherTabsRequested;
|
||||
terminal.DuplicateTabRequested -= Terminal_DuplicateTabRequested;
|
||||
|
||||
ApplicationView.ExecuteOnUiThreadAsync(() =>
|
||||
{
|
||||
var wasSelected = _selectedTerminal == terminal;
|
||||
|
||||
Terminals.Remove(terminal);
|
||||
|
||||
if (Terminals.Count == 0)
|
||||
{
|
||||
ApplicationView.TryCloseAsync();
|
||||
}
|
||||
else if (wasSelected)
|
||||
{
|
||||
SelectedTerminal = Terminals.LastOrDefault(t => t != terminal);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void OnTerminalOptionsChanged(TerminalOptionsChangedMessage message)
|
||||
{
|
||||
ApplicationView.ExecuteOnUiThreadAsync(() =>
|
||||
{
|
||||
BackgroundOpacity = message.TerminalOptions.BackgroundOpacity;
|
||||
UseAcrylicBackground = message.TerminalOptions.UseAcrylicBackground;
|
||||
}, CoreDispatcherPriority.Low);
|
||||
}
|
||||
|
||||
private void OnKeyBindingChanged(KeyBindingsChangedMessage message)
|
||||
{
|
||||
LoadKeyBindings();
|
||||
|
||||
ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true);
|
||||
}
|
||||
|
||||
private void OnCommandHistoryChanged(CommandHistoryChangedMessage message)
|
||||
{
|
||||
ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true);
|
||||
}
|
||||
|
||||
private void SelectTabNumber(int tabNumber)
|
||||
{
|
||||
if (tabNumber < Terminals.Count)
|
||||
{
|
||||
SelectedTerminal = Terminals[tabNumber];
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectNextTab()
|
||||
{
|
||||
var currentIndex = Terminals.IndexOf(SelectedTerminal);
|
||||
var nextIndex = (currentIndex + 1) % Terminals.Count;
|
||||
SelectedTerminal = Terminals[nextIndex];
|
||||
}
|
||||
|
||||
private void SelectPreviousTab()
|
||||
{
|
||||
var currentIndex = Terminals.IndexOf(SelectedTerminal);
|
||||
var previousIndex = (currentIndex - 1 + Terminals.Count) % Terminals.Count;
|
||||
SelectedTerminal = Terminals[previousIndex];
|
||||
}
|
||||
|
||||
public void ShowSettings()
|
||||
{
|
||||
ShowSettingsRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void ToggleFullScreen()
|
||||
{
|
||||
ApplicationView.ToggleFullScreen();
|
||||
}
|
||||
|
||||
public void OnWindowKeyDown(int key, bool control, bool alt, bool shift, bool meta)
|
||||
{
|
||||
var binding = _keyBindings.Values.SelectMany(bs => bs).FirstOrDefault(b =>
|
||||
b.Key == key && b.Ctrl == control && b.Alt == alt && b.Shift == shift && b.Meta == meta);
|
||||
|
||||
if (binding != null)
|
||||
{
|
||||
_keyboardCommandService.SendCommand(binding.Command);
|
||||
}
|
||||
}
|
||||
|
||||
#region App menu
|
||||
|
||||
private const int RecentItemsMaxCount = 10;
|
||||
|
||||
private MenuViewModel _menuViewModel;
|
||||
|
||||
private readonly RelayCommand _newDefaultTabCommand;
|
||||
private readonly RelayCommand _newDefaultWindowCommand;
|
||||
private readonly RelayCommand _newRemoteTabCommand;
|
||||
private readonly RelayCommand _newRemoteWindowCommand;
|
||||
private readonly RelayCommand _newQuickLaunchTabCommand;
|
||||
private readonly RelayCommand _newQuickLaunchWindowCommand;
|
||||
private readonly RelayCommand _settingsCommand;
|
||||
private readonly RelayCommand _aboutCommand;
|
||||
private readonly ICommand _quitCommand;
|
||||
|
||||
public MenuViewModel AppMenuViewModel
|
||||
{
|
||||
get => _menuViewModel;
|
||||
private set => Set(ref _menuViewModel, value);
|
||||
}
|
||||
|
||||
private void CreateMenuViewModel()
|
||||
{
|
||||
var appMenuViewModel = new MenuViewModel();
|
||||
|
||||
if (_applicationSettings.TabWindowCascadingAppMenu)
|
||||
{
|
||||
var tabItem = new ExpandableMenuItemViewModel(
|
||||
I18N.TranslateWithFallback("MenuItem_NewTab_Text", "New Tab"),
|
||||
description: I18N.TranslateWithFallback("MenuItem_NewTab_Text", "Launches a session in a new tab."),
|
||||
icon: Mdl2Icon.Add());
|
||||
|
||||
FillCoreItems(tabItem.SubItems, NewTerminalLocation.Tab);
|
||||
|
||||
appMenuViewModel.Items.Add(tabItem);
|
||||
|
||||
var windowItem = new ExpandableMenuItemViewModel(
|
||||
I18N.TranslateWithFallback("MenuItem_NewWindow_Text", "New Window"),
|
||||
description: I18N.TranslateWithFallback("MenuItem_NewWindow_Description", "Launches a session in a new window."),
|
||||
icon: Mdl2Icon.NewWindow());
|
||||
|
||||
FillCoreItems(windowItem.SubItems, NewTerminalLocation.Window);
|
||||
|
||||
appMenuViewModel.Items.Add(windowItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillCoreItems(appMenuViewModel.Items, _applicationSettings.NewTerminalLocation);
|
||||
}
|
||||
|
||||
appMenuViewModel.Items.Add(new ExpandableMenuItemViewModel(I18N.TranslateWithFallback("Recent.Text", "Recent"),
|
||||
GetRecentMenuItems(), I18N.TranslateWithFallback("Recent_Description", "Recently opened sessions."),
|
||||
icon: Mdl2Icon.History()));
|
||||
|
||||
appMenuViewModel.Items.Add(new SeparatorMenuItemViewModel());
|
||||
|
||||
var settingsItem = new MenuItemViewModel(I18N.TranslateWithFallback("Settings.Text", "Settings"),
|
||||
_settingsCommand, I18N.TranslateWithFallback("Settings_Description", "Opens settings window."),
|
||||
icon: Mdl2Icon.Settings());
|
||||
|
||||
if (_keyBindings.TryGetValue(nameof(Command.ShowSettings), out var keyBindings) &&
|
||||
keyBindings.FirstOrDefault() is KeyBinding settingsKeyBinding &&
|
||||
_acceleratorKeyValidator.Valid(settingsKeyBinding.Key))
|
||||
{
|
||||
LoadKeyBindingsFromModel(settingsItem, settingsKeyBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsItem.KeyBinding = null;
|
||||
}
|
||||
|
||||
appMenuViewModel.Items.Add(settingsItem);
|
||||
|
||||
appMenuViewModel.Items.Add(new MenuItemViewModel(I18N.TranslateWithFallback("AboutDialog.Title", "About"), _aboutCommand,
|
||||
I18N.TranslateWithFallback("About_Description", "Basic info about the app."),
|
||||
icon: Mdl2Icon.Info()));
|
||||
|
||||
appMenuViewModel.Items.Add(new SeparatorMenuItemViewModel());
|
||||
|
||||
var quitItem = new MenuItemViewModel(I18N.TranslateWithFallback("Quit.Text", "Quit"), _quitCommand,
|
||||
I18N.TranslateWithFallback("Quit.Description", "Quit Fluent Terminal"),
|
||||
icon: Mdl2Icon.Cancel());
|
||||
appMenuViewModel.Items.Add(quitItem);
|
||||
|
||||
if (!appMenuViewModel.EquivalentTo(_menuViewModel))
|
||||
{
|
||||
AppMenuViewModel = appMenuViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
private void FillCoreItems(ObservableCollection<MenuItemViewModelBase> items, NewTerminalLocation location)
|
||||
{
|
||||
var tab = location == NewTerminalLocation.Tab;
|
||||
|
||||
if (_defaultProfile?.Name is string defaultProfileName)
|
||||
{
|
||||
var defaultProfileItem = new MenuItemViewModel(
|
||||
defaultProfileName, tab ? _newDefaultTabCommand : _newDefaultWindowCommand,
|
||||
I18N.TranslateWithFallback("MenuItem_DefaultProfile_Description",
|
||||
"Starts new terminal session based on the default profile."), icon: Mdl2Icon.FavoriteStar());
|
||||
|
||||
var defaultProfileCommand = tab ? nameof(Command.NewTab) : nameof(Command.NewWindow);
|
||||
|
||||
if (_keyBindings.TryGetValue(defaultProfileCommand, out var kbs) &&
|
||||
kbs.FirstOrDefault() is KeyBinding tabKeyBindings &&
|
||||
_acceleratorKeyValidator.Valid(tabKeyBindings.Key))
|
||||
{
|
||||
LoadKeyBindingsFromModel(defaultProfileItem, tabKeyBindings);
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultProfileItem.KeyBinding = null;
|
||||
}
|
||||
|
||||
items.Add(defaultProfileItem);
|
||||
}
|
||||
|
||||
var remoteConnectItem = new MenuItemViewModel(
|
||||
I18N.TranslateWithFallback("MenuItem_Remote_Text", "Remote Connect..."),
|
||||
tab ? _newRemoteTabCommand : _newRemoteWindowCommand,
|
||||
I18N.TranslateWithFallback("MenuItem_Remote_Description",
|
||||
"Opens a dialog for launching a new SSH or Mosh terminal session."),
|
||||
icon: Mdl2Icon.Globe());
|
||||
|
||||
var command = tab ? nameof(Command.NewSshTab) : nameof(Command.NewSshWindow);
|
||||
|
||||
if (_keyBindings.TryGetValue(command, out var keyBindings) &&
|
||||
keyBindings.FirstOrDefault() is KeyBinding remoteTabKeyBinding &&
|
||||
_acceleratorKeyValidator.Valid(remoteTabKeyBinding.Key))
|
||||
{
|
||||
LoadKeyBindingsFromModel(remoteConnectItem, remoteTabKeyBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
remoteConnectItem.KeyBinding = null;
|
||||
}
|
||||
|
||||
items.Add(remoteConnectItem);
|
||||
|
||||
var quickLaunchItem = new MenuItemViewModel(
|
||||
I18N.TranslateWithFallback("MenuItem_QuickLaunch_Text", "Quick Launch..."),
|
||||
tab ? _newQuickLaunchTabCommand : _newQuickLaunchWindowCommand,
|
||||
I18N.TranslateWithFallback("MenuItem_QuickLaunch_Description",
|
||||
"Opens a \"Quick Launch\" dialog for starting a new terminal session."),
|
||||
icon: Mdl2Icon.Play());
|
||||
|
||||
command = tab ? nameof(Command.NewCustomCommandTab) : nameof(Command.NewCustomCommandWindow);
|
||||
|
||||
if (_keyBindings.TryGetValue(command, out keyBindings) &&
|
||||
keyBindings.FirstOrDefault() is KeyBinding quickTabKeyBinding &&
|
||||
_acceleratorKeyValidator.Valid(quickTabKeyBinding.Key))
|
||||
{
|
||||
LoadKeyBindingsFromModel(quickLaunchItem, quickTabKeyBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
quickLaunchItem.KeyBinding = null;
|
||||
}
|
||||
|
||||
items.Add(quickLaunchItem);
|
||||
}
|
||||
|
||||
private ObservableCollection<MenuItemViewModel> GetRecentMenuItems() =>
|
||||
new ObservableCollection<MenuItemViewModel>(_commandHistoryService
|
||||
.GetHistoryRecentFirst(top: RecentItemsMaxCount).Select(CommandToMenuItem));
|
||||
|
||||
private MenuItemViewModel CommandToMenuItem(ExecutedCommand command)
|
||||
{
|
||||
var itemCommand = new RelayCommand(async () => await AddProfileAsync(command.ShellProfile),
|
||||
keepTargetAlive: true);
|
||||
var keyBinding = command.ShellProfile.KeyBindings?.FirstOrDefault() is KeyBinding kb
|
||||
? new MenuItemKeyBindingViewModel(kb)
|
||||
: null;
|
||||
|
||||
return new MenuItemViewModel(command.Value, itemCommand, keyBinding: keyBinding);
|
||||
}
|
||||
|
||||
private void LoadKeyBindingsFromModel(MenuItemViewModel menuItemViewModel, KeyBinding keyBinding)
|
||||
{
|
||||
if (!_acceleratorKeyValidator.Valid(keyBinding.Key))
|
||||
{
|
||||
menuItemViewModel.KeyBinding = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (menuItemViewModel.KeyBinding == null)
|
||||
{
|
||||
menuItemViewModel.KeyBinding = new MenuItemKeyBindingViewModel(keyBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
menuItemViewModel.KeyBinding.Key = keyBinding.Key;
|
||||
menuItemViewModel.KeyBinding.Ctrl = keyBinding.Ctrl;
|
||||
menuItemViewModel.KeyBinding.Alt = keyBinding.Alt;
|
||||
menuItemViewModel.KeyBinding.Shift = keyBinding.Shift;
|
||||
menuItemViewModel.KeyBinding.Windows = keyBinding.Meta;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion App menu
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class ExpandableMenuItemViewModel : MenuItemViewModelBase
|
||||
{
|
||||
public ObservableCollection<MenuItemViewModelBase> SubItems { get; }
|
||||
|
||||
public ExpandableMenuItemViewModel(string text, IEnumerable<MenuItemViewModelBase> subItems = null,
|
||||
string description = null, Mdl2Icon icon = null) : base(text, description, icon)
|
||||
{
|
||||
if (subItems == null)
|
||||
{
|
||||
SubItems = new ObservableCollection<MenuItemViewModelBase>();
|
||||
}
|
||||
else if (subItems is ObservableCollection<MenuItemViewModelBase> observableSubItems)
|
||||
{
|
||||
SubItems = observableSubItems;
|
||||
}
|
||||
else
|
||||
{
|
||||
SubItems = new ObservableCollection<MenuItemViewModelBase>(subItems);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool EquivalentTo(MenuItemViewModelBase other)
|
||||
{
|
||||
if (!base.EquivalentTo(other)) return false;
|
||||
|
||||
if (!(other is ExpandableMenuItemViewModel otherExpandable) ||
|
||||
SubItems.Count != otherExpandable.SubItems.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !SubItems.Where((t, i) => !t.EquivalentTo(otherExpandable.SubItems[i])).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public sealed class Mdl2Icon
|
||||
{
|
||||
public string Color { get; }
|
||||
public string Glyph { get; }
|
||||
|
||||
private Mdl2Icon(string glyph, string color = null)
|
||||
{
|
||||
Glyph = glyph;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public static Mdl2Icon Link(string color = null) => new Mdl2Icon("\uE71B", color);
|
||||
|
||||
public static Mdl2Icon Copy(string color = null) => new Mdl2Icon("\uE8C8", color);
|
||||
|
||||
public static Mdl2Icon Paste(string color = null) => new Mdl2Icon("\uE77F", color);
|
||||
|
||||
public static Mdl2Icon Edit(string color = null) => new Mdl2Icon("\uE70F", color);
|
||||
|
||||
public static Mdl2Icon Search(string color = null) => new Mdl2Icon("\uE721", color);
|
||||
|
||||
public static Mdl2Icon Add(string color = null) => new Mdl2Icon("\uE710", color);
|
||||
|
||||
public static Mdl2Icon Cancel(string color = null) => new Mdl2Icon("\uE711", color);
|
||||
|
||||
public static Mdl2Icon PaginationDotOutline10(string color = null) => new Mdl2Icon("\uF126", color);
|
||||
|
||||
public static Mdl2Icon PaginationDotSolid10(string color = null) => new Mdl2Icon("\uF127", color);
|
||||
|
||||
public static Mdl2Icon NewWindow(string color = null) => new Mdl2Icon("\uE78B", color);
|
||||
|
||||
public static Mdl2Icon History(string color = null) => new Mdl2Icon("\uE81C", color);
|
||||
|
||||
public static Mdl2Icon Settings(string color = null) => new Mdl2Icon("\uE713", color);
|
||||
|
||||
public static Mdl2Icon Info(string color = null) => new Mdl2Icon("\uE946", color);
|
||||
|
||||
public static Mdl2Icon FavoriteStar(string color = null) => new Mdl2Icon("\uE734", color);
|
||||
|
||||
public static Mdl2Icon Globe(string color = null) => new Mdl2Icon("\uE774", color);
|
||||
|
||||
public static Mdl2Icon Play(string color = null) => new Mdl2Icon("\uE768", color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
using FluentTerminal.Models;
|
||||
using GalaSoft.MvvmLight;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class MenuItemKeyBindingViewModel : ViewModelBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private int _key;
|
||||
|
||||
public int Key
|
||||
{
|
||||
get => _key;
|
||||
set => Set(ref _key, value);
|
||||
}
|
||||
|
||||
private int _keyModifiers;
|
||||
|
||||
// Corresponds to https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkeymodifiers
|
||||
public int KeyModifiers
|
||||
{
|
||||
get => _keyModifiers;
|
||||
private set => Set(ref _keyModifiers, value);
|
||||
}
|
||||
|
||||
private bool _ctrl;
|
||||
|
||||
public bool Ctrl
|
||||
{
|
||||
get => _ctrl;
|
||||
set
|
||||
{
|
||||
if (Set(ref _ctrl, value))
|
||||
{
|
||||
SetKeyModifiers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _alt;
|
||||
|
||||
public bool Alt
|
||||
{
|
||||
get => _alt;
|
||||
set
|
||||
{
|
||||
if (Set(ref _alt, value))
|
||||
{
|
||||
SetKeyModifiers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _shift;
|
||||
|
||||
public bool Shift
|
||||
{
|
||||
get => _shift;
|
||||
set
|
||||
{
|
||||
if (Set(ref _shift, value))
|
||||
{
|
||||
SetKeyModifiers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _windows;
|
||||
|
||||
public bool Windows
|
||||
{
|
||||
get => _windows;
|
||||
set
|
||||
{
|
||||
if (Set(ref _windows, value))
|
||||
{
|
||||
SetKeyModifiers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Constructors
|
||||
|
||||
public MenuItemKeyBindingViewModel(int key = 0, bool ctrl = false, bool alt = false, bool shift = false,
|
||||
bool windows = false)
|
||||
{
|
||||
_key = key;
|
||||
_ctrl = ctrl;
|
||||
_alt = alt;
|
||||
_shift = shift;
|
||||
_windows = windows;
|
||||
|
||||
SetKeyModifiers();
|
||||
}
|
||||
|
||||
public MenuItemKeyBindingViewModel(KeyBinding keyBinding) : this(keyBinding.Key, keyBinding.Ctrl,
|
||||
keyBinding.Alt, keyBinding.Shift, keyBinding.Meta)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region Methods
|
||||
|
||||
private void SetKeyModifiers()
|
||||
{
|
||||
// Based on VirtualKeyModifiers enum values (https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkeymodifiers)
|
||||
var result = 0;
|
||||
|
||||
if (_ctrl)
|
||||
{
|
||||
result |= 1;
|
||||
}
|
||||
|
||||
if (_alt)
|
||||
{
|
||||
result |= 2;
|
||||
}
|
||||
|
||||
if (_shift)
|
||||
{
|
||||
result |= 4;
|
||||
}
|
||||
|
||||
if (_windows)
|
||||
{
|
||||
result |= 8;
|
||||
}
|
||||
|
||||
KeyModifiers = result;
|
||||
}
|
||||
|
||||
public bool EquivalentTo(MenuItemKeyBindingViewModel other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
if (other == null) return false;
|
||||
|
||||
return _key == other._key && _keyModifiers == other._keyModifiers;
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class MenuItemViewModel : MenuItemViewModelBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private MenuItemKeyBindingViewModel _keyBinding;
|
||||
|
||||
public MenuItemKeyBindingViewModel KeyBinding
|
||||
{
|
||||
get => _keyBinding;
|
||||
set => Set(ref _keyBinding, value);
|
||||
}
|
||||
|
||||
public ICommand Command { get; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Constructors
|
||||
|
||||
public MenuItemViewModel(string text, ICommand command, string description = null, Mdl2Icon icon = null,
|
||||
MenuItemKeyBindingViewModel keyBinding = null) : base(text, description, icon)
|
||||
{
|
||||
_keyBinding = keyBinding;
|
||||
Command = command ?? throw new ArgumentNullException(nameof(command));
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region Methods
|
||||
|
||||
public override bool EquivalentTo(MenuItemViewModelBase other)
|
||||
{
|
||||
if (!base.EquivalentTo(other)) return false;
|
||||
|
||||
if (!(other is MenuItemViewModel menuItem)) return false;
|
||||
|
||||
return _keyBinding?.EquivalentTo(menuItem._keyBinding) ?? menuItem._keyBinding == null;
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using FluentTerminal.Models;
|
||||
using GalaSoft.MvvmLight;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class MenuItemViewModelBase : ViewModelBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private string _text;
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => _text;
|
||||
set => Set(ref _text, value);
|
||||
}
|
||||
|
||||
private string _description;
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => _description;
|
||||
set => Set(ref _description, value);
|
||||
}
|
||||
|
||||
private Mdl2Icon _icon;
|
||||
|
||||
public Mdl2Icon Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => Set(ref _icon, value);
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Constructor
|
||||
|
||||
protected MenuItemViewModelBase(string text, string description, Mdl2Icon icon)
|
||||
{
|
||||
_text = text;
|
||||
_description = description;
|
||||
_icon = icon;
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Methods
|
||||
|
||||
public virtual bool EquivalentTo(MenuItemViewModelBase other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
if (other == null) return false;
|
||||
|
||||
return _text.NullableEqualTo(other._text) && _description.NullableEqualTo(other._description) &&
|
||||
(_icon?.Equals(other._icon) ?? other._icon == null);
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using GalaSoft.MvvmLight;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class MenuViewModel : ViewModelBase
|
||||
{
|
||||
public ObservableCollection<MenuItemViewModelBase> Items { get; }
|
||||
|
||||
public MenuViewModel(IEnumerable<MenuItemViewModelBase> items = null)
|
||||
{
|
||||
if (items == null)
|
||||
{
|
||||
Items = new ObservableCollection<MenuItemViewModelBase>();
|
||||
}
|
||||
else if (items is ObservableCollection<MenuItemViewModelBase> observableItems)
|
||||
{
|
||||
Items = observableItems;
|
||||
}
|
||||
else
|
||||
{
|
||||
Items = new ObservableCollection<MenuItemViewModelBase>(items);
|
||||
}
|
||||
}
|
||||
|
||||
public bool EquivalentTo(MenuViewModel other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
if (other == null) return false;
|
||||
|
||||
if (Items.Count != other.Items.Count) return false;
|
||||
|
||||
return !Items.Where((t, i) => !t.EquivalentTo(other.Items[i])).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class RadioMenuItemViewModel : MenuItemViewModelBase
|
||||
{
|
||||
public object BindingSource { get; }
|
||||
public string BindingPath { get; }
|
||||
public string GroupName { get; }
|
||||
|
||||
public RadioMenuItemViewModel(string text, string groupName, object bindingSource, string bindingPath = null, string description = null, Mdl2Icon icon = null)
|
||||
: base(text, description, icon)
|
||||
{
|
||||
GroupName = groupName ?? throw new ArgumentNullException(nameof(groupName));
|
||||
BindingSource = bindingSource ?? throw new ArgumentNullException(nameof(bindingSource));
|
||||
BindingPath = bindingPath;
|
||||
}
|
||||
|
||||
public override bool EquivalentTo(MenuItemViewModelBase other)
|
||||
{
|
||||
if (!base.EquivalentTo(other)) return false;
|
||||
|
||||
if (!(other is RadioMenuItemViewModel radioMenuItem)) return false;
|
||||
|
||||
return GroupName == radioMenuItem.GroupName && BindingSource == radioMenuItem.BindingSource && BindingPath == radioMenuItem.BindingPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class SeparatorMenuItemViewModel : MenuItemViewModelBase
|
||||
{
|
||||
public SeparatorMenuItemViewModel()
|
||||
: base(string.Empty, string.Empty, null)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool EquivalentTo(MenuItemViewModelBase other)
|
||||
{
|
||||
return other is SeparatorMenuItemViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Menu
|
||||
{
|
||||
public class ToggleMenuItemViewModel : MenuItemViewModelBase
|
||||
{
|
||||
public object BindingSource { get; }
|
||||
public string BindingPath { get; }
|
||||
|
||||
public ToggleMenuItemViewModel(string text, object bindingSource, string bindingPath = null, string description = null, Mdl2Icon icon = null)
|
||||
: base(text, description, icon)
|
||||
{
|
||||
BindingSource = bindingSource ?? throw new ArgumentNullException(nameof(bindingSource));
|
||||
BindingPath = bindingPath;
|
||||
}
|
||||
|
||||
public override bool EquivalentTo(MenuItemViewModelBase other)
|
||||
{
|
||||
if (!base.EquivalentTo(other)) return false;
|
||||
|
||||
if (!(other is ToggleMenuItemViewModel toggleMenuItem)) return false;
|
||||
|
||||
return BindingSource == toggleMenuItem.BindingSource && BindingPath == toggleMenuItem.BindingPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
public class OverlayViewModel : ViewModelBase
|
||||
{
|
||||
private readonly DispatcherTimer _overlayTimer;
|
||||
private bool _showOverlay;
|
||||
private string _overlayContent;
|
||||
|
||||
// Important! The constructor has to be called from the UI thread.
|
||||
public OverlayViewModel()
|
||||
{
|
||||
_overlayTimer = new DispatcherTimer {Interval = new TimeSpan(0, 0, 2)};
|
||||
}
|
||||
|
||||
public bool ShowOverlay
|
||||
{
|
||||
get => _showOverlay;
|
||||
set => Set(ref _showOverlay, value);
|
||||
}
|
||||
|
||||
public string OverlayContent
|
||||
{
|
||||
get => _overlayContent;
|
||||
set => Set(ref _overlayContent, value);
|
||||
}
|
||||
|
||||
public void Show(string message)
|
||||
{
|
||||
OverlayContent = message;
|
||||
ShowOverlay = true;
|
||||
|
||||
if (_overlayTimer.IsEnabled)
|
||||
{
|
||||
_overlayTimer.Stop();
|
||||
_overlayTimer.Tick -= OnResizeOverlayTimerFinished;
|
||||
}
|
||||
_overlayTimer.Start();
|
||||
_overlayTimer.Tick += OnResizeOverlayTimerFinished;
|
||||
}
|
||||
|
||||
private void OnResizeOverlayTimerFinished(object sender, object e)
|
||||
{
|
||||
_overlayTimer.Stop();
|
||||
_overlayTimer.Tick -= OnResizeOverlayTimerFinished;
|
||||
ShowOverlay = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentTerminal.App.Services;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.App.ViewModels.Infrastructure;
|
||||
using FluentTerminal.App.ViewModels.Profiles;
|
||||
using FluentTerminal.App.ViewModels.Settings;
|
||||
using FluentTerminal.Models;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all profile view models. Implements logic for saving, editing, resetting, etc.
|
||||
/// </summary>
|
||||
public abstract class ProfileViewModelBase<T> : ViewModelBase where T : ProfileProviderViewModelBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
protected readonly IDialogService DialogService;
|
||||
protected readonly ISettingsService SettingsService;
|
||||
|
||||
private List<KeyBinding> _bindingsBeforeEdit;
|
||||
private Dictionary<string, string> _environmentVariablesBeforeEdit;
|
||||
private string _nameBeforeEdit;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Properties
|
||||
|
||||
protected bool IsNew { get; private set; }
|
||||
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
private bool _inEditMode;
|
||||
|
||||
public bool InEditMode
|
||||
{
|
||||
get => _inEditMode;
|
||||
set => Set(ref _inEditMode, value);
|
||||
}
|
||||
|
||||
private string _name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => Set(ref _name, value);
|
||||
}
|
||||
|
||||
public KeyBindingsViewModel KeyBindings { get; }
|
||||
|
||||
public ObservableCollection<EnvironmentVariableViewModel> EnvironmentVariables { get; } = new ObservableCollection<EnvironmentVariableViewModel>();
|
||||
|
||||
public T ProfileVm { get; protected set; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Events
|
||||
|
||||
// Needs to be triggered from UI thread
|
||||
public event EventHandler Deleted;
|
||||
|
||||
#endregion Events
|
||||
|
||||
#region Commands
|
||||
|
||||
public IAsyncCommand CancelEditCommand { get; }
|
||||
|
||||
public IAsyncCommand DeleteCommand { get; }
|
||||
|
||||
public RelayCommand EditCommand { get; }
|
||||
|
||||
public IAsyncCommand SaveChangesCommand { get; }
|
||||
|
||||
public IAsyncCommand AddKeyboardShortcutCommand { get; }
|
||||
|
||||
#endregion Commands
|
||||
|
||||
#region Constructor
|
||||
|
||||
protected ProfileViewModelBase(ShellProfile shellProfile, ISettingsService settingsService, IDialogService dialogService, bool isNew)
|
||||
{
|
||||
SettingsService = settingsService;
|
||||
DialogService = dialogService;
|
||||
IsNew = isNew;
|
||||
|
||||
KeyBindings = new KeyBindingsViewModel(shellProfile.Id.ToString(), dialogService, string.Empty, false);
|
||||
|
||||
foreach (var environmentVariable in shellProfile.EnvironmentVariables)
|
||||
{
|
||||
EnvironmentVariables.Add(new EnvironmentVariableViewModel
|
||||
{
|
||||
Name = environmentVariable.Key,
|
||||
Value = environmentVariable.Value
|
||||
});
|
||||
}
|
||||
|
||||
Initialize(shellProfile);
|
||||
|
||||
DeleteCommand = new AsyncCommand(DeleteAsync, CanDelete);
|
||||
EditCommand = new RelayCommand(Edit);
|
||||
CancelEditCommand = new AsyncCommand(CancelEditAsync);
|
||||
SaveChangesCommand = new AsyncCommand(SaveChangesAsync);
|
||||
AddKeyboardShortcutCommand = new AsyncCommand(AddKeyboardShortcut);
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Methods
|
||||
|
||||
// Requires UI thread
|
||||
// Loads view model properties from the input shellProfile
|
||||
protected void Initialize(ShellProfile shellProfile)
|
||||
{
|
||||
Id = shellProfile.Id;
|
||||
Name = shellProfile.Name;
|
||||
|
||||
KeyBindings.Clear();
|
||||
foreach (var keyBinding in shellProfile.KeyBindings.Select(x => new KeyBinding(x)).ToList())
|
||||
{
|
||||
KeyBindings.Add(keyBinding);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool HasChanges()
|
||||
{
|
||||
return ProfileVm.HasChanges()
|
||||
|| !_nameBeforeEdit.NullableEqualTo(_name)
|
||||
|| !(_bindingsBeforeEdit?.SequenceEqual(KeyBindings.KeyBindings.Select(x => x.Model).ToList()) ?? false)
|
||||
|| !(_environmentVariablesBeforeEdit?.SequenceEqual(EnvironmentVariables.ToDictionary(x => x.Name, x => x.Value)) ?? false);
|
||||
}
|
||||
|
||||
// Requires UI thread
|
||||
private async Task DeleteAsync()
|
||||
{
|
||||
// ConfigureAwait(true) because we need to trigger Deleted event from the calling (UI) thread.
|
||||
var result = await DialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"),
|
||||
I18N.Translate("ConfirmDeleteProfile"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true);
|
||||
|
||||
if (result == DialogButton.OK)
|
||||
{
|
||||
Deleted?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract bool CanDelete();
|
||||
|
||||
private void Edit()
|
||||
{
|
||||
if (InEditMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_bindingsBeforeEdit = KeyBindings.KeyBindings.Select(x => x.Model).ToList();
|
||||
_environmentVariablesBeforeEdit = EnvironmentVariables.ToDictionary(x => x.Name, x => x.Value);
|
||||
_nameBeforeEdit = _name;
|
||||
|
||||
KeyBindings.Editable = true;
|
||||
InEditMode = true;
|
||||
}
|
||||
|
||||
// Requires UI thread
|
||||
private async Task CancelEditAsync()
|
||||
{
|
||||
if (IsNew)
|
||||
{
|
||||
await DeleteAsync().ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasChanges())
|
||||
{
|
||||
KeyBindings.Editable = false;
|
||||
InEditMode = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ConfigureAwait(true) because we're setting some view-model properties afterwards
|
||||
if (await DialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"),
|
||||
I18N.Translate("ConfirmDiscardChanges"), DialogButton.OK, DialogButton.Cancel)
|
||||
.ConfigureAwait(true) == DialogButton.OK)
|
||||
{
|
||||
// Cancelled, so rollback
|
||||
// ConfigureAwait(true) because we're setting some view-model properties afterwards
|
||||
await ProfileVm.RejectChangesAsync().ConfigureAwait(true);
|
||||
|
||||
KeyBindings.Editable = false;
|
||||
InEditMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Requires UI thread
|
||||
private async Task SaveChangesAsync()
|
||||
{
|
||||
// ConfigureAwait(true) because we're setting some view-model properties afterwards.
|
||||
var error = await ProfileVm.AcceptChangesAsync().ConfigureAwait(true);
|
||||
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
await DialogService.ShowMessageDialogAsync(I18N.Translate("InvalidInput"), error, DialogButton.OK)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (EnvironmentVariables.Select(x => x.Name).Any(string.IsNullOrWhiteSpace))
|
||||
{
|
||||
await DialogService.ShowMessageDialogAsync(I18N.Translate("InvalidInput"),
|
||||
I18N.Translate("EmptyEnvironmentVariableName"), DialogButton.OK).ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (EnvironmentVariables.Select(x => x.Name).Distinct().Count() != EnvironmentVariables.Count)
|
||||
{
|
||||
await DialogService.ShowMessageDialogAsync(I18N.Translate("InvalidInput"),
|
||||
I18N.Translate("DuplicateEnvironmentVariable"), DialogButton.OK).ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var profile = ProfileVm.Model;
|
||||
|
||||
profile.Id = Id;
|
||||
profile.Name = _name;
|
||||
profile.KeyBindings = KeyBindings.KeyBindings.Select(x => x.Model).ToList();
|
||||
profile.EnvironmentVariables = EnvironmentVariables.ToDictionary(x => x.Name, x => x.Value);
|
||||
|
||||
if (profile is SshProfile sshProfile)
|
||||
{
|
||||
SettingsService.SaveSshProfile(sshProfile, IsNew);
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsService.SaveShellProfile(profile, IsNew);
|
||||
}
|
||||
|
||||
KeyBindings.Editable = false;
|
||||
InEditMode = false;
|
||||
IsNew = false;
|
||||
}
|
||||
|
||||
private Task AddKeyboardShortcut()
|
||||
{
|
||||
return KeyBindings.ShowAddKeyBindingDialogAsync();
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using System.Threading.Tasks;
|
||||
using FluentTerminal.App.Services;
|
||||
using FluentTerminal.App.Services.Utilities;
|
||||
using FluentTerminal.App.ViewModels.Infrastructure;
|
||||
using FluentTerminal.Models;
|
||||
|
||||
namespace FluentTerminal.App.ViewModels.Profiles
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for common profiles (PowerShell, CMD, WSL).
|
||||
/// </summary>
|
||||
public class CommonProfileProviderViewModel : ProfileProviderViewModelBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly IFileSystemService _fileSystemService;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Properties
|
||||
|
||||
public bool PreInstalled { get; private set; }
|
||||
|
||||
private string _location;
|
||||
|
||||
public string Location
|
||||
{
|
||||
get => _location;
|
||||
set => Set(ref _location, value);
|
||||
}
|
||||
|
||||
private string _workingDirectory;
|
||||
|
||||
public string WorkingDirectory
|
||||
{
|
||||
get => _workingDirectory;
|
||||
set => Set(ref _workingDirectory, value);
|
||||
}
|
||||
|
||||
private string _arguments;
|
||||
|
||||
public string Arguments
|
||||
{
|
||||
get => _arguments;
|
||||
set => Set(ref _arguments, value);
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Commands
|
||||
|
||||
public IAsyncCommand BrowseForCustomShellCommand { get; }
|
||||
|
||||
public IAsyncCommand BrowseForWorkingDirectoryCommand { get; }
|
||||
|
||||
#endregion Commands
|
||||
|
||||
#region Constructor
|
||||
|
||||
public CommonProfileProviderViewModel(ISettingsService settingsService, IApplicationView applicationView,
|
||||
IFileSystemService fileSystemService, ShellProfile original = null) : base(settingsService, applicationView,
|
||||
true, original)
|
||||
{
|
||||
_fileSystemService = fileSystemService;
|
||||
|
||||
BrowseForCustomShellCommand = new AsyncCommand(BrowseForCustomShell);
|
||||
BrowseForWorkingDirectoryCommand = new AsyncCommand(BrowseForWorkingDirectory);
|
||||
|
||||
Initialize(Model);
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Methods
|
||||
|
||||
private void Initialize(ShellProfile profile)
|
||||
{
|
||||
PreInstalled = profile.PreInstalled;
|
||||
Location = profile.Location;
|
||||
Arguments = profile.Arguments;
|
||||
WorkingDirectory = profile.WorkingDirectory;
|
||||
}
|
||||
|
||||
protected override void LoadFromProfile(ShellProfile profile)
|
||||
{
|
||||
base.LoadFromProfile(profile);
|
||||
|
||||
Initialize(profile);
|
||||
}
|
||||
|
||||
protected override async Task CopyToProfileAsync(ShellProfile profile)
|
||||
{
|
||||
await base.CopyToProfileAsync(profile).ConfigureAwait(false);
|
||||
|
||||
profile.Location = _location;
|
||||
profile.Arguments = _arguments;
|
||||
profile.WorkingDirectory = _workingDirectory;
|
||||
}
|
||||
|
||||
public override async Task<string> ValidateAsync()
|
||||
{
|
||||
var error = await base.ValidateAsync().ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_location))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
error = I18N.Translate("LocationCantBeEmpty");
|
||||
|
||||
return string.IsNullOrEmpty(error) ? "Location cannot be empty." : error;
|
||||
}
|
||||
|
||||
public override bool HasChanges()
|
||||
{
|
||||
return base.HasChanges() || !Model.Location.NullableEqualTo(_location) ||
|
||||
!Model.WorkingDirectory.NullableEqualTo(_workingDirectory) ||
|
||||
!Model.Arguments.NullableEqualTo(_arguments);
|
||||
}
|
||||
|
||||
// Requires UI thread
|
||||
private async Task BrowseForCustomShell()
|
||||
{
|
||||
// ConfigureAwait(true) because we're setting some view-model properties afterwards.
|
||||
var file = await _fileSystemService.OpenFileAsync(new[] { ".exe" }).ConfigureAwait(true);
|
||||
if (file != null)
|
||||
{
|
||||
Location = file.Path;
|
||||
}
|
||||
}
|
||||
|
||||
// Requires UI thread
|
||||
private async Task BrowseForWorkingDirectory()
|
||||
{
|
||||
// ConfigureAwait(true) because we're setting some view-model properties afterwards.
|
||||
var directory = await _fileSystemService.BrowseForDirectoryAsync().ConfigureAwait(true);
|
||||
if (directory != null)
|
||||
{
|
||||
WorkingDirectory = directory;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
Loaded 100 of 783 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user