Stylus addon support, Fixed tray menu dpi, Fix drag and drop subs no delay option

- Fixed tray menu not scaling with DPI
- Added Stylus addon support + Handle for HandleStylusUsoInstall (Installing from uso archives)
- Fixed drag and dropped subtitles not being handled as "ExternalEmbedded" preventing delay setting
- Added zips of unpacked extensions for use in app.
This commit is contained in:
Zarg 2025-02-07 06:30:11 +01:00
parent aa03891ed4
commit 76d4355cd4
11 changed files with 76 additions and 8 deletions

View file

@ -72,6 +72,7 @@ bool g_allowZoom = false;
int g_tray_itemH = 31;
int g_tray_sepH = 8;
int g_tray_w = 200;
int g_font_height = 12;
// Splash
HWND g_hSplash = nullptr;

View file

@ -116,6 +116,7 @@ extern bool g_allowZoom;
extern int g_tray_itemH;
extern int g_tray_sepH;
extern int g_tray_w;
extern int g_font_height;
// Splash
extern HWND g_hSplash;

View file

@ -84,7 +84,6 @@ int main(int argc, char* argv[])
// Load config
LoadSettings();
LoadCustomMenuFont();
// Updater
g_updaterThread=std::thread(RunAutoUpdaterOnce);
@ -117,6 +116,11 @@ int main(int argc, char* argv[])
AppendToCrashLog(L"[BOOT]: CreateWindow failed!");
return 1;
}
// Scale Values with DPI
ScaleWithDPI();
LoadCustomMenuFont();
// Load Saved position
WINDOWPLACEMENT wp;
if (LoadWindowPlacement(wp)) {

View file

@ -48,7 +48,7 @@ void LoadCustomMenuFont()
g_hMenuFont = nullptr;
}
LOGFONTW lf = { 0 };
lf.lfHeight = -12;
lf.lfHeight = -g_font_height;
lf.lfWeight = FW_MEDIUM;
wcscpy_s(lf.lfFaceName, L"Arial Rounded MT");
lf.lfQuality = CLEARTYPE_QUALITY;

View file

@ -4,7 +4,13 @@
#include <string>
#include "../core/globals.h"
void HandlePremidLogin(const std::wstring& finalUri) {
bool HandleExtensions(const std::wstring& finalUri) {
bool handledPremid = HandlePremidLogin(finalUri);
bool handledStylus = HandleStylusUsoInstall(finalUri);
return handledPremid || handledStylus;
}
bool HandlePremidLogin(const std::wstring& finalUri) {
if (finalUri.rfind(L"https://login.premid.app", 0) == 0 && finalUri.rfind(L"https://discord.com", 0) != 0) {
std::wstring extensionId;
auto it = std::find_if(g_extensionMap.begin(), g_extensionMap.end(),
@ -16,7 +22,7 @@ void HandlePremidLogin(const std::wstring& finalUri) {
} else {
std::wcout << L"[EXTENSIONS]: Extension id not found\n";
g_webview->Navigate(g_webuiUrl.c_str());
return;
return true;
}
std::wstring codeParam;
@ -35,5 +41,28 @@ void HandlePremidLogin(const std::wstring& finalUri) {
std::wstring uri = L"chrome-extension://" + extensionId + L"/popup.html";
g_webview->Navigate(uri.c_str());
return true;
}
return false;
}
bool HandleStylusUsoInstall(const std::wstring& finalUri) {
if (finalUri.rfind(L"https://raw.githubusercontent.com/uso-archive", 0) == 0) {
std::wstring extensionId;
auto it = std::find_if(g_extensionMap.begin(), g_extensionMap.end(),
[](const std::pair<std::wstring, std::wstring>& p) -> bool {
return p.first.find(L"stylus") != std::wstring::npos;
});
if (it != g_extensionMap.end()) {
extensionId = it->second;
} else {
std::wcout << L"[EXTENSIONS]: Extension id not found\n";
g_webview->Navigate(g_webuiUrl.c_str());
return true;
}
std::wstring uri = L"chrome-extension://" + extensionId + L"/install-usercss.html?updateUrl=" + finalUri;
g_webview->Navigate(uri.c_str());
return true;
}
return false;
}

View file

@ -3,6 +3,8 @@
#include <string>
void HandlePremidLogin(const std::wstring& finalUri);
bool HandleExtensions(const std::wstring& finalUri);
bool HandlePremidLogin(const std::wstring& finalUri);
bool HandleStylusUsoInstall(const std::wstring& finalUri);
#endif //EXTENSIONS_H

View file

@ -1,7 +1,9 @@
#include "helpers.h"
#include <iostream>
#include <shellscalingapi.h>
#include <tlhelp32.h>
#include <VersionHelpers.h>
#include <winhttp.h>
#include "../core/globals.h"
@ -284,4 +286,32 @@ bool FetchAndParseWhitelist() {
}
return false;
}
void ScaleWithDPI() {
if (!g_hWnd) return;
UINT dpi = 96;
HMONITOR hMonitor = MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTOPRIMARY);
HRESULT hr = GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpi, nullptr);
if (FAILED(hr)) {
// Fall back to using g_hWnd's DPI if GetDpiForMonitor is unavailable
if (IsWindowsVersionOrGreater(10, 0, 1607))
{
dpi = GetDpiForWindow(g_hWnd);
}
else
{
HDC hdc = GetDC(g_hWnd);
dpi = GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(g_hWnd, hdc);
}
}
// Lambda to scale a value based on current DPI
auto ScaleValue = [dpi](int value) -> int {
return MulDiv(value, dpi, 96);
};
g_tray_itemH = ScaleValue(g_tray_itemH);
g_tray_sepH = ScaleValue(g_tray_sepH);
g_tray_w = ScaleValue(g_tray_w);
g_font_height = ScaleValue(g_font_height);
}

View file

@ -17,5 +17,6 @@ bool IsDuplicateProcessRunning(const std::vector<std::wstring>& targetProcesses)
bool isSubtitle(const std::wstring& filePath);
bool URLContainsAny(const std::wstring& url);
bool FetchAndParseWhitelist();
void ScaleWithDPI();
#endif // HELPERS_H

View file

@ -353,7 +353,7 @@ static void SetupWebMessageHandler()
if(g_hSplash && !g_waitStarted.exchange(true)) {
WaitAndRefreshIfNeeded();
}
HandlePremidLogin(finalUri);
HandleExtensions(finalUri);
}
return S_OK;
}).Get(),
@ -506,9 +506,9 @@ static void SetupWebMessageHandler()
{
std::wstring filePath = wuri.substr(8);
std::string utf8FilePath = WStringToUtf8(filePath);
std::string baseName = std::filesystem::path(utf8FilePath).filename().string();
if (isSubtitle(filePath)) {
std::vector<std::string> subaddArgs = {"sub-add",utf8FilePath};
std::vector<std::string> subaddArgs = {"sub-add",utf8FilePath, "select", baseName + " External", "Other Tracks"};
HandleEvent("mpv-command", subaddArgs);
return S_OK;
}

Binary file not shown.

Binary file not shown.