Skip to content

Commit 474183f

Browse files
committed
🐛 移除mac顶部菜单栏中的没有实际用途的各种按钮
1 parent ca2900c commit 474183f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

app/src/main.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import "./index.css";
3636
import "./polyfills/roundRect";
3737
import { exists } from "./utils/fs";
3838
import { exit, writeStderr } from "./utils/otherApi";
39-
import { getCurrentWindow, isDesktop, isFrame, isWeb, isWindows } from "./utils/platform";
39+
import { getCurrentWindow, isDesktop, isFrame, isMac, isWeb, isWindows } from "./utils/platform";
40+
import { Menu, MenuItem } from "@tauri-apps/api/menu";
4041

4142
const router = createMemoryRouter(routes);
4243
const Routes = () => <RouterProvider router={router} />;
@@ -48,6 +49,9 @@ const el = document.getElementById("root")!;
4849
(async () => {
4950
const matches = !isWeb && isDesktop ? await getMatches() : null;
5051
const isCliMode = isDesktop && matches?.args.output?.occurrences === 1;
52+
if (isMac) {
53+
macosLoadMenu();
54+
}
5155
await Promise.all([
5256
Settings.init(),
5357
RecentFileManager.init(),
@@ -160,6 +164,30 @@ async function loadStartFile() {
160164
}
161165
}
162166

167+
/** macos加载顶部菜单栏 */
168+
async function macosLoadMenu() {
169+
// 奇怪了,什么都显示不出来(
170+
// 创建菜单项
171+
const testItem1 = await MenuItem.new({
172+
text: "测试",
173+
action: (_id) => {
174+
console.log(_id);
175+
},
176+
});
177+
const testItem2 = await MenuItem.new({
178+
text: "测试2",
179+
action: (_id) => {
180+
console.log(_id);
181+
},
182+
});
183+
// 创建主菜单
184+
const menu = await Menu.new({ items: [testItem1, testItem2] });
185+
186+
// 设置应用菜单
187+
await menu.setAsAppMenu();
188+
console.log("macos加载菜单栏成功");
189+
}
190+
163191
/** 渲染应用 */
164192
async function renderApp(cli: boolean = false) {
165193
const root = createRoot(el);

0 commit comments

Comments
 (0)