Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit fcf9ae0

Browse files
committed
Squash merge branch 'WebAuthAPI'
- Add wrapper and abstraction for Spotify's web access (auth + API) - Implemented ToastifyAPI.Core.Auth - Create ToastifyWebAPI wrapper and abstractions - Add version information to installer - Add ToastifyWebAuthAPI.dll to NSIS script - Change post-build.cmd to use ToastifyWebAuthAPI's PreBuildTool - Add ToastifyWebAuthAPI private dependency
1 parent 52287b8 commit fcf9ae0

28 files changed

+908
-39
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ UpgradeLog*.htm
183183

184184
# =================================
185185

186+
# Dependenceis
187+
/_dependencies/
188+
186189
# Auto-generated files
187190
*.g.cs
188191

InstallationScript/Install.nsi

+19-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ ManifestSupportedOS "{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" # Windows 10
3131
OutFile "ToastifyInstaller.exe"
3232
InstallDir $PROGRAMFILES64\Toastify
3333

34+
# Installer's Version Information
35+
VIProductVersion ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0
36+
VIFileVersion ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0
37+
VIAddVersionKey "ProductVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
38+
VIAddVersionKey "FileVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
39+
VIAddVersionKey "ProductName" "${APPNAME}"
40+
VIAddVersionKey "FileDescription" "${APPNAME} Installer"
41+
VIAddVersionKey "LegalCopyright" "© 2018 Alessandro Attard Barbini"
42+
3443

3544
;--------------------------------
3645
; Pages
@@ -86,18 +95,21 @@ Section "${APPNAME} (required)"
8695

8796
# ToastifyAPI.dll
8897
${If} ${IsWin10}
89-
File /oname=ToastifyAPI.dll "ToastifyAPI_UWP.dll"
90-
File /oname=ToastifyAPI.pdb "ToastifyAPI_UWP.pdb"
98+
File /oname=ToastifyAPI.dll "ToastifyAPI_UWP.dll"
99+
File /oname=ToastifyAPI.pdb "ToastifyAPI_UWP.pdb"
91100
${Else}
92-
File /oname=ToastifyAPI.dll "ToastifyAPI_Win32.dll"
93-
File /oname=ToastifyAPI.pdb "ToastifyAPI_Win32.pdb"
101+
File /oname=ToastifyAPI.dll "ToastifyAPI_Win32.dll"
102+
File /oname=ToastifyAPI.pdb "ToastifyAPI_Win32.pdb"
94103
${EndIf}
95104

96105
# Toastify.exe
97106
File "Toastify.exe"
98107
File "Toastify.exe.config"
99108
File "Toastify.pdb"
100109

110+
# ToastifyWebAuthAPI.dll
111+
File /nonfatal "ToastifyWebAuthAPI.dll"
112+
101113
# Resources
102114
File "LICENSES\LICENSE"
103115
File "LICENSES\LICENSE-3RD-PARTY"
@@ -166,6 +178,9 @@ Section "un.Toastify"
166178
Delete "$INSTDIR\Toastify.exe.config"
167179
Delete "$INSTDIR\Toastify.pdb"
168180

181+
# ToastifyWebAuthAPI.dll
182+
Delete "$INSTDIR\ToastifyWebAuthAPI.dll"
183+
169184
# Resources
170185
Delete "$INSTDIR\LICENSE"
171186
Delete "$INSTDIR\LICENSE-3RD-PARTY"

Toastify/Toastify.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="MSBuild.Sdk.Extras/1.6.55" ToolsVersion="15.0">
33
<!-- Project Info -->
44
<PropertyGroup>
@@ -207,7 +207,7 @@
207207

208208
<!-- Execute pre-build.cmd script -->
209209
<Message Importance="High" Text="[PRE-BUILD] Execute pre-build.cmd script" />
210-
<Exec Command="&quot;$(ProjectDir)pre-build.cmd&quot; &quot;$(ProjectFileName)&quot; &quot;$(ProjectDir)&quot; &quot;$(DevEnvDir)&quot;" />
210+
<Exec Command="&quot;$(ProjectDir)pre-build.cmd&quot; &quot;$(SolutionDir)&quot; &quot;$(DevEnvDir)&quot;" />
211211

