generated from maximegris/angular-electron
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
390 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as fs from 'fs-extra'; | ||
import * as recursiveReadDir from 'recursive-readdir'; | ||
import { SendToUI } from '../types'; | ||
import { baseUrl } from './constants'; | ||
|
||
const depDir = `${baseUrl}/resources/dependencies`; | ||
|
||
export async function addDependency(sendToUI: SendToUI, data: any) { | ||
sendToUI('notify', { | ||
type: 'info', | ||
text: `Attempting to download mod dependency ${data}`, | ||
}); | ||
|
||
try { | ||
const res = await fetch(data); | ||
const resJson = await res.json(); | ||
|
||
if ( | ||
!resJson.meta || | ||
!resJson.meta.name || | ||
!resJson.meta.author || | ||
!resJson.meta.savedAt || | ||
!resJson.meta.version | ||
) { | ||
sendToUI('notify', { | ||
type: 'error', | ||
text: 'Malformed mod!', | ||
}); | ||
return; | ||
} | ||
|
||
resJson.meta._url = data; | ||
|
||
fs.ensureDirSync(depDir); | ||
fs.writeJSONSync(`${depDir}/${resJson.meta.name}.rairmod`, resJson); | ||
|
||
getAndSendDependencies(sendToUI); | ||
|
||
sendToUI('notify', { | ||
type: 'success', | ||
text: `Got dependency mod "${resJson.meta.name}"!`, | ||
}); | ||
|
||
sendToUI('adddependency', { name: resJson.meta.name, url: data }); | ||
} catch { | ||
sendToUI('notify', { | ||
type: 'error', | ||
text: 'Malformed mod URL!', | ||
}); | ||
} | ||
} | ||
|
||
export async function getAndSendDependencies(sendToUI: SendToUI) { | ||
const deps = await getDependencies(); | ||
sendToUI('dependencies', deps); | ||
} | ||
|
||
export async function getDependencies() { | ||
fs.ensureDirSync(depDir); | ||
|
||
const allDeps = await recursiveReadDir(depDir); | ||
const allDepData = allDeps | ||
.filter((f) => f.includes('rairmod')) | ||
.map((f) => fs.readJSONSync(f)); | ||
|
||
return allDepData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './constants'; | ||
export * from './dependencies'; | ||
export * from './modtest'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<div role="tablist" class="tabs tabs-boxed rounded-none"> | ||
|
||
<div class="tab flex flex-row justify-end"> | ||
<button class="btn btn-primary btn-sm mr-2" [swal]="addDependency"> | ||
<ng-icon name="heroPlus"></ng-icon> | ||
</button> | ||
<button class="btn-sm btn btn-success mr-3" (click)="exit.emit()">Done</button> | ||
</div> | ||
|
||
</div> | ||
|
||
<div class="flex flex-row gap-2 mb-3"> | ||
<div class="form-column"> | ||
|
||
@if(modService.activeDependencies().length === 0) { | ||
<div class="form-row"> | ||
<p>You don't currently have any dependencies.</p> | ||
</div> | ||
} | ||
|
||
@for(dep of modService.activeDependencies(); track $index) { | ||
<div class="form-row split pl-3"> | ||
<div class="form-column justify-center pr-3"> | ||
<div class="form-row"> | ||
<h2 class="text-xl font-bold mb-1">{{ dep.meta.name }}</h2> | ||
<h3 class="text-lg italic mb-2">{{ dep.meta.author }} · Last edited {{ dep.meta.savedAt | date }}</h3> | ||
|
||
<p class="italic">{{ dep.meta._url }}</p> | ||
</div> | ||
</div> | ||
|
||
<div class="form-column justify-center"> | ||
<div class="form-row"> | ||
<ul class="list-disc"> | ||
<li>{{ dep.achievements.length | number }} Achievements</li> | ||
<li>{{ dep.items.length | number }} Items</li> | ||
<li>{{ dep.npcs.length | number }} NPCs</li> | ||
<li>{{ dep.dialogs.length | number }} NPC Scripts</li> | ||
<li>{{ dep.quests.length | number }} Quests</li> | ||
<li>{{ dep.recipes.length | number }} Recipes</li> | ||
<li>{{ dep.spawners.length | number }} Spawners</li> | ||
<li>{{ dep.stems.length | number }} STEMs</li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<div class="form-column justify-center"> | ||
<div class="form-row"> | ||
<button class="ml-1 btn btn-info btn-sm" (click)="addNewDependency(dep.meta._url)"> | ||
<ng-icon name="heroArrowPathRoundedSquare"></ng-icon> | ||
</button> | ||
<button class="ml-1 btn btn-error btn-sm" (click)="removeDependency(dep.meta.name)"> | ||
<ng-icon name="heroMinus"></ng-icon> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
|
||
</div> | ||
</div> | ||
|
||
<swal #addDependency title="Add Dependency" text="Add a dependency by pasting the link here." input="text" | ||
confirmButtonText="Add Dependency" [focusCancel]="true" (confirm)="addNewDependency($event)"> | ||
</swal> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, inject, output } from '@angular/core'; | ||
import { ElectronService } from '../services/electron.service'; | ||
import { ModService } from '../services/mod.service'; | ||
|
||
@Component({ | ||
selector: 'app-dependencies', | ||
templateUrl: './dependencies.component.html', | ||
styleUrl: './dependencies.component.scss', | ||
}) | ||
export class DependenciesComponent { | ||
public exit = output(); | ||
|
||
public modService = inject(ModService); | ||
private electronService = inject(ElectronService); | ||
|
||
addNewDependency(dependency: string) { | ||
if (!dependency?.trim()) return; | ||
this.electronService.send('ADD_DEPENDENCY', dependency); | ||
} | ||
|
||
removeDependency(dependency: string) { | ||
this.modService.removeModDependency(dependency); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.