Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<div class="sdpi-item-label">Back Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#000000" id="backColor" oninput="setSettings()">
</div>
<div type="text" class="sdpi-item" id="dvUserTokenName">
<div class="sdpi-item-label">User Token Name</div>
<input type="text" class="sdpi-item-value sdProperty" value="user" id="userTokenName" onkeypress="javascript:if(event.keyCode == 13) setSettings();">
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Google Calendar</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/barraider/streamdeck-easypi@latest/src/sdpi.css">
<script src="https://cdn.jsdelivr.net/gh/barraider/streamdeck-easypi@latest/src/sdtools.common.js"></script>
<meta charset="utf-8" />
<title>Google Calendar</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/barraider/streamdeck-easypi@latest/src/sdpi.css">
<script src="https://cdn.jsdelivr.net/gh/barraider/streamdeck-easypi@latest/src/sdtools.common.js"></script>

<script src="PluginActionPI.js"></script>
<script src="PluginActionPI.js"></script>
</head>

<body>
<div class="sdpi-wrapper">
<div type="color" class="sdpi-item" id="dvFrontolor">
<div class="sdpi-item-label">Front Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#FFFFFF" id="frontColor" oninput="setSettings()">
</div>
<div type="color" class="sdpi-item" id="dvBackColor">
<div class="sdpi-item-label">Back Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#000000" id="backColor" oninput="setSettings()">
</div>
</div>
<div class="sdpi-wrapper">
<div type="color" class="sdpi-item" id="dvFrontolor">
<div class="sdpi-item-label">Front Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#FFFFFF" id="frontColor" oninput="setSettings()">
</div>
<div type="color" class="sdpi-item" id="dvBackColor">
<div class="sdpi-item-label">Back Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#000000" id="backColor" oninput="setSettings()">
</div>
<div type="text" class="sdpi-item" id="dvUserTokenName">
<div class="sdpi-item-label">User Token Name</div>
<input type="text" class="sdpi-item-value sdProperty" value="user" id="userTokenName" onkeypress="javascript:if(event.keyCode == 13) setSettings();">
</div>
</div>
</body>
</html>
20 changes: 7 additions & 13 deletions src/GoogleAPIs/AdSenseManagement/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Google.Apis.Adsense.v2; // https://googleapis.dev/dotnet/Google.Apis.Adsense.v2/latest/api/Google.Apis.Adsense.v2.html
using Google.Apis.Adsense.v2.Data;
using Google.Apis.Auth.OAuth2;

