Skip to content

Commit

Permalink
Merge pull request #453 from intechstudio/DANIM1130/unify_profiles
Browse files Browse the repository at this point in the history
Danim1130/unify profiles
  • Loading branch information
danim1130 authored Oct 13, 2023
2 parents 09c7825 + 716c7de commit 38c7261
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 384 deletions.
39 changes: 39 additions & 0 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,36 @@ function startPluginDirectoryWatcher(
});
}

let configWatcher: chokidar.FSWatcher | undefined;
function startConfigWatcher(configPath, rootDirectory) {
configWatcher?.close();

async function sendLocalConfigs() {
var result = await loadConfigsFromDirectory(configPath, rootDirectory);
mainWindow.webContents.send("sendConfigsToRenderer", result);
}

configWatcher = chokidar.watch(path.join(configPath, "configs"), {
ignored: /[\/\\]\./,
persistent: true,
ignoreInitial: true, // Ignore initial events on startup
depth: 0, // Only watch the top-level directory
});
configWatcher.on("add", function (path) {
sendLocalConfigs();
});
configWatcher.on("change", function (path) {
sendLocalConfigs();
});
configWatcher.on("unlink", function (path) {
sendLocalConfigs();
});
configWatcher.on("ready", function () {
sendLocalConfigs();
});
sendLocalConfigs();
}

ipcMain.handle("startPlugin", async (event, arg) => {
console.log("pluginstart!", arg.name);
switch (arg.name) {
Expand Down Expand Up @@ -494,6 +524,15 @@ ipcMain.handle("saveConfig", async (event, arg) => {
return await saveConfig(arg.configPath, arg.rootDirectory, arg.config);
});

ipcMain.handle("startConfigsWatch", async (event, arg) => {
return await startConfigWatcher(arg.configPath, arg.rootDirectory);
});

ipcMain.handle("stopConfigsWatch", async (event) => {
configWatcher?.close();
configWatcher = undefined;
});

ipcMain.handle("deleteConfig", async (event, arg) => {
return await deleteConfig(arg.configPath, arg.rootDirectory, arg.config);
});
Expand Down
5 changes: 5 additions & 0 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ contextBridge.exposeInMainWorld("electron", {
configPath,
rootDirectory,
}),
onSendConfigsToRenderer: (callback) =>
ipcRenderer.on("sendConfigsToRenderer", callback),
startConfigsWatch: (configPath, rootDirectory) =>
ipcRenderer.invoke("startConfigsWatch", { configPath, rootDirectory }),
stopConfigsWatch: () => ipcRenderer.invoke("stopConfigsWatch"),
saveConfig: (configPath, rootDirectory, config) =>
ipcRenderer.invoke("saveConfig", {
configPath,
Expand Down
12 changes: 10 additions & 2 deletions src/electron/src/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ export async function loadConfigsFromDirectory(configPath, rootDirectory) {
if (isJson(data)) {
let obj = JSON.parse(data);
if (obj.configType) {
const dateObject = await getDateOfModify(filepath);
obj.fileName = file;
obj.fsModifiedAt = dateObject?.modifiedAt;

//TODO: remove around 2024 summer, temporary map from localId to id
if (!obj.id && obj.localId) {
obj.id = obj.localId;
delete obj.localId;
}
configs.push(obj);
} else {
log.info("JSON is not a grid config!");
Expand Down Expand Up @@ -152,6 +156,10 @@ export async function saveConfig(configPath, rootDirectory, config) {
config.name = `New local ${config.configType} ${fileNameCounter}`;
}

if (!config.id) {
config.id = uuidv4();
}

await fs.promises
.writeFile(
`${path}/${rootDirectory}/${fileName}.json`,
Expand Down
16 changes: 14 additions & 2 deletions src/renderer/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import { setTooltip } from "./main/user-interface/tooltip/Tooltip";
import { Analytics } from "./runtime/analytics.js";
import SendFeedback from "./main/user-interface/SendFeedback.svelte";
import { selectedConfigStore } from "./runtime/config-helper.store";
const configuration = window.ctxProcess.configuration();
Expand Down Expand Up @@ -98,7 +99,7 @@
window.electron.configs.onExternalResponse((_event, value) => {
// listening to this store on ProfileCloud.svelte
profileLinkStore.set({ id: value });
configLinkStore.set({ id: value });
});
window.onmessage = (event) => {
Expand Down Expand Up @@ -407,7 +408,18 @@
</div>
</div>
{:else}
<ActiveChanges class="w-fit self-center mt-10 " />
<ActiveChanges class="w-fit self-center mt-10 z-11" />
{#if $selectedConfigStore?.configType === "preset"}
<button
class="self-center mt-4 z-10 relative items-center justify-center focus:outline-none bg-select
rounded text-white py-1 w-24 hover:bg-yellow-600"
on:click={() => {
selectedConfigStore.set({});
}}
>
<div>Cancel</div>
</button>
{/if}
{/if}
{#if $runtime.length == 0 && $appSettings.firmwareNotificationState === 0}
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/lib/auth.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
GoogleAuthProvider,
OAuthProvider,
getAuth,
signInAnonymously,
signInWithCredential,
signOut,
} from "firebase/auth";
Expand Down Expand Up @@ -35,6 +36,13 @@ const createAuth = () => {
);
}

async function anonymousLogin() {
await signInAnonymously(centralAuth).then(async () => {
const userIdToken = await centralAuth.currentUser!.getIdToken();
set({ event: "login", providerId: "oidc", idToken: userIdToken });
});
}

async function socialLogin(provider, idToken) {
if (provider == "google") {
const credential = GoogleAuthProvider.credential(idToken);
Expand Down Expand Up @@ -65,6 +73,7 @@ const createAuth = () => {
login,
socialLogin,
logout,
anonymousLogin,
};
};

Expand Down
4 changes: 4 additions & 0 deletions src/renderer/main/modals/UserLogin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
authStore.login(email, password);
}
async function anonymousLogin() {
authStore.anonymousLogin();
}
async function logout() {
authStore.logout();
}
Expand Down
Loading

0 comments on commit 38c7261

Please sign in to comment.