Implement Firebase config management via GitHub Actions secrets

This commit is contained in:
Andrei Andreev 2023-04-20 23:01:58 +02:00
parent a0b9e36ed4
commit 0b1fa8723a
7 changed files with 72 additions and 16 deletions

View File

@ -1,5 +1,8 @@
name: Deploy master name: Deploy master
env:
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
on: on:
push: push:
branches: branches:

View File

@ -1,5 +1,8 @@
name: Deploy release name: Deploy release
env:
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
on: on:
push: push:
branches: branches:

View File

@ -5,3 +5,11 @@ const browserslist = require("browserslist-useragent-regexp");
const userAgentRegExp = browserslist.getUserAgentRegExp({ allowHigherVersions: true }); const userAgentRegExp = browserslist.getUserAgentRegExp({ allowHigherVersions: true });
const checkFunction = `export const supportedBrowsers = ${userAgentRegExp};`; const checkFunction = `export const supportedBrowsers = ${userAgentRegExp};`;
fs.writeFileSync(path.resolve(__dirname, "../src/supported-browsers.js"), checkFunction); fs.writeFileSync(path.resolve(__dirname, "../src/supported-browsers.js"), checkFunction);
const firebaseConfig = process.env.FIREBASE_CONFIG;
if (firebaseConfig) {
fs.writeFileSync(
path.resolve(__dirname, "../src/core/storage/firebase-config.js"),
`export const firebaseConfig = ${firebaseConfig};`
);
}

View File

@ -18,6 +18,7 @@ export default {
}, },
data() { data() {
return { return {
cloudAvailable: false,
cloudEnabled: false, cloudEnabled: false,
forceCloudOverwrite: false, forceCloudOverwrite: false,
showCloudModal: false, showCloudModal: false,
@ -70,6 +71,7 @@ export default {
methods: { methods: {
update() { update() {
const options = player.options; const options = player.options;
this.cloudAvailable = Cloud.isAvailable;
this.cloudEnabled = options.cloudEnabled; this.cloudEnabled = options.cloudEnabled;
this.forceCloudOverwrite = options.forceCloudOverwrite; this.forceCloudOverwrite = options.forceCloudOverwrite;
this.showCloudModal = options.showCloudModal; this.showCloudModal = options.showCloudModal;
@ -209,7 +211,10 @@ export default {
</div> </div>
<OpenModalHotkeysButton /> <OpenModalHotkeysButton />
</div> </div>
<h2 class="c-cloud-options-header"> <h2
v-if="cloudAvailable"
class="c-cloud-options-header"
>
<span v-if="hideGoogleName">Logged in to Google <i>(name hidden)</i></span> <span v-if="hideGoogleName">Logged in to Google <i>(name hidden)</i></span>
<span v-else-if="loggedIn">Logged in as {{ userName }}</span> <span v-else-if="loggedIn">Logged in as {{ userName }}</span>
<span v-else>Not logged in</span> <span v-else>Not logged in</span>
@ -218,7 +223,10 @@ export default {
<span v-if="cloudEnabled">Cloud Saving will occur automatically every 10 minutes.</span> <span v-if="cloudEnabled">Cloud Saving will occur automatically every 10 minutes.</span>
<span v-else>Cloud Saving has been disabled on this save.</span> <span v-else>Cloud Saving has been disabled on this save.</span>
</div> </div>
<div class="l-options-grid"> <div
v-if="cloudAvailable"
class="l-options-grid"
>
<div <div
v-if="!STEAM" v-if="!STEAM"
class="l-options-grid__row" class="l-options-grid__row"

View File

@ -485,6 +485,7 @@ GameDatabase.tabs = [
name: "Shop", name: "Shop",
newUIClass: "shop", newUIClass: "shop",
hideAt: 1.5, hideAt: 1.5,
condition: () => Cloud.isAvailable,
id: 10, id: 10,
hidable: true, hidable: true,
subtabs: [ subtabs: [

View File

@ -17,28 +17,26 @@ import { sha512_256 } from "js-sha512";
import { STEAM } from "@/env"; import { STEAM } from "@/env";
import { decodeBase64Binary } from "./base64-binary"; import { decodeBase64Binary } from "./base64-binary";
import { firebaseConfig } from "./firebase-config";
import { ProgressChecker } from "./progress-checker"; import { ProgressChecker } from "./progress-checker";
import { SteamRuntime } from "@/steam"; import { SteamRuntime } from "@/steam";
const firebaseConfig = { const hasFirebaseConfig = firebaseConfig.apiKey !== null;
apiKey: "AIzaSyDuRTTluAFufmvw1zxGH6fsyEHmmbu8IHI", if (hasFirebaseConfig) {
authDomain: "antimatter-dimensions-a00f2.firebaseapp.com", initializeApp(firebaseConfig);
databaseURL: "https://antimatter-dimensions-a00f2.firebaseio.com", }
projectId: "antimatter-dimensions-a00f2",
storageBucket: "antimatter-dimensions-a00f2.appspot.com",
messagingSenderId: "904798020003",
appId: "1:904798020003:web:d1448dcb2dedd8b5",
};
initializeApp(firebaseConfig);
export const Cloud = { export const Cloud = {
provider: new GoogleAuthProvider(), provider: hasFirebaseConfig ? new GoogleAuthProvider() : null,
auth: getAuth(), auth: hasFirebaseConfig ? getAuth() : null,
db: getDatabase(), db: hasFirebaseConfig ? getDatabase() : null,
user: null, user: null,
lastCloudHash: null, lastCloudHash: null,
get isAvailable() {
return hasFirebaseConfig;
},
resetTempState() { resetTempState() {
this.lastCloudHash = null; this.lastCloudHash = null;
GameStorage.lastCloudSave = Date.now(); GameStorage.lastCloudSave = Date.now();
@ -50,6 +48,10 @@ export const Cloud = {
}, },
async login() { async login() {
if (!this.isAvailable) {
return;
}
try { try {
await signInWithPopup(this.auth, this.provider); await signInWithPopup(this.auth, this.provider);
ShopPurchaseData.syncSTD(); ShopPurchaseData.syncSTD();
@ -61,6 +63,10 @@ export const Cloud = {
}, },
async loginWithSteam(accountId, staticAccountId, screenName) { async loginWithSteam(accountId, staticAccountId, screenName) {
if (!this.isAvailable) {
return;
}
if (this.loggedIn) { if (this.loggedIn) {
Cloud.user.displayName = screenName; Cloud.user.displayName = screenName;
return; return;
@ -115,6 +121,10 @@ export const Cloud = {
}, },
async saveCheck(forceModal = false) { async saveCheck(forceModal = false) {
if (!this.isAvailable) {
return;
}
const saveId = GameStorage.currentSlot; const saveId = GameStorage.currentSlot;
const cloudSave = await this.load(); const cloudSave = await this.load();
if (cloudSave === null) { if (cloudSave === null) {
@ -173,6 +183,10 @@ export const Cloud = {
}, },
async loadCheck() { async loadCheck() {
if (!this.isAvailable) {
return;
}
const save = await this.load(); const save = await this.load();
if (save === null) { if (save === null) {
if (player.options.hideGoogleName) GameUI.notify.info(`No cloud save for current Google Account`); if (player.options.hideGoogleName) GameUI.notify.info(`No cloud save for current Google Account`);
@ -258,11 +272,19 @@ export const Cloud = {
}, },
logout() { logout() {
if (!this.isAvailable) {
return;
}
signOut(this.auth); signOut(this.auth);
ShopPurchaseData.clearLocalSTD(); ShopPurchaseData.clearLocalSTD();
}, },
init() { init() {
if (!this.isAvailable) {
return;
}
getAuth().onAuthStateChanged(user => { getAuth().onAuthStateChanged(user => {
if (user) { if (user) {
this.user = { this.user = {

View File

@ -0,0 +1,11 @@
// Replace the following with your app's Firebase project configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
export const firebaseConfig = {
"apiKey": null,
"authDomain": null,
"databaseURL": null,
"projectId": null,
"storageBucket": null,
"messagingSenderId": null,
"appId": null,
};