Skip to content

Commit

Permalink
finishing up new version
Browse files Browse the repository at this point in the history
  • Loading branch information
enginkirmaci committed Dec 16, 2023
1 parent 7a4ae01 commit 44329c0
Show file tree
Hide file tree
Showing 28 changed files with 722 additions and 562 deletions.
2 changes: 0 additions & 2 deletions SnapIt.App/SnapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public SnapManager(

public async Task InitializeAsync()
{
Dev.Log();

if (IsInitialized)
{
return;
Expand Down
6 changes: 3 additions & 3 deletions SnapIt.Common/Dev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public static class Dev
public static bool IsInDesignMode { get => DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()); }

#if DEBUG
public const bool IsActive = false;
public const bool IsActive = true;
public const bool ShowSnapWindowOnStartup = true;
public const bool IsTopmostDisabled = true;
public const bool SkipLicense = true;
public const bool SkipLicense = false;
public const bool TestTrialEnded = false;
public const bool TestInTrial = false;
public const bool SkipRunAsAdmin = true;
#else
public const bool IsActive = false;
public const bool ShowSnapWindowOnStartup = false;
public const bool IsTopmostDisabled = false;
public const bool SkipLicense = true; //todo make it false with first release
public const bool SkipLicense = false; //todo make it false with first release
public const bool TestTrialEnded = false;

public const bool TestInTrial = false;
Expand Down
5 changes: 2 additions & 3 deletions SnapIt.Common/Entities/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ public class Constants
public static string AppName => Application.ResourceAssembly.GetName().Name;
public static string AppTitle => $"{AppName} - Window Manager";
public static string AppVersion => $"version {Application.ResourceAssembly.GetName().Version}";

//public const string AppUrl = "getsnapit.com";
public static readonly string RootFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppName);
public const string AppFeedbackUrl = "github.com/enginkirmaci/SnapIt/issues";

public const string AppPurchaseUrl = "getsnapit.com/checkout";
public const string AppVersionCheckUrl = "raw.githubusercontent.com/enginkirmaci/SnapIt/main/latest-version.json";
public const string AppNewVersionUrl = "github.com/enginkirmaci/SnapIt/releases/download/{0}/setup_SnapIt_{0}.exe";
public const string AppPrivacyUrl = "github.com/enginkirmaci/SnapIt/blob/main/PrivacyPolicy.md";
public const string AppRegistryKey = "SnapIt";
public const string GithubUrl = "github.com/enginkirmaci/SnapIt";
public const string MainRegion = "MainRegion";
//public const string AppUrl = "getsnapit.com";
}
7 changes: 1 addition & 6 deletions SnapIt.Services/FileOperationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ namespace SnapIt.Services;
public class FileOperationService : IFileOperationService
{
private const string LayoutFolder = "Layoutsv20";
private readonly string rootFolder;
private readonly string rootFolder = Constants.RootFolder;

public bool IsInitialized { get; private set; }

public FileOperationService()
{
rootFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), System.Windows.Forms.Application.ProductName);
}

public async Task InitializeAsync()
{
if (IsInitialized)
Expand Down
83 changes: 43 additions & 40 deletions SnapIt.Services/MouseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,59 +101,62 @@ public void Interrupt()

private void MouseMoveEvent(object sender, MouseEventArgs e)
{
var p = WpfScreenHelper.MouseHelper.MousePosition;

if (isListening && HoldingKeyResult() && IsDelayDone(p))
if (isListening)
{
if (!isWindowDetected)
{
holdKeyUsed = true;

activeWindow = winApiService.GetActiveWindow();
activeWindow.Dpi = DpiHelper.GetDpiFromPoint((int)p.X, (int)p.Y);
var p = WpfScreenHelper.MouseHelper.MousePosition;

if (activeWindow?.Title != null && windowsService.IsExcludedApplication(activeWindow.Title, false))
{
isListening = false;
}
else if (settingService.Settings.DisableForFullscreen && winApiService.IsFullscreen(activeWindow))
{
isListening = false;
}
else if (settingService.Settings.DisableForModal && !winApiService.IsAllowedWindowStyle(activeWindow))
{
isListening = false;
}
else if (settingService.Settings.DragByTitle)
if (HoldingKeyResult() && IsDelayDone(p))
{
if (!isWindowDetected)
{
var titleBarHeight = SystemInformation.CaptionHeight;
var FixedFrameBorderSize = SystemInformation.FixedFrameBorderSize.Height;
holdKeyUsed = true;

activeWindow = winApiService.GetActiveWindow();
activeWindow.Dpi = DpiHelper.GetDpiFromPoint((int)p.X, (int)p.Y);

if (activeWindow.Boundry.Top + titleBarHeight + 2 + FixedFrameBorderSize * 2 >= p.Y)
if (activeWindow?.Title != null && windowsService.IsExcludedApplication(activeWindow.Title, false))
{
isWindowDetected = true;
isListening = false;
}
else
else if (settingService.Settings.DisableForFullscreen && winApiService.IsFullscreen(activeWindow))
{
isListening = false;
}
else if (settingService.Settings.DisableForModal && !winApiService.IsAllowedWindowStyle(activeWindow))
{
isListening = false;
}
else if (settingService.Settings.DragByTitle)
{
var titleBarHeight = SystemInformation.CaptionHeight;
var FixedFrameBorderSize = SystemInformation.FixedFrameBorderSize.Height;

if (activeWindow.Boundry.Top + titleBarHeight + 2 + FixedFrameBorderSize * 2 >= p.Y)
{
isWindowDetected = true;
}
else
{
isListening = false;
}
}
else
{
isWindowDetected = true;
}
}
else
else if (ShowWindowsIfNecessary != null && ShowWindowsIfNecessary.Invoke())
{
isWindowDetected = true;
//todo maybe ShowWindowsIfNecessary?.Invoke() can work before SelectElementWithPoint
}
}
else if (ShowWindowsIfNecessary != null && ShowWindowsIfNecessary.Invoke())
{
//todo maybe ShowWindowsIfNecessary?.Invoke() can work before SelectElementWithPoint
}
else
{
snapAreaInfo = SelectElementWithPoint?.Invoke((int)p.X, (int)p.Y);

if (snapAreaInfo?.Screen != null)
else
{
settingService.LatestActiveScreen = snapAreaInfo.Screen;
snapAreaInfo = SelectElementWithPoint?.Invoke((int)p.X, (int)p.Y);

if (snapAreaInfo?.Screen != null)
{
settingService.LatestActiveScreen = snapAreaInfo.Screen;
}
}
}
}
Expand Down
29 changes: 17 additions & 12 deletions SnapIt.Services/StoreLicenseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,32 @@ public async Task<LicenseStatus> CheckStatusAsync()
if (Dev.SkipLicense)
return LicenseStatus.InTrial;

var license = await storeContext.GetAppLicenseAsync();
if (license.IsActive)
if (storeContext != null)
{
if (license.IsTrial)
var license = await storeContext.GetAppLicenseAsync();
if (license.IsActive)
{
licenseStatus = LicenseStatus.InTrial;
if (license.IsTrial)
{
licenseStatus = LicenseStatus.InTrial;

int remainingTrialTime = (license.ExpirationDate - DateTime.Now).Days;
int remainingTrialTime = (license.ExpirationDate - DateTime.Now).Days;

if (remainingTrialTime <= 0)
if (remainingTrialTime <= 0)
{
licenseStatus = LicenseStatus.TrialEnded;
}
}
else
{
licenseStatus = LicenseStatus.TrialEnded;
licenseStatus = LicenseStatus.Licensed;
}
}
else
{
licenseStatus = LicenseStatus.Licensed;
}

return licenseStatus;
}

return licenseStatus;
return LicenseStatus.Licensed;
}

[ComImport]
Expand Down
7 changes: 5 additions & 2 deletions SnapIt/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.IO;
using System.Windows;
using DryIoc;
using Prism.DryIoc;
using Prism.Ioc;
Expand All @@ -8,6 +9,7 @@
using SnapIt.Common;
using SnapIt.Common.Applications;
using SnapIt.Common.Contracts;
using SnapIt.Common.Entities;
using SnapIt.Common.Extensions;
using SnapIt.Services;
using SnapIt.Services.Contracts;
Expand Down Expand Up @@ -72,7 +74,8 @@ private void OnStartup(object sender, StartupEventArgs e)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day)
.WriteTo.File(Path.Combine(Constants.RootFolder, "logs", "log.txt"),
rollingInterval: RollingInterval.Day)
.CreateLogger();
RegisterGlobalExceptionHandling(Log.Logger);

Expand Down
2 changes: 1 addition & 1 deletion SnapIt/SnapIt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
<Product>SnapIt</Product>
<Description>SnapIt is a window manager for Windows. Organizes your windows to improve your productivity when working with wide and multiple screens.</Description>
<Version>4.3.11.0</Version>
<Version>5.0.0.0</Version>
<Copyright>Copyright © 2019</Copyright>
<Company>Engin KIRMACI</Company>
<FileVersion>
Expand Down
10 changes: 5 additions & 5 deletions SnapIt/ViewModels/Dialogs/ExcludeApplicationDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Prism.Mvvm;
using System.Windows;
using Prism.Mvvm;
using SnapIt.Common.Entities;
using SnapIt.Common.Mvvm;
using SnapIt.Services.Contracts;

namespace SnapIt.ViewModels.Dialogs;

public class ExcludeApplicationDialogViewModel : BindableBase
public class ExcludeApplicationDialogViewModel : ViewModelBase
{
private readonly IWinApiService winApiService;

Expand All @@ -20,11 +22,9 @@ public ExcludeApplicationDialogViewModel(
IWinApiService winApiService)
{
this.winApiService = winApiService;

_ = InitializeAsync();
}

public async Task InitializeAsync()
public override async Task InitializeAsync(RoutedEventArgs args)
{
selectedExcludedApplication = new();

Expand Down
11 changes: 11 additions & 0 deletions SnapIt/ViewModels/Dialogs/NewVersionDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Windows;
using SnapIt.Common.Mvvm;

namespace SnapIt.ViewModels.Dialogs;

public class NewVersionDialogViewModel : ViewModelBase
{
public override async Task InitializeAsync(RoutedEventArgs args)
{
}
}
12 changes: 4 additions & 8 deletions SnapIt/ViewModels/Dialogs/RenameDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using Prism.Mvvm;
using System.Windows;
using SnapIt.Common.Mvvm;

namespace SnapIt.ViewModels.Dialogs;

public class RenameDialogViewModel : BindableBase
public class RenameDialogViewModel : ViewModelBase
{
private string layoutName;

public string LayoutName { get => layoutName; set => SetProperty(ref layoutName, value); }

public RenameDialogViewModel()
{
_ = InitializeAsync();
}

public async Task InitializeAsync()
public override async Task InitializeAsync(RoutedEventArgs args)
{
}
}
10 changes: 5 additions & 5 deletions SnapIt/ViewModels/Dialogs/RunningApplicationsDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Prism.Mvvm;
using System.Windows;
using Prism.Mvvm;
using SnapIt.Common.Mvvm;
using SnapIt.Services.Contracts;

namespace SnapIt.ViewModels.Dialogs;

public class RunningApplicationsDialogViewModel : BindableBase
public class RunningApplicationsDialogViewModel : ViewModelBase
{
private readonly IWinApiService winApiService;
private string selectedApplication;
Expand All @@ -15,11 +17,9 @@ public class RunningApplicationsDialogViewModel : BindableBase
public RunningApplicationsDialogViewModel(IWinApiService winApiService)
{
this.winApiService = winApiService;

_ = InitializeAsync();
}

public async Task InitializeAsync()
public override async Task InitializeAsync(RoutedEventArgs args)
{
RunningApplications = new ObservableCollection<string>(winApiService.GetOpenWindowsNames());
}
Expand Down
22 changes: 22 additions & 0 deletions SnapIt/ViewModels/Dialogs/StoreWebsiteDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Windows;
using SnapIt.Common.Mvvm;

namespace SnapIt.ViewModels.Dialogs;

public class StoreWebsiteDialogViewModel : ViewModelBase
{
private string licenseMessageCloseButtonText;
private bool isTrialEnded;

public bool IsTrialEnded { get => isTrialEnded; set => SetProperty(ref isTrialEnded, value); }
public string LicenseMessageCloseButtonText { get => licenseMessageCloseButtonText; set => SetProperty(ref licenseMessageCloseButtonText, value); }

public StoreWebsiteDialogViewModel()
{
}

public override async Task InitializeAsync(RoutedEventArgs args)
{
LicenseMessageCloseButtonText = IsTrialEnded ? "Exit Application" : "Close";
}
}
26 changes: 26 additions & 0 deletions SnapIt/ViewModels/Dialogs/TrialMessageDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Windows;
using SnapIt.Common.Entities;
using SnapIt.Common.Mvvm;

namespace SnapIt.ViewModels.Dialogs;

public class TrialMessageDialogViewModel : ViewModelBase
{
private string licenseMessageCloseButtonText;
private string titleText;
private bool isTrialEnded;

public string LicenseMessageCloseButtonText { get => licenseMessageCloseButtonText; set => SetProperty(ref licenseMessageCloseButtonText, value); }
public string TitleText { get => titleText; set => SetProperty(ref titleText, value); }
public bool IsTrialEnded { get => isTrialEnded; set => SetProperty(ref isTrialEnded, value); }

public TrialMessageDialogViewModel()
{
}

public override async Task InitializeAsync(RoutedEventArgs args)
{
TitleText = $"{Constants.AppName} Trial";
LicenseMessageCloseButtonText = IsTrialEnded ? "Exit Application" : "Close";
}
}
Loading

0 comments on commit 44329c0

Please sign in to comment.