using DateRangeEnum = Google.Apis.Adsense.v2.AccountsResource.ReportsResource.GenerateRequest.DateRangeEnum;
using DimensionsEnum = Google.Apis.Adsense.v2.AccountsResource.ReportsResource.GenerateRequest.DimensionsEnum;
Expand All @@ -16,28 +17,21 @@ namespace StreamDock.Plugins.GoogleAPIs.AdSenseManagement
/// <summary>
/// 구글 API 서비스 대리자
/// </summary>
internal class ApiService
internal class ApiService : GoogleAuth
{
private AdsenseService service;
private int maxListPageSize = 50;
private Account adSenseAccount;
readonly AdsenseService service;
readonly int maxListPageSize = 50;
Account adSenseAccount;

/// <summary>
/// <see cref="ApiService"/> 클래스의 새 인스턴스를 초기화합니다.
/// </summary>
/// <param name="service">요청을 실행할 애드센스 서비스 개체입니다.</param>
/// <param name="maxListPageSize">검색할 최대 페이지 크기입니다.</param>
private ApiService(AdsenseService service)
internal ApiService(UserCredential userCredential, AdsenseService service)
{
this.service = service;
}
/// <summary>
/// 서비스 생성
/// </summary>
/// <returns></returns>
internal static async Task<ApiService> GetService()
{
return new ApiService(new AdsenseService(await GoogleAuth.GetServiceInitializer()));
base.userCredential = userCredential;
}
/// <summary>
/// 로그인한 사용자의 모든 계정을 가져오고 출력합니다.
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleAPIs/AdSenseManagement/ChartReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace StreamDock.Plugins.GoogleAPIs.AdSenseManagement
{
internal class ChartReport
{
PluginSettings pluginSettings;
readonly PluginSettings pluginSettings;

internal ChartReport(PluginSettings pluginSettings)
{
Expand Down
17 changes: 9 additions & 8 deletions src/GoogleAPIs/AdSenseManagement/DataBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,33 @@

using BarRaider.SdTools;

using Google.Apis.Adsense.v2;

namespace StreamDock.Plugins.GoogleAPIs.AdSenseManagement
{
/// <summary>
/// API 동작 정의 프로시저
/// </summary>
internal class DataBinder
{
PluginSettings pluginSettings { get; set; }
Item item { get; set; }

PluginSettings pluginSettings;
Item item;
GoogleAuth googleAuth;
internal DataBinder(PluginSettings pluginsettings, Item item)
{
this.pluginSettings = pluginsettings;
this.item = item;
this.googleAuth = new();
}
/// <summary>
/// 키가 눌렸을 때 동작 정의. Google API 통신.
/// </summary>
internal async Task<Item> ExecuteAsync()
{
Item _item = this.item;

try
{
// 구글 API 통신 인스턴스
ApiService apiSevice = await ApiService.GetService();
ApiService apiSevice = new ApiService(googleAuth.userCredential, new AdsenseService(await googleAuth.GetServiceInitializerAsync(pluginSettings.UserTokenName)));

string accountName = apiSevice.GetAccountName();
if (Item.AccountName.IsNullOrEmpty())
Expand Down Expand Up @@ -59,14 +60,14 @@ internal async Task<Item> ExecuteAsync()
Logger.Instance.LogMessage(TracingLevel.INFO, "보고서 저장 완료.");
#endif
// 디스플레이용 데이터 가공
_item = SetDisplayValue();
item = SetDisplayValue();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.Message);
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.StackTrace);
}
return _item;
return item;
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/GoogleAPIs/AdSenseManagement/Models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class Item

internal void Init()
{
Accounts = new List<Account>();
Payments = new List<Payment>();
Sites = new List<Site>();
ReportResults = new Dictionary<IReportKey, ReportResult> { };
ReportCharts = new Dictionary<IReportKey, Image> { };
Accounts?.Clear();
Payments?.Clear();
Sites?.Clear();
ReportResults?.Clear();
ReportCharts?.Clear();
}
}
}
9 changes: 8 additions & 1 deletion src/GoogleAPIs/AdSenseManagement/Models/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace StreamDock.Plugins.GoogleAPIs.AdSenseManagement
{
public class PluginSettings : INotifyPropertyChanged
{
//? Json 속성 이름과 CS 속성 이름이 중복되면 안 됨. 대소문자 구분.
[JsonProperty(PropertyName = "resource")]
public string PiResource { get; set; } = "Payments";

private Resources resources;
public Resources Resource {
public Resources Resource
{
get
{
var _ = PiResource.TryParse<Resources>();
Expand Down Expand Up @@ -90,6 +92,10 @@ public DimensionsEnum Dimensions
public string PiBackColor { get; set; }
public Color BackColor => GraphicsTools.ColorFromHex(PiBackColor);

[JsonProperty(PropertyName = "userTokenName")]
public string PiUserTokenName { get; set; }
public string UserTokenName => PiUserTokenName;

public ValueTypes ValueType { get; set; }

public static PluginSettings CreateDefaultSettings()
Expand All @@ -101,6 +107,7 @@ public static PluginSettings CreateDefaultSettings()
instance.PiDimensions = String.Empty;
instance.PiFrontColor = "#FFFFFF";
instance.PiBackColor = String.Empty;
instance.PiUserTokenName = "user";
instance.ValueType = ValueTypes.String;
return instance;
}
Expand Down
76 changes: 55 additions & 21 deletions src/GoogleAPIs/AdSenseManagement/PluginAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -19,7 +20,7 @@ public class PluginAction : KeypadBase
{
Item item;
PluginSettings pluginSettings;
DataBinder apiAction;
DataBinder dataBinder;

public PluginAction(ISDConnection connection, InitialPayload payload) : base(connection, payload)
{
Expand All @@ -34,8 +35,9 @@ public PluginAction(ISDConnection connection, InitialPayload payload) : base(con
Connection.OnPropertyInspectorDidDisappear += Connection_OnPropertyInspectorDidDisappear;
Connection.OnSendToPlugin += Connection_OnSendToPlugin;
Connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;
pluginSettings.PropertyChanged += PropertyChanged;
}

#region Event
/// <summary>
/// 제목이 변경되거나 스트림독에 플러그인이 나타날 때 호출됩니다.titleParametersDidChange
/// 하드웨어 기준.
Expand All @@ -45,15 +47,25 @@ public PluginAction(ISDConnection connection, InitialPayload payload) : base(con
private async void Connection_OnTitleParametersDidChange(object sender, SDEventReceivedEventArgs<BarRaider.SdTools.Events.TitleParametersDidChange> e)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "OnTitleParametersDidChange Event Handled");
//Tools.AutoPopulateSettings(pluginSettings, e.Event.Payload.Settings);

if (!GoogleAuth.CredentialIsExist())
if (!GoogleAuth.CredentialIsExist(pluginSettings.UserTokenName))
{
await DisplayInitialAsync();
}
else
{
//TODO 자동 갱신 or 수동 갱신
await DisplayBusyAsync();
await UpdateApiDataAsync();
//if (!CheckExistData())
//{
// await DisplayInitialAsync();
//}
//else
//{
// await DisplayPreValueAsync();
//}
}
}

Expand Down Expand Up @@ -129,7 +141,12 @@ private void Connection_OnApplicationDidLaunch(object sender, SDEventReceivedEve
{
Logger.Instance.LogMessage(TracingLevel.INFO, "OnApplicationDidLaunch Event Handled");
}

private void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Logger.Instance.LogMessage(TracingLevel.INFO, $"{e.PropertyName} Property Changed");
}
#endregion
#region Steam Dock
/// <summary>
/// 스트림독에 플러그인이 표시되지 않으면 호출됩니다.
/// </summary>
Expand Down Expand Up @@ -175,16 +192,31 @@ public async override void ReceivedSettings(ReceivedSettingsPayload payload)
Logger.Instance.LogMessage(TracingLevel.INFO, "ReceivedSettings called");

Tools.AutoPopulateSettings(pluginSettings, payload.Settings);
await SaveSettingsAsync(); // 스트림독으로 설정 업로드

await SaveSettingsAsync();
await DisplayInitialAsync();
if (!GoogleAuth.CredentialIsExist(pluginSettings.UserTokenName))
{
item.Init();
dataBinder = null;
await DisplayInitialAsync();
}
else if (CheckExistData())
{
await DisplayBusyAsync();
await UpdateApiDataAsync();
}
else
{
await DisplayInitialAsync();
}
}

public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "ReceivedGlobalSettings called");
Tools.AutoPopulateSettings(pluginSettings, payload.Settings);
}

#endregion
#region Private Methods
/// <summary>
/// 설정 값을 스트림독으로 전달합니다.
Expand Down Expand Up @@ -217,21 +249,23 @@ private async Task DisplayInitialAsync()
{
try
{

if (!CheckExistData())
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.INFO, "기존 데이터 없음.");
#endif
item.DisplayValues.OnlyOne("Press Key...");
}
else
{
item.DisplayValues.OnlyOne("Press Key...");
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.INFO, "기존 데이터 발견.");
Logger.Instance.LogMessage(TracingLevel.INFO, "DisplayInitialAsync: 스트림독으로 이미지 전송 중...");
#endif
UpdateValues();
}
await Connection.SetImageAsync(UpdateKeyImage(item, true)); // 초기 이미지 출력
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.Message);
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.StackTrace);
}
}
private async Task DisplayPreValueAsync()
{
try
{
UpdateValues();
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.INFO, "DisplayInitialAsync: 스트림독으로 이미지 전송 중...");
#endif
Expand Down Expand Up @@ -345,7 +379,7 @@ private Bitmap UpdateKeyImage(Item item, bool initial = false)
/// <returns></returns>
private DataBinder GetApiInstance()
{
return apiAction ?? new DataBinder(pluginSettings, item);
return dataBinder ?? new DataBinder(pluginSettings, item);
}
#endregion
}
Expand Down
Loading