212212
<!-- Transform TextTemplate files -->
213213
<Message Importance="High" Text="[PRE-BUILD] Transform TextTemplate files" />
@@ -252,10 +252,12 @@
252252
<ItemGroup>
253253
<NsisFiles Include="$(TargetDir)*.nsi;$(TargetDir)*.nsh" />
254254
<ToastifyInstaller Include="$(TargetDir)ToastifyInstaller.exe" />
255+
<ToastifyWebAuthAPIDll Include="$(TargetDir)ToastifyWebAuthAPI.dll" />
255256
</ItemGroup>
256257
<RemoveDir Directories="$(TargetDir)lib;$(TargetDir)LICENSES;$(TargetDir)Resources" />
257258
<Delete Files="@(ToastifyApiWin32Files->'$(TargetDir)%(Filename)_Win32%(Extension)')" />
258259
<Delete Files="@(ToastifyApiUWPFiles->'$(TargetDir)%(Filename)_UWP%(Extension)')" />
260+
<Delete Files="@(ToastifyWebAuthAPIDll)" />
259261
<Delete Files="@(NsisFiles);@(ToastifyInstaller)" />
260262
<Delete Files="$(TargetDir)log.log" />
261263
</Target>

Toastify/post-build.cmd

+85-23
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,119 @@
22
SetLocal EnableExtensions EnableDelayedExpansion
33

44
SET nsisInstallerFileName=ToastifyInstaller.exe
5-
SET sfxArchiveName=ToastifyInstaller
65

76

8-
:: ----------[ POST-BUILD ]--------------------------------
9-
:: [in]ConfigurationName [in]DevEnvDir [in]SolutionDir [in]TargetDir [in]TargetFileName
7+
REM ----------[ POST-BUILD ]--------------------------------
8+
REM [in]ConfigurationName [in]DevEnvDir [in]SolutionDir [in]TargetDir [in]TargetFileName
109

1110
SET "ConfigurationName=%~1"
1211
SET "DevEnvDir=%~2"
1312
SET "SolutionDir=%~3"
1413
SET "TargetDir=%~4"
1514
SET "TargetFileName=%~5"
1615

17-
IF NOT ["%ConfigurationName:~0,7%"]==["Windows"] (
18-
GOTO EOF
19-
)
20-
IF ["%ConfigurationName:Release=%"]==["%ConfigurationName%"] (
21-
GOTO EOF
22-
)
23-
24-
:: It's a Windows Release configuration
2516

26-
:: CALL VsDevCmd
17+
REM ===============
18+
REM CALL VsDevCmd
19+
REM ===============
2720
ECHO;
28-
ECHO [POST-BUILD] CALL "%DevEnvDir%..\Tools\VsDevCmd.bat"
21+
ECHO [POST-BUILD] Start VS development console
2922
CALL "%DevEnvDir%..\Tools\VsDevCmd.bat"
3023

31-
:: Manifest
32-
::ECHO;
33-
::ECHO - mt.exe -nologo -manifest "%TargetDir%%TargetFileName%.manifest" -outputresource:"%TargetDir%%TargetFileName%;#1"
34-
::mt.exe -nologo -manifest "%TargetDir%%TargetFileName%.manifest" -outputresource:"%TargetDir%%TargetFileName%;#1"
35-
::DEL "%TargetDir%%TargetFileName%.manifest"
24+
CD /D "%SolutionDir%"
25+
26+
27+
REM ==============
28+
REM Dependencies
29+
REM ==============
30+
ECHO;
31+
ECHO [POST-BUILD] Processing dependencies...
32+
IF EXIST _dependencies (
33+
CD _dependencies
34+
35+
REM –––––––––––––––––––––––––––––––
36+
REM [OPTIONAL] ToastifyWebAuthAPI
37+
REM –––––––––––––––––––––––––––––––
38+
IF EXIST toastify.webauthapi (
39+
CD toastify.webauthapi
40+
SET ToastifyWebAuthAPI_Path=!CD!
41+
42+
ECHO [POST-BUILD] - Building ToastifyWebAuthAPI...
3643

37-
:: Copy installation scripts
44+
REM Build ToastifyWebAuthAPI's PreBuildTool
45+
ECHO [POST-BUILD] - PreBuildTool
46+
msbuild PreBuildTool\PreBuildTool.vcxproj /t:Clean,Build /p:Configuration=Release /p:Platform=x64 >"PreBuildTool\bin\x64\Release\build.log""
47+
IF NOT EXIST "PreBuildTool\bin\x64\Release\PreBuildTool.exe" (
48+
ECHO;
49+
ECHO ERROR: Build failed^^! See "!ToastifyWebAuthAPI_Path!\PreBuildTool\bin\x64\Release\build.log"
50+
ECHO;
51+
GOTO EOF
52+
) ELSE (
53+
DEL /Q /F "PreBuildTool\bin\x64\Release\build.log"
54+
)
55+
56+
REM Use PreBuildTool
57+
PreBuildTool\bin\x64\Release\PreBuildTool.exe "!ToastifyWebAuthAPI_Path!\ToastifyWebAuthAPI" "%TargetDir%Toastify.exe"
58+
IF ERRORLEVEL 1 (
59+
ECHO;
60+
ECHO ERROR in PreBuildTool.exe!
61+
ECHO;
62+
GOTO EOF
63+
)
64+
65+
REM Build ToastifyWebAuthAPI
66+
ECHO [POST-BUILD] - ToastifyWebAuthAPI
67+
msbuild ToastifyWebAuthAPI\ToastifyWebAuthAPI.vcxproj /t:Clean,Build /p:Configuration=Release /p:Platform=x64 >"ToastifyWebAuthAPI\bin\x64\Release\build.log""
68+
IF NOT EXIST "ToastifyWebAuthAPI\bin\x64\Release\ToastifyWebAuthAPI.dll" (
69+
ECHO;
70+
ECHO ERROR: Build failed^^! See "!ToastifyWebAuthAPI_Path!\ToastifyWebAuthAPI\bin\x64\Release\build.log"
71+
ECHO;
72+
GOTO EOF
73+
) ELSE (
74+
DEL /Q /F "ToastifyWebAuthAPI\bin\x64\Release\build.log"
75+
)
76+
77+
REM Copy ToastifyWebAuthAPI.dll to TargetDir
78+
COPY /Y "ToastifyWebAuthAPI\bin\x64\Release\ToastifyWebAuthAPI.dll" "%TargetDir%ToastifyWebAuthAPI.dll"
79+
)
80+
CD "%SolutionDir%"
81+
)
82+
83+
84+
REM ================================================================
85+
REM Check if it's a Windows Release build; continue only if it is!
86+
REM ================================================================
87+
IF NOT ["%ConfigurationName:~0,7%"]==["Windows"] GOTO EOF
88+
IF ["%ConfigurationName:Release=%"]==["%ConfigurationName%"] GOTO EOF
89+
90+
91+
REM ========================================
92+
REM Copy installation scripts to TargetDir
93+
REM ========================================
3894
ECHO;
3995
ECHO [POST-BUILD] Copy install script
4096
COPY /Y "%SolutionDir%InstallationScript\Install.nsi" "%TargetDir%Install.nsi"
4197
COPY /Y "%SolutionDir%InstallationScript\*.nsh" "%TargetDir%"
4298

