Skip to content

Commit

Permalink
Add UtilityMixin
Browse files Browse the repository at this point in the history
The mixin contains code which is shared by the implementations of r2
and Thunderstore mod managers.

Updating the game and profile specific mod lists were split to separate
methods since as far as I could tell, one doesn't affect the other.

Refs TS-1140
  • Loading branch information
anttimaki committed Nov 21, 2022
1 parent a16ba31 commit dee959f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
32 changes: 5 additions & 27 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
</template>

<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import Component, { mixins } from 'vue-class-component';
import 'bulma-steps/dist/js/bulma-steps.min.js';
import R2Error from './model/errors/R2Error';
import ManagerSettings from './r2mm/manager/ManagerSettings';
Expand Down Expand Up @@ -57,10 +56,6 @@ import AdmZipProvider from './providers/generic/zip/AdmZipProvider';
import ManagerSettingsMigration from './r2mm/manager/ManagerSettingsMigration';
import BindLoaderImpl from './providers/components/loaders/bind_impls/BindLoaderImpl';
import GameManager from './model/game/GameManager';
import ThunderstorePackages from './r2mm/data/ThunderstorePackages';
import ProfileModList from './r2mm/mods/ProfileModList';
import Profile from './model/Profile';
import ManifestV2 from './model/ManifestV2';
import PlatformInterceptorProvider from './providers/generic/game/platform_interceptor/PlatformInterceptorProvider';
import PlatformInterceptorImpl from './providers/generic/game/platform_interceptor/PlatformInterceptorImpl';
import ProfileInstallerProvider from './providers/ror2/installing/ProfileInstallerProvider';
Expand All @@ -69,10 +64,10 @@ import InstallationRuleApplicator from './r2mm/installing/default_installation_r
import GenericProfileInstaller from './r2mm/installing/profile_installers/GenericProfileInstaller';
import ConnectionProviderImpl from './r2mm/connection/ConnectionProviderImpl';
import ConnectionProvider from './providers/generic/connection/ConnectionProvider';
import ApiCacheUtils from './utils/ApiCacheUtils';
import UtilityMixin from './components/mixins/UtilityMixin.vue';
@Component
export default class App extends Vue {
export default class App extends mixins(UtilityMixin) {
private errorMessage: string = '';
private errorStack: string = '';
Expand Down Expand Up @@ -100,7 +95,8 @@ export default class App extends Vue {
const riskOfRain2Game = GameManager.gameList.find(value => value.displayName === "Risk of Rain 2")!;
GameManager.activeGame = riskOfRain2Game;
this.hookModListRefresh();
this.hookThunderstoreModListRefresh();
this.hookProfileModListRefresh();
const settings = await ManagerSettings.getSingleton(riskOfRain2Game);
this.settings = settings;
Expand Down Expand Up @@ -169,23 +165,5 @@ export default class App extends Vue {
BindLoaderImpl.bind();
}
private hookModListRefresh() {
setInterval(() => {
ThunderstorePackages.update(GameManager.activeGame)
.then(async (response) => {
await ApiCacheUtils.storeLastRequest(response.data);
await this.$store.dispatch("updateThunderstoreModList", ThunderstorePackages.PACKAGES);
// Ignore the warning. If no profile is selected on game selection then getActiveProfile will return undefined.
if (Profile.getActiveProfile() !== undefined) {
ProfileModList.getModList(Profile.getActiveProfile()).then((value: ManifestV2[] | R2Error) => {
if (!(value instanceof R2Error)) {
this.$store.dispatch("updateModList", value);
}
});
}
});
}, 5 * 60 * 1000);
}
}
</script>
45 changes: 45 additions & 0 deletions src/components/mixins/UtilityMixin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script lang='ts'>
import Vue from 'vue';
import Component from 'vue-class-component';
import R2Error from '../../model/errors/R2Error';
import GameManager from '../../model/game/GameManager';
import Profile from '../../model/Profile';
import ThunderstorePackages from '../../r2mm/data/ThunderstorePackages';
import ProfileModList from '../../r2mm/mods/ProfileModList';
import ApiCacheUtils from '../../utils/ApiCacheUtils';
@Component
export default class UtilityMixin extends Vue {
readonly REFRESH_INTERVAL = 5 * 60 * 1000;
hookProfileModListRefresh() {
setInterval(this.refreshProfileModList, this.REFRESH_INTERVAL);
}
hookThunderstoreModListRefresh() {
setInterval(this.refreshThunderstoreModList, this.REFRESH_INTERVAL);
}
async refreshProfileModList() {
const profile = Profile.getActiveProfile();
// If no profile is selected on game selection then getActiveProfile will return undefined.
if (profile === undefined) {
return;
}
const modList = await ProfileModList.getModList(profile);
if (!(modList instanceof R2Error)) {
this.$store.dispatch("updateModList", modList);
}
}
async refreshThunderstoreModList() {
const response = await ThunderstorePackages.update(GameManager.activeGame);
await ApiCacheUtils.storeLastRequest(response.data);
await this.$store.dispatch("updateThunderstoreModList", ThunderstorePackages.PACKAGES);
}
}
</script>

0 comments on commit dee959f

Please sign in to comment.