Skip to content

Commit 753275c

Browse files
committed
Build shortcuts and menubar
1 parent 8c9ce6f commit 753275c

File tree

5 files changed

+401
-195
lines changed

5 files changed

+401
-195
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You can download the latest build from [actions](https://github.com/nab138/YCode
1414

1515
## How it works
1616

17-
- A darwin SDK is generated from a user provided copy of Xcode 16.3 and darwin tools from [darwin-tools-linux-llvm](https://github.com/xtool-org/darwin-tools-linux-llvm)
17+
- A darwin SDK is generated from a user provided copy of Xcode 16.3 (extracted with [unxip](https://github.com/saagarjha/unxip)) and darwin tools from [darwin-tools-linux-llvm](https://github.com/xtool-org/darwin-tools-linux-llvm)
1818
- Swift uses the darwin SDK to build an executable which is packaged into an .app bundle.
1919
- [apple-private-apis](https://github.com/SideStore/apple-private-apis) is used to login to the Apple Account. Heavy additions have been made to support actually accessing the Developer APIs
2020
- [ZSign](https://github.com/zhlynn/zsign) is used to sign the IPA with the certificate and provisioning profile acquired from the Apple Account
@@ -33,5 +33,5 @@ The app is currently functional but does not have all the features it should. Yo
3333

3434
### AI Usage
3535

36-
- Generated the logo
37-
- Helped port small sections of code from [Sideloader](https://github.com/Dadoum/Sideloader) because I'm not familiar with dlang syntax
36+
- Generated the logo (I'm sorry, its only temporary I promise)
37+
- Helped port small sections of code from [Sideloader](https://github.com/Dadoum/Sideloader) because I'm not familiar with dlang syntax

src/components/CommandButton.tsx

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { Button } from "@mui/joy";
1+
import { Button, MenuItem } from "@mui/joy";
22
import { useCommandRunner } from "../utilities/Command";
33
import { useIDE } from "../utilities/IDEContext";
44

55
export interface CommandButtonProps {
66
command: string;
77
parameters?: Record<string, unknown>;
88
label?: string;
9-
icon: React.ReactNode;
9+
tooltip?: string;
10+
icon?: React.ReactNode;
1011
variant?: "plain" | "outlined" | "soft" | "solid";
1112
sx?: React.CSSProperties;
1213
clearConsole?: boolean;
1314
validate?: () => boolean;
15+
disabled?: boolean;
16+
useMenuItem?: boolean;
17+
shortcut?: React.ReactNode;
18+
id?: string;
1419
}
1520

1621
export default function CommandButton({
@@ -19,26 +24,39 @@ export default function CommandButton({
1924
label,
2025
icon,
2126
variant,
27+
tooltip,
2228
sx = {},
2329
clearConsole = true,
2430
validate = () => true,
31+
disabled = false,
32+
useMenuItem = false,
33+
shortcut,
34+
id,
2535
}: CommandButtonProps) {
2636
const { isRunningCommand, currentCommand, runCommand, cancelCommand } =
2737
useCommandRunner();
2838
const { setConsoleLines } = useIDE();
2939

40+
const Component: React.ElementType = useMenuItem ? MenuItem : Button;
41+
3042
return (
31-
<Button
32-
disabled={isRunningCommand && currentCommand !== command}
33-
startDecorator={label == "" || label == undefined ? undefined : icon}
34-
loading={isRunningCommand && currentCommand === command}
43+
<Component
44+
disabled={disabled || (isRunningCommand && currentCommand !== command)}
45+
loading={
46+
useMenuItem ? undefined : isRunningCommand && currentCommand === command
47+
}
3548
variant={variant}
3649
size="md"
37-
sx={{
38-
marginRight: "var(--padding-md)",
39-
padding: "0 var(--padding-md)",
40-
...sx,
41-
}}
50+
sx={
51+
useMenuItem
52+
? {}
53+
: {
54+
marginRight: "var(--padding-md)",
55+
padding: "0 var(--padding-md)",
56+
...sx,
57+
}
58+
}
59+
title={tooltip}
4260
onClick={() => {
4361
if (!validate()) {
4462
return;
@@ -54,8 +72,11 @@ export default function CommandButton({
5472
}
5573
runCommand(command, parameters);
5674
}}
75+
id={id}
5776
>
5877
{label == "" || label == undefined ? icon : label}
59-
</Button>
78+
{shortcut !== undefined && " "}
79+
{shortcut}
80+
</Component>
6081
);
6182
}

src/components/Menu/MenuBar.tsx

Lines changed: 35 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { WebviewWindow } from "@tauri-apps/api/webviewWindow";
21
import Menu from "@mui/joy/Menu";
32
import List from "@mui/joy/List";
43
import ListItem from "@mui/joy/ListItem";
54
import { useCallback, useEffect, useRef, useState } from "react";
65
import MenuBarButton from "./MenuBarButton";
7-
import MenuGroup, { MenuBarData } from "./MenuGroup";
6+
import MenuGroup from "./MenuGroup";
87
import { Shortcut, acceleratorPresssed } from "../../utilities/Shortcut";
98
import CommandButton from "../CommandButton";
109
import {
@@ -14,165 +13,11 @@ import {
1413
CleaningServices,
1514
} from "@mui/icons-material";
1615
import { useParams } from "react-router-dom";
17-
import { openUrl } from "@tauri-apps/plugin-opener";
1816
import { Divider, Option, Select } from "@mui/joy";
1917
import { DeviceInfo, useIDE } from "../../utilities/IDEContext";
2018
import { useStore } from "../../utilities/StoreContext";
2119
import { useToast } from "react-toast-plus";
22-
23-
const bar = [
24-
{
25-
label: "File",
26-
items: [
27-
{
28-
label: "New",
29-
items: [
30-
{
31-
name: "New File...",
32-
shortcut: "Ctrl+N",
33-
callback: () => {
34-
console.log("New File!");
35-
},
36-
},
37-
{
38-
name: "New Project...",
39-
callbackName: "newProject",
40-
},
41-
],
42-
},
43-
{
44-
label: "Open",
45-
items: [
46-
{
47-
name: "Open File...",
48-
shortcut: "Ctrl+O",
49-
callback: () => {
50-
console.log("Open File!");
51-
},
52-
},
53-
{
54-
name: "Open Folder...",
55-
callbackName: "openFolderDialog",
56-
},
57-
],
58-
},
59-
{
60-
label: "Save",
61-
items: [
62-
{
63-
name: "Save",
64-
shortcut: "Ctrl+S",
65-
callbackName: "save",
66-
},
67-
{
68-
name: "Save As...",
69-
shortcut: "Ctrl+Shift+S",
70-
callback: () => {
71-
console.log("Save As!");
72-
},
73-
},
74-
],
75-
},
76-
],
77-
},
78-
{
79-
label: "Edit",
80-
items: [
81-
{
82-
label: "Timeline",
83-
items: [
84-
{
85-
name: "Undo",
86-
shortcut: "Ctrl+Z",
87-
callback: () => {
88-
console.log("Undo!");
89-
},
90-
},
91-
{
92-
name: "Redo",
93-
shortcut: "Ctrl+Shift+Z",
94-
callback: () => {
95-
console.log("Redo!");
96-
},
97-
},
98-
],
99-
},
100-
{
101-
label: "Settings",
102-
items: [
103-
{
104-
name: "Preferences...",
105-
callback: async () => {
106-
let prefsWindow = await WebviewWindow.getByLabel("prefs");
107-
if (prefsWindow) {
108-
prefsWindow.show();
109-
prefsWindow.center();
110-
prefsWindow.setFocus();
111-
return;
112-
}
113-
114-
const appWindow = new WebviewWindow("prefs", {
115-
title: "Preferences",
116-
resizable: false,
117-
width: 800,
118-
height: 600,
119-
url: "/preferences/general",
120-
});
121-
appWindow.once("tauri://created", function () {
122-
appWindow.center();
123-
});
124-
appWindow.once("tauri://error", function (e) {
125-
console.error("Error creating window:", e);
126-
});
127-
},
128-
},
129-
],
130-
},
131-
],
132-
},
133-
{
134-
label: "View",
135-
items: [
136-
{
137-
label: "Navigation",
138-
items: [
139-
{
140-
name: "Show Welcome Page",
141-
callbackName: "welcomePage",
142-
},
143-
],
144-
},
145-
{
146-
label: "Debug",
147-
items: [
148-
{
149-
name: "Reload Window",
150-
callback: async () => {
151-
window.location.reload();
152-
},
153-
shortcut: "Ctrl+R",
154-
},
155-
],
156-
},
157-
],
158-
},
159-
{
160-
label: "Help",
161-
items: [
162-
{
163-
label: "About YCode",
164-
items: [
165-
{
166-
name: "View Github",
167-
callback: () => {
168-
openUrl("https://github.com/nab138/YCode");
169-
},
170-
},
171-
],
172-
},
173-
],
174-
},
175-
] as MenuBarData;
20+
import bar from "./MenuBarDefinition";
17621

17722
export interface MenuBarProps {
17823
callbacks: Record<string, () => void>;
@@ -199,10 +44,33 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
19944
if (item.shortcut) {
20045
const shortcut = Shortcut.fromString(item.shortcut);
20146
let callback;
202-
if (item.callbackName !== undefined) {
47+
if (
48+
"callbackName" in item &&
49+
typeof item.callbackName === "string"
50+
) {
20351
callback = callbacks[item.callbackName];
52+
} else if (
53+
"callback" in item &&
54+
typeof item.callback === "function"
55+
) {
56+
callback = item.callback;
57+
} else if (
58+
"component" in item &&
59+
"componentId" in item &&
60+
typeof item.componentId === "string"
61+
) {
62+
// This whole thing needs to be reworked because this is disgusting, too bad I'm lazy!
63+
callback = () => {
64+
const element = document.getElementById(
65+
item.componentId as string
66+
);
67+
console.log(element);
68+
if (element) {
69+
(element as HTMLButtonElement).click();
70+
}
71+
};
20472
} else {
205-
callback = item.callback ?? (() => {});
73+
callback = () => {};
20674
}
20775
items.push({
20876
shortcut,
@@ -324,6 +192,7 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
324192
}}
325193
menu={
326194
<Menu
195+
keepMounted
327196
size="sm"
328197
onClose={() => {
329198
menus.current[index]?.focus();
@@ -333,6 +202,7 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
333202
handleKeyDown={handleKeyDown}
334203
resetMenuIndex={resetMenuIndex}
335204
groups={menu.items}
205+
selectedDevice={selectedDevice}
336206
callbacks={callbacks}
337207
/>
338208
</Menu>
@@ -350,6 +220,7 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
350220
folder: path,
351221
toolchainPath: selectedToolchain?.path ?? "",
352222
}}
223+
tooltip="Clean"
353224
sx={{ marginLeft: "auto", marginRight: 0 }}
354225
/>
355226
<CommandButton
@@ -361,6 +232,7 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
361232
toolchainPath: selectedToolchain?.path ?? "",
362233
debug: true,
363234
}}
235+
tooltip="Build .ipa"
364236
sx={{ marginRight: 0 }}
365237
/>
366238
<Divider orientation="vertical" />
@@ -369,12 +241,14 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
369241
variant="plain"
370242
command="refresh_idevice"
371243
icon={<Refresh />}
244+
tooltip="Refresh Devices"
372245
parameters={{}}
373246
sx={{ marginLeft: 0, marginRight: 0 }}
374247
clearConsole={false}
375248
/>
376249
<Select
377250
size="sm"
251+
title="Select Device"
378252
value={selectedDevice?.id.toString() ?? "none"}
379253
onChange={(_, value) => {
380254
setSelectedDevice(
@@ -395,6 +269,8 @@ export default function MenuBar({ callbacks }: MenuBarProps) {
395269
))}
396270
</Select>
397271
<CommandButton
272+
disabled={!selectedDevice}
273+
tooltip="Build & Install"
398274
variant="plain"
399275
command="deploy_swift"
400276
icon={<PhonelinkSetup />}

0 commit comments

Comments
 (0)