Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Jun 15, 2023
2 parents 2caaf9d + 720fb4b commit c2c366c
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 119 deletions.
14 changes: 7 additions & 7 deletions OpenTween/Api/TwitterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ public sealed class TwitterApi : IDisposable

internal IApiConnection? ApiConnection;

private TwitterAppToken appToken = TwitterAppToken.GetDefault();
public TwitterAppToken AppToken { get; private set; } = TwitterAppToken.GetDefault();

public TwitterApi()
{
}

public TwitterApi(ApiKey consumerKey, ApiKey consumerSecret)
{
this.appToken = new()
this.AppToken = new()
{
AuthType = APIAuthType.OAuth1,
OAuth1ConsumerKey = consumerKey,
OAuth1ConsumerSecret = consumerSecret,
OAuth1CustomConsumerKey = consumerKey,
OAuth1CustomConsumerSecret = consumerSecret,
};
}

public void Initialize(string accessToken, string accessSecret, long userId, string screenName)
=> this.Initialize(this.appToken, accessToken, accessSecret, userId, screenName);
=> this.Initialize(this.AppToken, accessToken, accessSecret, userId, screenName);

public void Initialize(TwitterAppToken appToken, string accessToken, string accessSecret, long userId, string screenName)
{
this.appToken = appToken;
this.AppToken = appToken;

var newInstance = new TwitterApiConnection(this.appToken, accessToken, accessSecret);
var newInstance = new TwitterApiConnection(this.AppToken, accessToken, accessSecret);
var oldInstance = Interlocked.Exchange(ref this.ApiConnection, newInstance);
oldInstance?.Dispose();

Expand Down
4 changes: 2 additions & 2 deletions OpenTween/AppendSettingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ public void ApplyNetworkSettings()
return new UserAccount
{
TwitterAuthType = appToken.AuthType,
TwitterOAuth1ConsumerKey = appToken.OAuth1ConsumerKey.Value,
TwitterOAuth1ConsumerSecret = appToken.OAuth1ConsumerSecret.Value,
TwitterOAuth1ConsumerKey = appToken.OAuth1CustomConsumerKey?.Value ?? "",
TwitterOAuth1ConsumerSecret = appToken.OAuth1CustomConsumerSecret?.Value ?? "",
Username = accessTokenResponse["screen_name"],
UserId = long.Parse(accessTokenResponse["user_id"]),
Token = accessTokenResponse["oauth_token"],
Expand Down
35 changes: 31 additions & 4 deletions OpenTween/ApplicationPreconditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace OpenTween
/// </summary>
public sealed class ApplicationPreconditions
{
// Windows の最小要件
private static readonly string OSMinimumVersionName = "Windows 10";
private static readonly Version OSMinimumVersion = new(10, 0, 0, 0);

// .NET Framework ランタイムの最小要件
// 参照: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
private const string RuntimeMinimumVersionName = ".NET Framework 4.8";
Expand All @@ -48,11 +52,11 @@ public static bool CheckAll()
{
var conditions = new ApplicationPreconditions();

if (!conditions.CheckApiKey())
if (!conditions.CheckOSVersion())
{
var message = Properties.Resources.WarnIfApiKeyError_Message;
ShowMessageBox(message, MessageBoxIcon.Error);
return false;
// 警告のみ表示し、起動は中断しない
var message = string.Format(Properties.Resources.CheckOSVersion_Error, OSMinimumVersionName);
ShowMessageBox(message, MessageBoxIcon.Warning);
}

if (!conditions.CheckRuntimeVersion())
Expand All @@ -62,6 +66,13 @@ public static bool CheckAll()
return false;
}

if (!conditions.CheckApiKey())
{
var message = Properties.Resources.WarnIfApiKeyError_Message;
ShowMessageBox(message, MessageBoxIcon.Error);
return false;
}

if (!conditions.CheckRunAsNormalUser())
{
var message = string.Format(Properties.Resources.WarnIfRunAsAdministrator_Message, ApplicationSettings.ApplicationName);
Expand All @@ -80,6 +91,22 @@ private static void ShowMessageBox(string message, MessageBoxIcon icon)
public bool CheckApiKey()
=> this.CanDecryptApiKey(ApplicationSettings.TwitterConsumerKey);

/// <summary>
/// 起動中の OS のバージョンが最小要件を満たしているか確認する
/// </summary>
public bool CheckOSVersion()
{
var os = Environment.OSVersion;

if (os.Platform != PlatformID.Win32NT)
return false;

if (os.Version < ApplicationPreconditions.OSMinimumVersion)
return false;

return true;
}

/// <summary>
/// 動作中の .NET Framework のバージョンが適切か確認する
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions OpenTween/AuthTypeSelectDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions OpenTween/AuthTypeSelectDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ public AuthTypeSelectDialog()
private void OKButton_Click(object sender, EventArgs e)
{
TwitterAppToken result;
if (this.AuthByOAuth1RadioButton.Checked)
if (this.AuthByOAuth1BuiltinKeyRadioButton.Checked)
{
result = TwitterAppToken.GetDefault();
}
else if (this.AuthByOAuth1RadioButton.Checked)
{
var consumerKey = this.OAuth1ConsumerKeyTextBox.Text;
var consumerSecret = this.OAuth1ConsumerSecretTextBox.Text;
result = new()
{
AuthType = APIAuthType.OAuth1,
OAuth1ConsumerKey = ApiKey.Create(this.OAuth1ConsumerKeyTextBox.Text),
OAuth1ConsumerSecret = ApiKey.Create(this.OAuth1ConsumerSecretTextBox.Text),
OAuth1CustomConsumerKey = MyCommon.IsNullOrEmpty(consumerKey) ? null : ApiKey.Create(consumerKey),
OAuth1CustomConsumerSecret = MyCommon.IsNullOrEmpty(consumerSecret) ? null : ApiKey.Create(consumerSecret),
};
}
else if (this.UseTwitterComCookieRadioButton.Checked)
Expand Down
2 changes: 2 additions & 0 deletions OpenTween/AuthTypeSelectDialog.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

<data name="AuthByOAuth1BuiltinKeyRadioButton.Size" type="System.Drawing.Size, System.Drawing"><value>284, 16</value></data>
<data name="AuthByOAuth1BuiltinKeyRadioButton.Text"><value>Use OAuth 1.0a (with OpenTween built-in API key)</value></data>
<data name="AuthByOAuth1RadioButton.Size" type="System.Drawing.Size, System.Drawing"><value>103, 16</value></data>
<data name="AuthByOAuth1RadioButton.Text"><value>Use OAuth 1.0a</value></data>
<data name="AuthByOAuth2RadioButton.Size" type="System.Drawing.Size, System.Drawing"><value>215, 16</value></data>
Expand Down
Loading

0 comments on commit c2c366c

Please sign in to comment.