Skip to content

Commit

Permalink
Select font and icon sizes #24 #22
Browse files Browse the repository at this point in the history
  • Loading branch information
brondavies committed Oct 28, 2024
1 parent 1399a91 commit f2e36b8
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 105 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
# built on .NET Core.
# To learn how to migrate your existing application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: .NET Core Desktop

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:

strategy:
matrix:
configuration: [Debug, Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: src/TrayToolbar/TrayToolbar.sln
Test_Project_Path:
Wap_Project_Directory: src/TrayToolbar/
Wap_Project_Path: src/TrayToolbar/TrayToolbar.csproj

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

# Execute all unit tests in the solution
# - name: Execute unit tests
# run: dotnet test

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}

# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the pfx
run: |
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
$certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
# Create the app package by building and packaging the Windows Application Packaging project
- name: Create the app package
run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
env:
Appx_Bundle: Always
Appx_Bundle_Platforms: x86|x64
Appx_Package_Build_Mode: StoreUpload
Configuration: ${{ matrix.configuration }}

# Remove the pfx
- name: Remove the pfx
run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx

# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: MSIX Package
path: ${{ env.Wap_Project_Directory }}\AppPackages
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# TrayToolbar
Creates a menu with all your favorite shortcuts within easy reach just by putting them in a local folder.

[![CodeQL](https://github.com/brondavies/TrayToolbar/actions/workflows/codeql.yml/badge.svg?branch=master&event=push)](https://github.com/brondavies/TrayToolbar/actions/workflows/codeql.yml) [![Download](https://img.shields.io/github/v/release/brondavies/TrayToolbar?label=Version&color=%234b2)](https://github.com/brondavies/TrayToolbar/releases)
[![CodeQL](https://github.com/brondavies/TrayToolbar/actions/workflows/codeql.yml/badge.svg?branch=master&event=push)](https://github.com/brondavies/TrayToolbar/actions/workflows/codeql.yml) [![Download](https://img.shields.io/github/v/release/brondavies/TrayToolbar?label=Version&labelColor=%23222&color=%233a4)](https://github.com/brondavies/TrayToolbar/releases)

- Replaces the Windows 7-10 feature that no longer exists in Windows 11 for custom toolbars on the taskbar
- Choose the folder(s) and customize the file filter
- Launches links, files and apps from this menu which exist in the chosen folders and subfolders
- Automatically updates the menu with changes in the folder
- Choose your preference for icon and font sizes
- Includes support for English, Spanish, French, German, Portuguese, Italian, Japanese, Chinese, Russian, and Korean

<p style="background:#f9f9f9">💡 Can also be used in Windows 8 and 10!</p>
Expand Down
5 changes: 3 additions & 2 deletions src/TrayToolbar/ConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Win32;
using System.Net.Http.Json;
using System.Text.Json;
using TrayToolbar.Extensions;
using R = TrayToolbar.Resources.Resources;

namespace TrayToolbar
Expand Down Expand Up @@ -37,9 +38,9 @@ internal static void SetStartupKey(bool value)
{
key.SetValue(STARTUP_VALUE, ApplicationExe, RegistryValueKind.String);
}
else
else if (key.GetValueNames().Contains(STARTUP_VALUE))
{
if (key.GetValueNames().Contains(STARTUP_VALUE))
if ($"{key.GetValue(STARTUP_VALUE)}".Is(ApplicationExe))
{
key.DeleteValue(STARTUP_VALUE);
}
Expand Down
10 changes: 2 additions & 8 deletions src/TrayToolbar/Extensions/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ public static Icon GetIcon(this string path)
return ShellIcons.FetchIcon(path, false);
}

public static Bitmap GetImage(this string file)
public static Bitmap GetImage(this string file, bool large = false)
{
Icon? icon = null;
try
{
icon = Icon.ExtractAssociatedIcon(file);
}
catch { }
return (icon ?? SystemIcons.Application).ToBitmap();
return ShellIcons.FetchIcon(file, large).ToBitmap();
}

public static bool HasValue([NotNullWhen(true)] this string? value)
Expand Down
27 changes: 17 additions & 10 deletions src/TrayToolbar/Extensions/ShellIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ public static Icon FetchIcon(string path, bool large = false)
return icon;
}

static uint SizeOfSHGetFileInfo = (uint)Marshal.SizeOf(new SHFILEINFO());
private static Icon ExtractFromPath(string path, bool large = false)
{
SHFILEINFO shinfo = new SHFILEINFO();
SHGetFileInfo(
var shinfo = new SHFILEINFO();
var himl = SHGetFileInfo(
path,
0, ref shinfo, (uint)Marshal.SizeOf(shinfo),
SHGFI_ICON | (large ? SHGFI_LARGEICON : SHGFI_SMALLICON));
var icon = Icon.FromHandle(shinfo.hIcon);
//DestroyIcon(shinfo.hIcon); //makes icon invisible?
return icon;
0, ref shinfo, SizeOfSHGetFileInfo,
SHGFI_SYSICONINDEX | (large ? SHGFI_LARGEICON : SHGFI_SMALLICON));

Icon? icon = null;
var iconHandle = ImageList_GetIcon(himl, shinfo.iIcon, ILD_NORMAL);
if (iconHandle != 0)
{
icon = Icon.FromHandle(iconHandle);
}
return icon ?? SystemIcons.Application;
}

/// <summary>
Expand All @@ -40,11 +46,12 @@ private struct SHFILEINFO
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);

[DllImport("user32.dll")]
private static extern bool DestroyIcon(IntPtr handle);
[DllImport("Comctl32.dll")]
private static extern IntPtr ImageList_GetIcon(IntPtr himl, int i, int flags);

private const uint SHGFI_ICON = 0x100;
private const int ILD_NORMAL = 0x00000000;
private const uint SHGFI_LARGEICON = 0x0;
private const uint SHGFI_SMALLICON = 0x000000001;
private const uint SHGFI_SYSICONINDEX = 0x4000;
}
}
4 changes: 4 additions & 0 deletions src/TrayToolbar/Models/TrayToolbarConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public string[]? IgnoreFileTypes

