mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-30 05:28:15 +03:00
API improvements
- updated empathize to 1.4.0; due to it was removed `Launcher.isPackageAvailable()` method which now included in empathize as `Package.exists()` - `Game.isTelemetryDisabled()` now rejects an Error object when `iputils` package (`ping` command) is not installed - due to the change above was slightly rewritten `Launch.ts` script
This commit is contained in:
parent
1808cdf39f
commit
fcc67af03a
8 changed files with 251 additions and 280 deletions
|
@ -11,7 +11,7 @@
|
|||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@empathize/framework": "^1.3.5",
|
||||
"@empathize/framework": "^1.4.0",
|
||||
"js-md5": "^0.7.3",
|
||||
"semver": "^7.3.5",
|
||||
"svelte-i18n": "^3.3.13",
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<script lang="ts">
|
||||
import { _, locale } from 'svelte-i18n';
|
||||
|
||||
import { Package } from '../empathize';
|
||||
|
||||
import type { Shader } from '../ts/types/Shaders';
|
||||
|
||||
import Shaders from '../ts/launcher/Shaders';
|
||||
import Launcher from '../ts/Launcher';
|
||||
|
||||
import SelectionBox from './SelectionBox.svelte';
|
||||
|
||||
|
@ -23,7 +24,7 @@
|
|||
shadersOptions['custom'] = 'settings.shaders.items.shaders.items.custom';
|
||||
});
|
||||
|
||||
Launcher.isPackageAvailable('reshade').then((available) => reshadeInstalled = available);
|
||||
Package.exists('reshade').then((available) => reshadeInstalled = available);
|
||||
</script>
|
||||
|
||||
<div>
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
Windows,
|
||||
|
||||
// OS API
|
||||
Process, Tray, IPC, Notification, Archive,
|
||||
Process, Tray, IPC, Notification, Archive, Package,
|
||||
|
||||
// Network API
|
||||
fetch, Domain, Downloader,
|
||||
|
@ -42,7 +42,7 @@ export {
|
|||
Windows,
|
||||
|
||||
// OS API
|
||||
Process, Tray, IPC, Notification, Archive,
|
||||
Process, Tray, IPC, Notification, Archive, Package,
|
||||
|
||||
// Network API
|
||||
fetch, Domain, Downloader,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { onMount } from 'svelte';
|
||||
import { _, locale, locales } from 'svelte-i18n';
|
||||
|
||||
import { Windows, Configs, Debug, IPC, Process, path } from './empathize';
|
||||
import { Windows, Configs, Debug, IPC, Process, path, Package } from './empathize';
|
||||
|
||||
import constants from './ts/Constants';
|
||||
import Launcher from './ts/Launcher';
|
||||
|
@ -86,7 +86,7 @@
|
|||
tooltip: 'settings.enhancements.items.gamemode.tooltip.enabled'
|
||||
};
|
||||
|
||||
Launcher.isPackageAvailable('gamemoderun').then((available) => {
|
||||
Package.exists('gamemoderun').then((available) => {
|
||||
gamemode.disabled = !available;
|
||||
|
||||
if (gamemode.disabled)
|
||||
|
|
|
@ -7,7 +7,7 @@ import type {
|
|||
|
||||
import type { Stream as DownloadingStream } from '@empathize/framework/dist/network/Downloader';
|
||||
|
||||
import { fetch, Domain, promisify, Downloader, Cache, Debug } from '../empathize';
|
||||
import { fetch, Domain, promisify, Downloader, Cache, Debug, Package } from '../empathize';
|
||||
import { DebugThread } from '@empathize/framework/dist/meta/Debug';
|
||||
|
||||
import constants from './Constants';
|
||||
|
@ -246,12 +246,25 @@ export default class Game
|
|||
|
||||
/**
|
||||
* Check if the telemetry servers are disabled
|
||||
*
|
||||
* @returns throws Error object when iputils package (ping command) is not available
|
||||
*/
|
||||
public static isTelemetryDisabled(): Promise<boolean>
|
||||
{
|
||||
const debugThread = new DebugThread('Game.isTelemetryDisabled', 'Checking if the telemetry servers are disabled');
|
||||
|
||||
return new Promise(async (resolve) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// If ping command is not available - throw an error
|
||||
if (!await Package.exists('ping'))
|
||||
{
|
||||
debugThread.log('iputils package is not installed');
|
||||
|
||||
reject(new Error('iputils package is not installed'));
|
||||
}
|
||||
|
||||
// Otherwise - check if telemetry is disabled
|
||||
else
|
||||
{
|
||||
const pipeline = promisify({
|
||||
callbacks: await constants.uri.telemetry.map((domain) => {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -271,6 +284,7 @@ export default class Game
|
|||
|
||||
resolve(disabled === false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,45 +154,4 @@ export default class Launcher
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if some binary file or package downloaded
|
||||
*/
|
||||
public static isPackageAvailable(name: string): Promise<boolean>
|
||||
{
|
||||
return new Promise(async (resolve) => {
|
||||
let available = false;
|
||||
|
||||
let paths: string[] = (await Neutralino.os.getEnv('PATH')).split(':');
|
||||
|
||||
// Add "/usr/share" if it is not included
|
||||
// because we use these paths to check if some library exists in system
|
||||
if (!paths.includes('/usr/share'))
|
||||
paths.push('/usr/share');
|
||||
|
||||
// Sort them by length because obviously
|
||||
// "/usr/bin" more important than some randomly generated
|
||||
// yaml or npm folder for its globally downloaded packages
|
||||
paths = paths.sort((a, b) => a.length - b.length);
|
||||
|
||||
for (const path of paths)
|
||||
{
|
||||
// Becasue await Neutralino.filesystem.getStats will throw an erro
|
||||
// if the specified path doesn't exist
|
||||
try
|
||||
{
|
||||
if (await Neutralino.filesystem.getStats(`${path}/${name}`))
|
||||
{
|
||||
available = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
catch {}
|
||||
}
|
||||
|
||||
resolve(available);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Notification } from '../../../empathize';
|
||||
import { Notification, Package } from '../../../empathize';
|
||||
|
||||
import type Launcher from '../../Launcher';
|
||||
|
||||
import Launcher from '../../Launcher';
|
||||
import Patch from '../../Patch';
|
||||
import constants from '../../Constants';
|
||||
import Locales from '../Locales';
|
||||
|
@ -8,7 +9,7 @@ import Locales from '../Locales';
|
|||
export default (launcher: Launcher): Promise<void> => {
|
||||
return new Promise(async (resolve) => {
|
||||
// Show an error notification if xdelta3 package is not installed
|
||||
if (!await Launcher.isPackageAvailable('xdelta3'))
|
||||
if (!await Package.exists('xdelta3'))
|
||||
{
|
||||
Notification.show({
|
||||
...(Locales.translate('notifications.xdelta3_package_required') as { title: string, body: string }),
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { Process, Windows, Configs, Notification, path } from '../../../empathize';
|
||||
import { Process, Windows, Configs, Notification, path, Package } from '../../../empathize';
|
||||
import { DebugThread } from '@empathize/framework/dist/meta/Debug';
|
||||
|
||||
import Launcher from '../../Launcher';
|
||||
import type Launcher from '../../Launcher';
|
||||
|
||||
import constants from '../../Constants';
|
||||
import Runners from '../../core/Runners';
|
||||
import Game from '../../Game';
|
||||
|
@ -13,24 +14,11 @@ export default (launcher: Launcher): Promise<void> => {
|
|||
return new Promise(async (resolve) => {
|
||||
const debugThread = new DebugThread('State/Launch', 'Starting the game');
|
||||
|
||||
// Show an error notification if ping is not available
|
||||
if (!await Launcher.isPackageAvailable('ping'))
|
||||
{
|
||||
Notification.show({
|
||||
...(Locales.translate('notifications.iputils_package_required') as { title: string, body: string }),
|
||||
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
|
||||
importance: 'critical'
|
||||
});
|
||||
|
||||
debugThread.log('iputils package is not installed!');
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
const telemetry = await Game.isTelemetryDisabled();
|
||||
|
||||
// Check if telemetry servers are disabled
|
||||
Game.isTelemetryDisabled()
|
||||
.then(async (telemetryDisabled) => {
|
||||
// If telemetry servers are not disabled
|
||||
if (!telemetry)
|
||||
if (!telemetryDisabled)
|
||||
{
|
||||
Notification.show({
|
||||
...(Locales.translate('notifications.telemetry_not_disabled') as { title: string, body: string }),
|
||||
|
@ -116,7 +104,7 @@ export default (launcher: Launcher): Promise<void> => {
|
|||
*/
|
||||
const shaders = await Configs.get('shaders');
|
||||
|
||||
if (shaders !== 'none' && await Launcher.isPackageAvailable('reshade'))
|
||||
if (shaders !== 'none' && await Package.exists('reshade'))
|
||||
{
|
||||
const launcherShadersFile = `${await constants.paths.launcherDir}/vkBasalt.conf`;
|
||||
|
||||
|
@ -155,7 +143,7 @@ export default (launcher: Launcher): Promise<void> => {
|
|||
/**
|
||||
* Gamemode integration
|
||||
*/
|
||||
if (await Configs.get('gamemode') && await Launcher.isPackageAvailable('gamemoderun'))
|
||||
if (await Configs.get('gamemode') && await Package.exists('gamemoderun'))
|
||||
command = `gamemoderun ${command}`;
|
||||
|
||||
/**
|
||||
|
@ -248,5 +236,13 @@ export default (launcher: Launcher): Promise<void> => {
|
|||
setTimeout(waiter, 5000);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Notification.show({
|
||||
...(Locales.translate('notifications.iputils_package_required') as { title: string, body: string }),
|
||||
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
|
||||
importance: 'critical'
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue