diff --git a/.github/workflows/deploy-master.yml b/.github/workflows/deploy-master.yml index e23ee31ca..ac50bbf0b 100644 --- a/.github/workflows/deploy-master.yml +++ b/.github/workflows/deploy-master.yml @@ -1,5 +1,8 @@ name: Deploy master +env: + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + on: push: branches: diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index f03b684fb..160c3ae76 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -1,5 +1,8 @@ name: Deploy release +env: + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + on: push: branches: diff --git a/build/pre-build.js b/build/pre-build.js index fce54bf4d..f43d53b02 100644 --- a/build/pre-build.js +++ b/build/pre-build.js @@ -5,3 +5,11 @@ const browserslist = require("browserslist-useragent-regexp"); const userAgentRegExp = browserslist.getUserAgentRegExp({ allowHigherVersions: true }); const checkFunction = `export const supportedBrowsers = ${userAgentRegExp};`; 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};` + ); +} diff --git a/src/components/tabs/options-saving/OptionsSavingTab.vue b/src/components/tabs/options-saving/OptionsSavingTab.vue index 7dabf6e84..b1dad31fc 100644 --- a/src/components/tabs/options-saving/OptionsSavingTab.vue +++ b/src/components/tabs/options-saving/OptionsSavingTab.vue @@ -18,6 +18,7 @@ export default { }, data() { return { + cloudAvailable: false, cloudEnabled: false, forceCloudOverwrite: false, showCloudModal: false, @@ -70,6 +71,7 @@ export default { methods: { update() { const options = player.options; + this.cloudAvailable = Cloud.isAvailable; this.cloudEnabled = options.cloudEnabled; this.forceCloudOverwrite = options.forceCloudOverwrite; this.showCloudModal = options.showCloudModal; @@ -209,7 +211,10 @@ export default { -

+

Logged in to Google (name hidden) Logged in as {{ userName }} Not logged in @@ -218,7 +223,10 @@ export default { Cloud Saving will occur automatically every 10 minutes. Cloud Saving has been disabled on this save. -
+
Cloud.isAvailable, id: 10, hidable: true, subtabs: [ diff --git a/src/core/storage/cloud-saving.js b/src/core/storage/cloud-saving.js index 2c3e4ca2c..0d7c04e3b 100644 --- a/src/core/storage/cloud-saving.js +++ b/src/core/storage/cloud-saving.js @@ -17,28 +17,26 @@ import { sha512_256 } from "js-sha512"; import { STEAM } from "@/env"; import { decodeBase64Binary } from "./base64-binary"; +import { firebaseConfig } from "./firebase-config"; import { ProgressChecker } from "./progress-checker"; import { SteamRuntime } from "@/steam"; -const firebaseConfig = { - apiKey: "AIzaSyDuRTTluAFufmvw1zxGH6fsyEHmmbu8IHI", - authDomain: "antimatter-dimensions-a00f2.firebaseapp.com", - 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); +const hasFirebaseConfig = firebaseConfig.apiKey !== null; +if (hasFirebaseConfig) { + initializeApp(firebaseConfig); +} export const Cloud = { - provider: new GoogleAuthProvider(), - auth: getAuth(), - db: getDatabase(), + provider: hasFirebaseConfig ? new GoogleAuthProvider() : null, + auth: hasFirebaseConfig ? getAuth() : null, + db: hasFirebaseConfig ? getDatabase() : null, user: null, lastCloudHash: null, + get isAvailable() { + return hasFirebaseConfig; + }, + resetTempState() { this.lastCloudHash = null; GameStorage.lastCloudSave = Date.now(); @@ -50,6 +48,10 @@ export const Cloud = { }, async login() { + if (!this.isAvailable) { + return; + } + try { await signInWithPopup(this.auth, this.provider); ShopPurchaseData.syncSTD(); @@ -61,6 +63,10 @@ export const Cloud = { }, async loginWithSteam(accountId, staticAccountId, screenName) { + if (!this.isAvailable) { + return; + } + if (this.loggedIn) { Cloud.user.displayName = screenName; return; @@ -115,6 +121,10 @@ export const Cloud = { }, async saveCheck(forceModal = false) { + if (!this.isAvailable) { + return; + } + const saveId = GameStorage.currentSlot; const cloudSave = await this.load(); if (cloudSave === null) { @@ -173,6 +183,10 @@ export const Cloud = { }, async loadCheck() { + if (!this.isAvailable) { + return; + } + const save = await this.load(); if (save === null) { if (player.options.hideGoogleName) GameUI.notify.info(`No cloud save for current Google Account`); @@ -258,11 +272,19 @@ export const Cloud = { }, logout() { + if (!this.isAvailable) { + return; + } + signOut(this.auth); ShopPurchaseData.clearLocalSTD(); }, init() { + if (!this.isAvailable) { + return; + } + getAuth().onAuthStateChanged(user => { if (user) { this.user = { diff --git a/src/core/storage/firebase-config.js b/src/core/storage/firebase-config.js new file mode 100644 index 000000000..8f9c97b42 --- /dev/null +++ b/src/core/storage/firebase-config.js @@ -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, +};