public int Theme { get; set; } = 0;

public float FontSize { get; set; } = 9;

public bool LargeIcons { get; set; }

[Obsolete("Folder is obsolete", true)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Folder
Expand Down
36 changes: 36 additions & 0 deletions src/TrayToolbar/Resources/Resources.Designer.cs

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

12 changes: 12 additions & 0 deletions src/TrayToolbar/Resources/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@
<data name="Exclude folders" xml:space="preserve">
<value>Ordner ausschließen</value>
</data>
<data name="Menu Font Size" xml:space="preserve">
<value>Menü Schriftgröße</value>
</data>
<data name="Icon Size" xml:space="preserve">
<value>Symbolgröße</value>
</data>
<data name="Small" xml:space="preserve">
<value>Klein</value>
</data>
<data name="Large" xml:space="preserve">
<value>Groß</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/TrayToolbar/Resources/Resources.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@
<data name="Exclude folders" xml:space="preserve">
<value>Excluir carpetas</value>
</data>
<data name="Menu Font Size" xml:space="preserve">
<value>Tamaño de fuente del menú</value>
</data>
<data name="Icon Size" xml:space="preserve">
<value>Tamaño del icono</value>
</data>
<data name="Small" xml:space="preserve">
<value>Pequeño</value>
</data>
<data name="Large" xml:space="preserve">
<value>Grande</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/TrayToolbar/Resources/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@
<data name="Exclude folders" xml:space="preserve">
<value>Exclure des dossiers</value>
</data>
<data name="Menu Font Size" xml:space="preserve">
<value>Taille de la police du menu</value>
</data>
<data name="Icon Size" xml:space="preserve">
<value>Taille de l'icône</value>
</data>
<data name="Small" xml:space="preserve">
<value>Petit</value>
</data>
<data name="Large" xml:space="preserve">
<value>Grand</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/TrayToolbar/Resources/Resources.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@
<data name="Exclude folders" xml:space="preserve">
<value>Escludi cartelle</value>
</data>
<data name="Menu Font Size" xml:space="preserve">
<value>Dimensione carattere del menu</value>
</data>
<data name="Icon Size" xml:space="preserve">
<value>Dimensione dell'icona</value>
</data>
<data name="Small" xml:space="preserve">
<value>Piccolo</value>
</data>
<data name="Large" xml:space="preserve">
<value>Grande</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/TrayToolbar/Resources/Resources.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@
<data name="Exclude folders" xml:space="preserve">
<value>フォルダを除外する</value>
</data>
<data name="Menu Font Size" xml:space="preserve">
<value>メニューのフォントサイズ</value>
</data>
<data name="Icon Size" xml:space="preserve">
<value>アイコンサイズ</value>
</data>
<data name="Small" xml:space="preserve">
<value>小さい</value>
</data>
<data name="Large" xml:space="preserve">
<value>大きい</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/TrayToolbar/Resources/Resources.ko.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@
<data name="Exclude folders" xml:space="preserve">
<value>폴더 제외</value>
</data>
<data name="Menu Font Size" xml:space="preserve">
<value>메뉴 글꼴 크기</value>
</data>
<data name="Icon Size" xml:space="preserve">
<value>아이콘 크기</value>
</data>
<data name="Small" xml:space="preserve">
<value>작은</value>
</data>
<data name="Large" xml:space="preserve">
<value>크기가 큰</value>
</data>
</root>
Loading

0 comments on commit f2e36b8

Please sign in to comment.