Skip to content

Commit

Permalink
fix URL Scheme not working issue, add shortcut to toggle hud by long …
Browse files Browse the repository at this point in the history
…press icon
  • Loading branch information
AsakuraFuuko committed Mar 14, 2024
1 parent 4c32629 commit 3858e07
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
13 changes: 11 additions & 2 deletions layout/Applications/Helium.app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.leemin.helium</string>
<key>CFBundleURLSchemes</key>
Expand All @@ -54,6 +52,17 @@
</array>
</dict>
</array>
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconSymbolName</key>
<string>switch.2</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Toggle HUD</string>
<key>UIApplicationShortcutItemType</key>
<string>com.leemin.helium.shortcut.toggle-hud</string>
</dict>
</array>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>CFBundleLocalizations</key>
Expand Down
1 change: 1 addition & 0 deletions layout/Applications/Helium.app/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Toggle HUD" = "Toggle HUD";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Toggle HUD" = "打开/关闭悬浮窗";
28 changes: 28 additions & 0 deletions src/app/MainApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#import "MainApplication.h"
#import "Helium-Swift.h"

#import "../hud/HUDHelper.h"
#import "../extensions/FontUtils.h"
#import "../extensions/Weather/HWeatherController.h"
#import "../helpers/private_headers/UIApplication+Private.h"

@implementation MainApplicationDelegate

Expand Down Expand Up @@ -32,4 +34,30 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
if ([shortcutItem.type isEqualToString:@"com.leemin.helium.shortcut.toggle-hud"]) {
SetHUDEnabled(!IsHUDEnabled());
[[UIApplication sharedApplication] suspend];
}
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
if ([url.scheme isEqualToString:@"helium"]) {
if ([url.host isEqualToString:@"toggle"]) {
SetHUDEnabled(!IsHUDEnabled());
[[UIApplication sharedApplication] suspend];
return YES;
} else if ([url.host isEqualToString:@"on"]) {
SetHUDEnabled(true);
[[UIApplication sharedApplication] suspend];
return YES;
} else if ([url.host isEqualToString:@"off"]) {
SetHUDEnabled(false);
[[UIApplication sharedApplication] suspend];
return YES;
}
}
return NO;
}

@end
20 changes: 3 additions & 17 deletions src/views/navigation/HomePageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,14 @@ struct HomePageView: View {
.onAppear {
#if !targetEnvironment(simulator)
isNowEnabled = IsHUDEnabledBridger()
NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main) { _ in
isNowEnabled = IsHUDEnabledBridger()
}
#endif
if UserDefaults.standard.string(forKey: "dateLocale", forPath: USER_DEFAULTS_PATH) == nil {
UserDefaults.standard.setValue(Locale.current.languageCode!, forKey: "dateLocale", forPath: USER_DEFAULTS_PATH)
}
}
.onOpenURL(perform: { url in
let _ = FileManager.default
// MARK: URL Schemes
if url.absoluteString == "helium://toggle" {
#if !targetEnvironment(simulator)
toggleHUD(!isNowEnabled)
#endif
} else if url.absoluteString == "helium://on" {
#if !targetEnvironment(simulator)
toggleHUD(true)
#endif
} else if url.absoluteString == "helium://off" {
#if !targetEnvironment(simulator)
toggleHUD(false)
#endif
}
})
.navigationTitle(Text(NSLocalizedString("Helium", comment: "")))
}
.navigationViewStyle(StackNavigationViewStyle())
Expand Down

0 comments on commit 3858e07

Please sign in to comment.