Skip to content

Commit

Permalink
latest fixes before release
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgayayci committed Jan 24, 2024
1 parent 967b63d commit 42c2c20
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 126 deletions.
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.example.nextron
productName: Dfinity Dfx
productName: dfinity-dfx
copyright: Copyright © 2023 Tolga Yaycı
directories:
output: dist
Expand Down
30 changes: 17 additions & 13 deletions main/background.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fixPath = require("fix-path");
fixPath();

import { app, ipcMain, dialog } from "electron";
import serve from "electron-serve";

Expand All @@ -14,12 +17,10 @@ import {
const path = require("node:path");
const fs = require("fs");
const { shell } = require("electron");
const fixPath = require("fix-path");

const isProd: boolean = process.env.NODE_ENV === "production";

const Store = require("electron-store");
fixPath();

const schema = {
projects: {
Expand All @@ -43,10 +44,7 @@ const schema = {
properties: {
name: { type: "string" },
principal: { type: "string" },
isInternetIdentity: { type: "boolean" },
internetIdentityPrincipal: { type: "string", default: "" },
},
required: ["isInternetIdentity"],
},
},
};
Expand All @@ -70,7 +68,6 @@ if (isProd) {

(async () => {
await app.whenReady();
app.dock.setIcon("resources/icon.png");

const mainWindow = createWindow("main", {
width: 1500,
Expand Down Expand Up @@ -220,34 +217,31 @@ if (isProd) {
}
);

// New Function: Retrieve and Store Identities
async function retrieveAndStoreIdentities() {
try {
const result = await executeDfxCommand("identity", "list");
// Split the result string into an array of identities
const identityNames = result
.split("\n")
.filter((identity) => identity.trim() !== "");
.filter(
(identity) => identity.trim() !== "" && identity.trim() !== "*"
);

for (const name of identityNames) {
// Create an identity object
const identity = {
name: name,
isInternetIdentity: false, // Set this based on your criteria
internetIdentityPrincipal: "", // Set this appropriately
};

// Add each identity to the store
try {
await handleIdentities(store, "add", identity);
} catch (error) {
console.error(`Error adding identity '${name}':`, error);
// Handle error appropriately for each identity
}
}
} catch (error) {
console.error("Error retrieving identities:", error);
// Handle error appropriately
}
}

Expand All @@ -263,7 +257,7 @@ if (isProd) {
}
});

ipcMain.handle("env:read-script", async () => {
ipcMain.handle("env:read-script", async (event) => {
try {
const envVars = readEnvVarsFromProfiles();
return envVars;
Expand All @@ -273,6 +267,16 @@ if (isProd) {
}
});

ipcMain.handle("identity:refresh", async (event) => {
try {
const envVars = retrieveAndStoreIdentities();
return envVars;
} catch (error) {
console.error("Failed to read identities from dfx:", error);
return { error };
}
});

await retrieveAndStoreIdentities();

if (isProd) {
Expand Down
19 changes: 3 additions & 16 deletions main/helpers/manage-identities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@ export function handleIdentities(store, action, identity, newIdentity?) {

switch (action) {
case "add":
if (identity.isInternetIdentity) {
if (
identities.some(
(i) =>
i.internetIdentityPrincipal === identity.internetIdentityPrincipal
)
) {
throw new Error("Internet identity already exists");
}
} else {
if (
!identity.name ||
identities.some((i) => i.name === identity.name)
) {
throw new Error("Identity already exists or name is missing");
}
if (!identity.name || identities.some((i) => i.name === identity.name)) {
throw new Error("Identity already exists or name is missing");
}

identities.push(identity);
break;

Expand Down
3 changes: 3 additions & 0 deletions main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ contextBridge.exposeInMainWorld('awesomeApi', {
updateEnvVariables: async (path, key, value) => {
return ipcRenderer.invoke('env:update-script', path, key, value);
},
refreshIdentities: async () => {
return ipcRenderer.invoke('identity:refresh');
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "dfinity-dfx-gui",
"description": "DFINITY DFX GUI is a cross platform, electron based application designed to streamline the use of the DFINITY's Internet Computer `dfx` CLI.",
"version": "0.0.1",
"version": "0.1.0",
"author": "Tolga Yaycı <tolgayayci@protonmail.com>",
"main": "app/background.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions renderer/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CSC_IDENTITY_AUTO_DISCOVERY=true
74 changes: 41 additions & 33 deletions renderer/components/canisters/canister-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@components/ui/dialog";

import { ScrollArea, ScrollBar } from "@components/ui/scroll-area";
Expand Down Expand Up @@ -48,45 +47,54 @@ export default function CanisterDetail({

const handleRemoveClick = async () => {
try {
await window.awesomeApi
.runDfxCommand("canister", "stop", [canisterName], [], projectPath)
.then(async () => {
await removeCanister();
})
.catch((err) => {
let errorMessage = "Failed to stop canister: ";
if (err.message) {
errorMessage += err.message;
} else {
// Stringify the error object or parts of it
errorMessage += JSON.stringify(err, null, 2); // Pretty print the error
}
setErrorMessage(errorMessage);
});
// First, try to stop the canister
await window.awesomeApi.runDfxCommand(
"canister",
"stop",
[canisterName],
[],
projectPath
);

// If the above command is successful, proceed to remove the canister
await removeCanister();
} catch (err) {
console.log(err);
// Handling any errors that occur in the try block
let errorMessage = "Failed to process canister: ";

if (err.message) {
errorMessage += err.message;
} else {
// Stringify the error object or parts of it
errorMessage += JSON.stringify(err, null, 2); // Pretty print the error
}

setErrorMessage(errorMessage);
}
};

const removeCanister = async () => {
try {
await window.awesomeApi
.runDfxCommand("canister", "delete", [canisterName], [], projectPath)
.then((data) => {
setSuccessMessage("Canister deleted successfully:" + data);
})
.catch((err) => {
let errorMessage = "Failed to delete canister: ";
if (err.message) {
errorMessage += err.message;
} else {
// Stringify the error object or parts of it
errorMessage += JSON.stringify(err, null, 2); // Pretty print the error
}
setErrorMessage(errorMessage);
});
// Using await to handle the promise
const data = await window.awesomeApi.runDfxCommand(
"canister",
"delete",
[canisterName],
[],
projectPath
);

setSuccessMessage("Canister deleted successfully: " + data);
} catch (err) {
console.log(err);
let errorMessage = "Failed to delete canister: ";

if (err.message) {
errorMessage += err.message;
} else {
// Stringify the error object or parts of it
errorMessage += JSON.stringify(err, null, 2); // Pretty print the error
}
setErrorMessage(errorMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion renderer/components/common/dfx-not-installed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function DfxNotInstalled() {
) as any
}
>
Visit Website
Visit GitHub
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
Expand Down
41 changes: 18 additions & 23 deletions renderer/components/identities/forms/createNewIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,25 @@ export async function onNewIdentityFormSubmit(
: null,
data.storage_mode ? `storage-mode=${data.storage_mode}` : null,
data.force === true ? "force" : null,
].filter(Boolean); // This will remove any null values from the array
].filter(Boolean);

await window.awesomeApi
.runDfxCommand(command, subcommand, args, flags)
.then(async () => {
await window.awesomeApi
.runDfxCommand(
"identity",
"get-principal",
["--identity"],
[data.identity_name]
)
.then(
async (principaldata) =>
await window.awesomeApi
.manageIdentities("add", {
name: data.identity_name,
isInternetIdentity: false,
principal: principaldata,
})
.then(async () => await window.awesomeApi.reloadApplication())
);
});
await window.awesomeApi.runDfxCommand(command, subcommand, args, flags);

const principaldata = await window.awesomeApi.runDfxCommand(
"identity",
"get-principal",
["--identity"],
[data.identity_name]
);

await window.awesomeApi.manageIdentities("add", {
name: data.identity_name,
isInternetIdentity: false,
principal: principaldata,
});

await window.awesomeApi.reloadApplication();
} catch (error) {
console.error(`Error: ${error}`); // log error
console.error(`Error: ${error}`);
}
}
13 changes: 4 additions & 9 deletions renderer/components/identities/forms/importNewIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@ export async function onimportIdentityFormSubmit(
data.pem_identity ? `pem-identity=${data.pem_identity}` : null,
data.storage_mode ? `storage-mode=${data.storage_mode}` : null,
data.force === true ? "force" : null,
].filter(Boolean); // This will remove any null values from the array
].filter(Boolean);

const result = await window.awesomeApi.runDfxCommand(
command,
subcommand,
args,
flags
);
await window.awesomeApi.runDfxCommand(command, subcommand, args, flags);

return result;
await window.awesomeApi.reloadApplication();
} catch (error) {
console.error(`Error: ${error}`); // log error
console.error(`Error: ${error}`);
}
}
20 changes: 9 additions & 11 deletions renderer/components/identities/forms/removeIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ export async function onRemoveIdentityFormSubmit(
Boolean
);

await window.awesomeApi
.runDfxCommand(command, subcommand, args)
.then(async () => {
await window.awesomeApi
.manageIdentities("delete", {
name: data.identity_name,
isInternetIdentity: false,
})
.then(async () => await window.awesomeApi.reloadApplication());
});
await window.awesomeApi.runDfxCommand(command, subcommand, args, flags);

await window.awesomeApi.manageIdentities("delete", {
name: data.identity_name,
isInternetIdentity: false,
});

await window.awesomeApi.reloadApplication();
} catch (error) {
console.error(`Error: ${error}`); // log error
console.error(`Error: ${error}`);
}
}
20 changes: 9 additions & 11 deletions renderer/components/identities/forms/renameIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ export async function onRenameIdentityFormSubmit(
const subcommand = "rename";
const args = [data.from_identity_name, data.to_identity_name];

await window.awesomeApi
.runDfxCommand(command, subcommand, args)
.then(async () => {
await window.awesomeApi
.manageIdentities(
"rename",
{ name: data.from_identity_name },
data.to_identity_name
)
.then(async () => await window.awesomeApi.reloadApplication());
});
await window.awesomeApi.runDfxCommand(command, subcommand, args);

await window.awesomeApi.manageIdentities(
"rename",
{ name: data.from_identity_name },
data.to_identity_name
);

await window.awesomeApi.reloadApplication();
} catch (error) {
console.error(`Error: ${error}`);
}
Expand Down
1 change: 1 addition & 0 deletions renderer/components/identities/identity-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function IdentityModal({
const handleImportIdentity = async (data) => {
try {
await onimportIdentityFormSubmit(data).then((res) => {
//@ts-ignore
if (res) {
toast(identityImportSuccess(res));
setShowCreateIdentityDialog(false);
Expand Down

0 comments on commit 42c2c20

Please sign in to comment.