@@ -36,7 +36,8 @@ import "./index.css";
3636import "./polyfills/roundRect" ;
3737import { exists } from "./utils/fs" ;
3838import { 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
4142const router = createMemoryRouter ( routes ) ;
4243const 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/** 渲染应用 */
164192async function renderApp ( cli : boolean = false ) {
165193 const root = createRoot ( el ) ;
0 commit comments