From 6db080b23254326f50cca9d36e942695608af38c Mon Sep 17 00:00:00 2001 From: James Date: Wed, 27 Sep 2023 21:46:30 -0500 Subject: [PATCH] fix plugin issues --- plugin/src/lua/plugin/PluginRunner.lua | 80 +++++----- .../src/lua/plugin/Vendor/Core/PluginGui.lua | 16 +- .../plugin/Vendor/Core/VersionController.lua | 30 ++-- .../Vendor/Libraries/EasyProfile/init.luau | 138 +++++------------- 4 files changed, 108 insertions(+), 156 deletions(-) diff --git a/plugin/src/lua/plugin/PluginRunner.lua b/plugin/src/lua/plugin/PluginRunner.lua index 52a87e4f..f781f500 100644 --- a/plugin/src/lua/plugin/PluginRunner.lua +++ b/plugin/src/lua/plugin/PluginRunner.lua @@ -2,7 +2,7 @@ local RunService = game:GetService("RunService") -if not plugin or RunService:IsRunMode() then +if not plugin or not RunService:IsEdit() then return end @@ -23,37 +23,44 @@ local CanaryStudioPluginButton = CanaryStudioPluginToolbar:CreateButton("Canary local PluginFinishedLoading = false local IsTesting = false +local OverrideValues = { + ReleaseLatest = { + published_at = "2007-01-14T20:34:22+00:00", + body = "This is a test!", + tag_name = "0.0.0", + target_commitish = "main" + }, + + LibrariesList = { + Roblox = '"TestPackage": {"$className": "ModuleScript"}', + Is = '"TestPackage": {"$className": "ModuleScript"}', + Cool = '"TestPackage": {"$className": "ModuleScript"}', + ["B)"] = '"TestPackage": {"$className": "ModuleScript"}', + }, + + ExternalSettings = { + Files = 14, + CanaryStudioChangelog = "We've made some large changes since the last update to the plugin and have fixed lots of bugs!\n\nInstalling has been revamped - The process is now a lot quicker and more performant\nRedesigned Home Page - The home page now has a menu bar and shows this changelog\nInternal code rework - It's now a lot easier to fix issues and add new features" + }, +} + +local HttpCache = require(Vendor.Core.HttpCache) Fetch.SetHttpCacheTable(Vendor.Core.HttpCache) if IsTesting then - local HttpCache = require(Vendor.Core.HttpCache) - PluginFinishedLoading = true - for cacheName in GitHubRequests do - if cacheName == "ReleaseLatest" then - HttpCache[cacheName] = { - published_at = "2007-01-14T20:34:22+00:00", - body = "This is a test!", - tag_name = "0.0.0", - target_commitish = "main" - } - elseif cacheName == "LibrariesList" then - HttpCache[cacheName] = { - Roblox = '"TestPackage": {"$className": "ModuleScript"}', - Is = '"TestPackage": {"$className": "ModuleScript"}', - Cool = '"TestPackage": {"$className": "ModuleScript"}', - ["B)"] = '"TestPackage": {"$className": "ModuleScript"}', - } - elseif cacheName == "ExternalSettings" then - HttpCache[cacheName] = { - Files = 11, - CanaryStudioChangelog = "We've made some large changes since the last update to the plugin and have fixed lots of bugs!\n\nInstalling has been revamped - The process is now a lot quicker and more performant\nRedesigned Home Page - The home page now has a menu bar and shows this changelog\nInternal code rework - It's now a lot easier to fix issues and add new features" - } - end + HttpCache[cacheName] = OverrideValues[cacheName] end + + PluginFinishedLoading = true else for cacheName, URL in GitHubRequests do - Fetch.FetchAsync(URL, true, 3, cacheName) + local Result = Fetch.FetchAsync(URL, true, 3, cacheName) + + if not Result then + warn("[CanaryStudio]: Could not fetch valid URL, getting local values. It is recommended to re-enter the place as most vital features will not work offline.") + HttpCache[cacheName] = OverrideValues[cacheName] + end end end @@ -62,30 +69,27 @@ local WindowController = require(Vendor.Core.WindowController)(PluginGui) CanaryStudioPluginButton.Click:Connect(function() if not PluginFinishedLoading then - warn("CanaryStudio has not finished loading yet.") + warn("[CanaryStudio]: Canary Studio has not finished loading yet.") return end WindowController.SetWindow("HomeWindow") end) -if IsTesting then - for scriptType, templateTable in CanaryStudioSettings.CanaryStudioInstanceTemplates do - for context, templateURL in templateTable do +for scriptType, templateTable in CanaryStudioSettings.CanaryStudioInstanceTemplates do + for context, templateURL in templateTable do + if IsTesting then CanaryStudioSettings.CanaryStudioInstanceTemplates[scriptType][context] = "-- this is testing!" + continue end - end -else - for scriptType, templateTable in CanaryStudioSettings.CanaryStudioInstanceTemplates do - for context, templateURL in templateTable do - local TemplateContents = Fetch.FetchAsync(templateURL, false) - if not TemplateContents then - CanaryStudioSettings.CanaryStudioInstanceTemplates[scriptType][context] = "-- could not get source" - end + local TemplateContents = Fetch.FetchAsync(templateURL, false) - CanaryStudioSettings.CanaryStudioInstanceTemplates[scriptType][context] = TemplateContents + if not TemplateContents then + CanaryStudioSettings.CanaryStudioInstanceTemplates[scriptType][context] = "-- could not get source" end + + CanaryStudioSettings.CanaryStudioInstanceTemplates[scriptType][context] = TemplateContents end end diff --git a/plugin/src/lua/plugin/Vendor/Core/PluginGui.lua b/plugin/src/lua/plugin/Vendor/Core/PluginGui.lua index cd75e4a0..b7e7ad1b 100644 --- a/plugin/src/lua/plugin/Vendor/Core/PluginGui.lua +++ b/plugin/src/lua/plugin/Vendor/Core/PluginGui.lua @@ -24,6 +24,7 @@ if not AlreadyRan then local TotalFiles = Iris.State(1) local TitleMessage = Iris.State("Updating ") local BelowMessage = Iris.State("Updating framework to latest version") + local FileType = Iris.State("files") Iris.UpdateGlobalConfig(Iris.TemplateConfig.sizeClear) Iris.UpdateGlobalConfig(Iris.TemplateConfig[`color{StudioSettings.Theme.Name}`]) @@ -136,7 +137,7 @@ if not AlreadyRan then end Iris.End() WindowList.ReleaseNotesWindow = Iris.Window(`Release Notes for {HttpCache.ReleaseLatest.tag_name}`, {isOpened = false}) do - Iris.Text(HttpCache.ReleaseLatest.body, true) + Iris.Text({HttpCache.ReleaseLatest.body, true}) Iris.Separator() Iris.Text(`Commit Branch: {HttpCache.ReleaseLatest.target_commitish}`) Iris.Text(`Published At: {FormattedPublishDate}`) @@ -144,15 +145,17 @@ if not AlreadyRan then WindowList.UpdateStatusWindow = Iris.Window({`{TitleMessage:get()}({math.floor((FinishedFiles:get() / TotalFiles:get()) * 100)}%)`, [Iris.Args.Window.NoClose] = true, [Iris.Args.Window.NoResize] = true}, {isOpened = false, size = Vector2.new(334, 109)}) do Iris.Text(BelowMessage:get()) - Iris.Text(`{FinishedFiles:get()} of {HttpCache.ExternalSettings.Files} files`) + Iris.Text(`{FinishedFiles:get()} of {TotalFiles:get()} files`) end Iris.End() WindowList.PackageManagerWindow = Iris.Window("Canary Studio - Package Manager", {isOpened = false}) do - + for libraryName in HttpCache.LibrariesList do + Settings.CanaryStudioInstallerPackages[libraryName] = Iris.Checkbox(libraryName).state.isChecked:get() + end end Iris.End() WindowList.ConfirmWindow = Iris.Window({"Confirm", [Iris.Args.Window.NoClose] = true, [Iris.Args.Window.NoTitleBar] = true}, {isOpened = false, size = Vector2.new(432, 122)}) do - Iris.Text(PluginGuiContents.ConfirmWindow.MessageText, true) + Iris.Text({PluginGuiContents.ConfirmWindow.MessageText, true}) Iris.SameLine() do if Iris.Button("OK").clicked() then PluginGuiContents.ConfirmWindow.ConfirmFunction() @@ -166,7 +169,7 @@ if not AlreadyRan then end Iris.End() WindowList.MessageWindow = Iris.Window({"Message", [Iris.Args.Window.NoClose] = true, [Iris.Args.Window.NoTitleBar] = true}, {isOpened = false, size = Vector2.new(432, 122)}) do - Iris.Text(PluginGuiContents.MessageWindow.MessageText, true, PluginGuiContents.MessageWindow.TextColor) + Iris.Text({PluginGuiContents.MessageWindow.MessageText, true, PluginGuiContents.MessageWindow.TextColor}) if Iris.Button("OK").clicked() then WindowController.SetWindow("MessageWindow", false) @@ -178,11 +181,12 @@ if not AlreadyRan then WindowController = require(Vendor.Core.WindowController)(WindowList) VersionController = require(Vendor.Core.VersionController) - VersionController.DataUpdated:Connect(function(files, totalfiles, title, body) + VersionController.DataUpdated:Connect(function(files, totalfiles, title, body, filetype) FinishedFiles:set(files) TotalFiles:set(totalfiles) TitleMessage:set(title) BelowMessage:set(body) + FileType:set(filetype) end) return WindowList diff --git a/plugin/src/lua/plugin/Vendor/Core/VersionController.lua b/plugin/src/lua/plugin/Vendor/Core/VersionController.lua index 4e9493f7..80a59e16 100644 --- a/plugin/src/lua/plugin/Vendor/Core/VersionController.lua +++ b/plugin/src/lua/plugin/Vendor/Core/VersionController.lua @@ -90,7 +90,7 @@ function VersionController.GetDirectoryFromStructureJSON(json: {any}, parent: In if not isPackage then FinishedFiles += 1 - VersionController.DataUpdated:Fire(FinishedFiles, HttpCache.ExternalSettings.Files, "Updating ", "Updating framework to latest version") + VersionController.DataUpdated:Fire(FinishedFiles, HttpCache.ExternalSettings.Files, "Updating ", "Updating framework to latest version", "files") end InstanceFromClass[propertyName] = Source @@ -194,9 +194,17 @@ function VersionController.UpdateFramework() CanaryEngineStructure.Parent = ReplicatedStorage end - if CurrentInstance.ReplicatedFirst then - CurrentInstance.ReplicatedFirst.Framework:Destroy() - EngineLoaderStructure.Parent = CurrentInstance.ReplicatedFirst + if CurrentInstance.ReplicatedFirst then + if CurrentInstance.ReplicatedFirst.Framework or CurrentInstance.ReplicatedFirst.Internal then + local EngineItem = CurrentInstance.ReplicatedFirst.Framework + + if not EngineItem then + EngineItem = CurrentInstance.ReplicatedFirst.Internal + end + + EngineItem:Destroy() + EngineLoaderStructure.Parent = CurrentInstance.ReplicatedFirst + end end if not ReplicatedFirst:GetAttribute("EngineLoaderEnabled") then @@ -209,7 +217,7 @@ function VersionController.UpdateFramework() task.wait(UPDATE_COOLDOWN_SECONDS) UpdateDebounce = false FinishedFiles = 0 - VersionController.DataUpdated:Fire(FinishedFiles, 1, "nil", "nil") + VersionController.DataUpdated:Fire(FinishedFiles, 1, "nil", "nil", "nil") end) end @@ -263,11 +271,9 @@ function VersionController.InstallFramework() FinishedFiles = 0 - if not TableKit.IsEmpty(HttpCache.LibrariesList) then - for _, value in CanaryStudioSettings.CanaryStudioInstallerPackages do - if value then - TotalPackageFiles += 1 - end + for _, value in CanaryStudioSettings.CanaryStudioInstallerPackages do + if value then + TotalPackageFiles += 1 end end @@ -283,7 +289,7 @@ function VersionController.InstallFramework() PackageInstallCache:FindFirstChild(libraryName):Clone().Parent = NewInstance[libraryJSON["$parent"] or "Replicated"].Packages FinishedFiles += 1 - VersionController.DataUpdated:Fire(FinishedFiles, TotalPackageFiles, "Installing ", "Installing latest version of packages") + VersionController.DataUpdated:Fire(FinishedFiles, TotalPackageFiles, "Installing ", "Installing latest version of packages", "packages") end FinishedFiles = 0 @@ -292,7 +298,7 @@ function VersionController.InstallFramework() WindowController.SetWindow("UpdateStatusWindow", false) WindowController.SetMessageWindow("Framework installed successfully!", Color3.fromRGB(205, 255, 151)) - VersionController.DataUpdated:Fire(FinishedFiles, 1, "nil", "nil") + VersionController.DataUpdated:Fire(FinishedFiles, 1, "nil", "nil", "nil") task.wait(UPDATE_COOLDOWN_SECONDS) UpdateDebounce = false end) diff --git a/src/lua/framework/Vendor/Libraries/EasyProfile/init.luau b/src/lua/framework/Vendor/Libraries/EasyProfile/init.luau index 7dd2778b..92ed74ce 100644 --- a/src/lua/framework/Vendor/Libraries/EasyProfile/init.luau +++ b/src/lua/framework/Vendor/Libraries/EasyProfile/init.luau @@ -52,48 +52,29 @@ ProfileObject.__index = ProfileObject EasyProfile.LoadedData = { } -type EasyProfile = { - LoadedData: {[string]: {[Player | string]: ProfileObject}}, - CreateProfileStore: (name: string, defaultProfileData: {[string]: any}, playerKeyPattern: string?) -> (ProfileStoreObject) -} - -export type ProfileObject = { - GlobalKeyAdded: Types.SignalController, - - CreateProfileLeaderstats: (self: ProfileObject, player: Player, statsToAdd: {string}?) -> (), - CanSaveData: (self: ProfileObject) -> (boolean), - GetProfileData: (self: ProfileObject) -> ({[string]: any}), - GetGlobalKeys: (self: ProfileObject) -> ({GlobalKey}?), - AddUserIds: (self: ProfileObject, userIds: {number} | number) -> (), - GetUserIds: (self: ProfileObject) -> ({number}?), - RemoveUserIds: (self: ProfileObject, userIds: {number}?) -> (), - GetMetaData: (self: ProfileObject) -> (ProfileMetaData), - GetDataUsage: (self: ProfileObject) -> (number?), -} - -export type ProfileStoreObject = { - SessionLockClaimed: Types.SignalController, - SessionLockUnclaimed: Types.SignalController, - - DeleteProfileAsync: (self: ProfileStoreObject, owner: number | string) -> (), - GetProfileAsync: (self: ProfileStoreObject, owner: number | string) -> ({[string]: any}?), - LoadProfileAsync: (self: ProfileStoreObject, owner: Player | string, reconcileData: boolean?, profileClaimedHandler: (((placeId: number, gameJobId: string) -> (ProfileLoadType)) | ProfileLoadType)?) -> (Future.Future), - UnclaimSessionLock: (self: ProfileStoreObject, owner: Player | string, valuesToSave: {[string]: any}, hopReadyCallback: (() -> ())?) -> (), - SetGlobalKeyAsync: (self: ProfileStoreObject, target: number | string, key: string, value: any) -> (), - RemoveGlobalKeyAsync: (self: ProfileStoreObject, target: number | string, keyId: number) -> (), -} - -- // Functions if not RunService:IsServer() then error("Cannot run on any environments except the server.") end -local function IsKeyValid(key: Player | string) - +local function IsProfileKeyValid(target: (Player | string | number)?, pattern: string, err: string, ...: string): string + if not target then + error("Target does not exist; did you forget to pass it?") + end + + if typeof(target) == "string" then + return target + elseif typeof(target) == "number" then + return string.format(pattern, target) + elseif typeof(target) == "Instance" and target:IsA("Player") then + return string.format(pattern, target.UserId) + else + error(string.format(err, ...)) + end end -function EasyProfile.CreateProfileStore(name: string?, defaultProfileData: {[string]: any}, playerKeyPattern: string?): ProfileStoreObject? +function EasyProfile.CreateProfileStore(name: string?, defaultProfileData: {[string]: any}, playerKeyPattern: string?) if not defaultProfileData then error("Default profile data is required") end @@ -117,30 +98,18 @@ end function ProfileStoreObject:DeleteProfileAsync(target: number | string) local CurrentLoadedProfileStore = self._ProfileStore - local ProfileKey: string - - if typeof(target) == "string" then - ProfileKey = target - elseif typeof(target) == "number" then - ProfileKey = string.format(self._Pattern, target) - else - error(`Cannot delete profile of type {typeof(target)}`) - end + local ProfileKey = IsProfileKeyValid(target, self._Pattern, + "Cannot delete profile of type %s", + typeof(target)) CurrentLoadedProfileStore:WipeProfileAsync(ProfileKey) end -function ProfileStoreObject:GetProfileAsync(target: number | string): Future.Future<{[string]: any}, () -> ()> +function ProfileStoreObject:GetProfileAsync(target: number | string): Future.Future ()> return Future.Try(function(profileStore, target) - local ProfileKey: string - - if typeof(target) == "string" then - ProfileKey = target - elseif typeof(target) == "number" then - ProfileKey = string.format(self._Pattern, target) - else - error(`Cannot get profile of type {typeof(target)}`) - end + local ProfileKey = IsProfileKeyValid(target, self._Pattern, + "Cannot get profile of type %s", + typeof(target)) local ProfileToView = profileStore:ViewProfileAsync(ProfileKey) @@ -148,7 +117,7 @@ function ProfileStoreObject:GetProfileAsync(target: number | string): Future.Fut error(`Requested data for target {target} does not exist, or was not fetched properly`) end - local Overwrite + local Overwrite: () -> () | nil Overwrite = function() ProfileToView:OverwriteAsync() @@ -159,26 +128,12 @@ function ProfileStoreObject:GetProfileAsync(target: number | string): Future.Fut end, self._ProfileStore, target) end -function ProfileStoreObject:LoadProfileAsync(owner: Player | string, reconcileData: boolean?, profileClaimedHandler: (((placeId: number, gameJobId: string) -> (ProfileLoadType)) | ProfileLoadType)?): Future.Future +function ProfileStoreObject:LoadProfileAsync(owner: Player | string, reconcileData: boolean?, profileClaimedHandler: (((placeId: number, gameJobId: string) -> (ProfileLoadType)) | ProfileLoadType)?): Future.Future return Future.Try(function(profileStore, owner, reconcileData, profileClaimedHandler) - if not profileStore then - error("No profile store loaded, make sure API requests are enabled") - end - - if not owner then - error("Cannot unclaim session lock for a owner that is non-existent") - end - local ProfileObjectMetatable = setmetatable({ }, ProfileObject) - local ProfileKey: string - - if typeof(owner) == "string" then - ProfileKey = owner - elseif typeof(owner) == "Instance" and owner:IsA("Player") then - ProfileKey = string.format(self._Pattern, owner.UserId) - else - error(`Cannot get profile key of type {typeof(owner)}`) - end + local ProfileKey = IsProfileKeyValid(owner, self._Pattern, + "Cannot get profile of type %s", + typeof(owner)) local LoadedProfile = profileStore:LoadProfileAsync(ProfileKey, profileClaimedHandler) @@ -202,9 +157,6 @@ function ProfileStoreObject:LoadProfileAsync(owner: Player | string, reconcileDa EasyProfile.LoadedData[self._Name][owner] = nil self.SessionLockUnclaimed:Fire(owner) - setmetatable(ProfileObjectMetatable, nil) - table.clear(ProfileObjectMetatable) - if typeof(owner) == "Instance" and owner:IsA("Player") then owner:Kick(`Data for user {owner.UserId} active on another server, please try again`) end @@ -224,10 +176,9 @@ function ProfileStoreObject:LoadProfileAsync(owner: Player | string, reconcileDa end) ProfileObjectMetatable.GlobalKeyAdded = Signal.CreateController("GlobalKeyAdded") :: Types.SignalController - ProfileObjectMetatable.Profile = LoadedProfile - EasyProfile.LoadedData[self._Name][owner] = ProfileObjectMetatable + EasyProfile.LoadedData[self._Name][owner] = ProfileObjectMetatable self.SessionLockClaimed:Fire(owner) return table.freeze(ProfileObjectMetatable) @@ -235,11 +186,11 @@ function ProfileStoreObject:LoadProfileAsync(owner: Player | string, reconcileDa end function ProfileStoreObject:UnclaimSessionLock(owner: Player | string, valuesToSave: {[string]: any}?, hopReadyCallback: (() -> ())?) - if not owner then - error("Cannot unclaim session lock for a owner that is non-existent") - end + local ProfileKey = IsProfileKeyValid(owner, self._Pattern, + "Cannot unclaim invalid session reference: %s", + typeof(owner)) - local Profile = EasyProfile.LoadedData[self._Name][owner].Profile + local Profile = EasyProfile.LoadedData[self._Name][ProfileKey].Profile if valuesToSave then for key, value in valuesToSave do @@ -260,16 +211,9 @@ end function ProfileStoreObject:SetGlobalKeyAsync(target: number | string, key: string, value: any) local CurrentLoadedProfileStore = self._ProfileStore - local ProfileKey: string - - if typeof(target) == "string" then - ProfileKey = target - elseif typeof(target) == "number" then - ProfileKey = string.format(self._Pattern, target) - else - error(`Cannot set global key of type {typeof(target)}`) - return - end + local ProfileKey = IsProfileKeyValid(target, self._Pattern, + "Cannot sent global key to invalid user: %s", + typeof(target)) CurrentLoadedProfileStore:GlobalUpdateProfileAsync(ProfileKey, function(globalUpdates) globalUpdates:AddActiveUpdate({ @@ -281,15 +225,9 @@ end function ProfileStoreObject:RemoveGlobalKeyAsync(target: number | string, keyId: number) local CurrentLoadedProfileStore = self._ProfileStore - local ProfileKey: string - - if typeof(target) == "string" then - ProfileKey = target - elseif typeof(target) == "number" then - ProfileKey = string.format(self._Pattern, target) - else - error(`Cannot remove global key of type {typeof(target)}`) - end + local ProfileKey = IsProfileKeyValid(target, self._Pattern, + "Cannot remove global key for invalid user: %s", + typeof(target)) CurrentLoadedProfileStore:GlobalUpdateProfileAsync(ProfileKey, function(globalUpdates) globalUpdates:ClearActiveUpdate(keyId)