43-
:: Check if makensis.exe is in the PATH
99+
100+
REM =====================================
101+
REM Check if makensis.exe is available
102+
REM =====================================
44103
makensis /VERSION 1>NUL 2>&1
45104
IF ERRORLEVEL 9009 (
46105
ECHO;
47-
ECHO ERROR: Couldn't find 'makensis' in the PATH!
48-
ECHO Make sure NSIS is installed in your system and its 'Bin' directory is in the PATH environment variable.
106+
ECHO ERROR: Couldn't find "makensis"!
107+
ECHO Make sure that NSIS is installed in your system and that its "Bin" directory is in the PATH environment variable.
49108
ECHO;
50109
GOTO EOF
51110
)
52111

53112
CD "%TargetDir%"
54113

55-
:: Compile NSIS installer
114+
115+
REM ========================
116+
REM Compile NSIS installer
117+
REM ========================
56118
ECHO;
57119
ECHO [POST-BUILD] Compile NSIS installer
58120
makensis Install.nsi || GOTO EOF

Toastify/pre-build.cmd

+43-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,54 @@
22
SetLocal EnableExtensions EnableDelayedExpansion
33

44

5-
:: ----------[ PRE-BUILD ]--------------------------------
6-
:: [in]ProjectFileName [in]ProjectDir [in]DevEnvDir
5+
REM ----------[ PRE-BUILD ]--------------------------------
6+
REM [in]SolutionDir [in]DevEnvDir
77

8-
SET "ProjectFileName=%~1"
9-
SET "ProjectDir=%~2"
10-
SET "DevEnvDir=%~3"
8+
SET "SolutionDir=%~1"
9+
SET "DevEnvDir=%~2"
1110

12-
:: CALL VsDevCmd
11+
12+
REM ===============
13+
REM CALL VsDevCmd
14+
REM ===============
1315
ECHO;
1416
ECHO [PRE-BUILD] Start VS development console
1517
CALL "%DevEnvDir%..\Tools\VsDevCmd.bat"
1618

19+
CD /D "%SolutionDir%"
20+
21+
22+
REM ==============
23+
REM Dependencies
24+
REM ==============
25+
ECHO;
26+
ECHO [PRE-BUILD] Fetching dependencies...
27+
IF NOT EXIST _dependencies MKDIR _dependencies
28+
CD _dependencies
29+
30+
REM ==============================================
31+
REM [OPTIONAL] ToastifyWebAuthAPI (private repo)
32+
REM ==============================================
33+
ECHO [PRE-BUILD] - ToastifyWebAuthAPI
34+
IF NOT EXIST toastify.webauthapi (
35+
git clone git@bitbucket.org-aleab:aleab/toastify.webauthapi.git
36+
)
37+
IF EXIST toastify.webauthapi (
38+
CD toastify.webauthapi
39+
40+
REM Reset remotes
41+
git remote remove origin 2>nul
42+
git remote remove origin-aleab 2>nul
43+
git remote add origin git@bitbucket.org:aleab/toastify.webauthapi.git
44+
git remote add origin-aleab git@bitbucket.org-aleab:aleab/toastify.webauthapi.git
45+
46+
git fetch origin-aleab
47+
git reset --hard origin-aleab/master
48+
CD ..
49+
)
50+
51+
CD "%SolutionDir%"
52+
53+
1754
:EOF
1855
ECHO;

Toastify/src/App.xaml.cs

+28-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,26 @@
2626
using Newtonsoft.Json.Linq;
2727
using PowerArgs;
2828
using SpotifyAPI;
29+
using SpotifyAPI.Web.Enums;
2930
using Toastify.Core;
31+
using Toastify.Core.Auth;
3032
using Toastify.Core.Broadcaster;
3133
using Toastify.Events;
3234
using Toastify.Model;
3335
using Toastify.Services;
3436
using Toastify.View;
3537
using ToastifyAPI.Core;
38+
using ToastifyAPI.Core.Auth;
3639
using ToastifyAPI.GitHub;
40+
using ToastifyAPI.Helpers;
3741
using ToastifyAPI.Interop;
3842
using ToastifyAPI.Interop.Interfaces;
3943
using ToastifyAPI.Logic;
4044
using ToastifyAPI.Logic.Interfaces;
4145
using MouseAction = ToastifyAPI.Core.MouseAction;
4246
using Resources = Toastify.Properties.Resources;
4347
using Spotify = ToastifyAPI.Spotify;
48+
using ToastifyWebAuthAPI_Utils = ToastifyAPI.Core.Auth.ToastifyWebAuthAPI.Utils;
4449

4550
namespace Toastify
4651
{
@@ -674,20 +679,39 @@ private static void SetupContainer()
674679
{
675680
Container = new WindsorContainer();
676681

677-
// ReSharper disable once RedundantExplicitParamsArrayCreation
678-
Container.Register(new IRegistration[]
682+
List<IRegistration> registrations = new List<IRegistration>
679683
{
684+
// I/O
680685
Component.For<IKeyboard>().Instance(InputDevices.PrimaryKeyboard),
681686
Component.For<IMouse>().Instance(InputDevices.PrimaryMouse),
682687
Component.For<IInputDevices>().ImplementedBy<InputDevices>(),
683688

689+
// Toastify Actions
684690
Component.For<IToastifyActionRegistry>().ImplementedBy<ToastifyActionRegistry>(),
685691

692+
// Hotkeys
686693
Component.For<IKeyboardHotkeyVisitor>().ImplementedBy<KeyboardHotkeyVisitor>(),
687694
Component.For<IMouseHookHotkeyVisitor>().ImplementedBy<MouseHookHotkeyVisitor>(),
688695

689-
Component.For<IToastifyBroadcaster>().ImplementedBy<ToastifyBroadcaster>()
690-
});
696+
// Core
697+
Component.For<IToastifyBroadcaster>().ImplementedBy<ToastifyBroadcaster>(),
698+
Component.For<ISpotifyWebAPI>().ImplementedBy<SpotifyWebAPI>(),
699+
Component.For<ISpotifyWeb>().ImplementedBy<SpotifyWeb>()
700+
};
701+
702+
// ISpotifyWebAuth
703+
if (ToastifyWebAuthAPI_Utils.Try())
704+
{
705+
const Scope scopes = Scope.UserReadPrivate | Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadPlaybackState;
706+
registrations.Add(Component.For<ISpotifyWebAuth>().ImplementedBy<ToastifyWebAuth>().DependsOn(
707+
Dependency.OnValue(nameof(ToastifyWebAuth.Scopes).ToLowerCamelCase(), scopes),
708+
Dependency.OnValue(nameof(ToastifyWebAuth.State).ToLowerCamelCase(), ""),
709+
Dependency.OnValue(nameof(ToastifyWebAuth.ShowDialog).ToLowerCamelCase(), true)));
710+
}
711+
else
712+
registrations.Add(Component.For<ISpotifyWebAuth>().ImplementedBy<NoAuth>());
713+
714+
Container.Register(registrations.ToArray());
691715
}
692716

693717
#endregion Static setup

0 commit comments

Comments
 (0)