Skip to content

Commit d2313da

Browse files
committed
Fix SIGSEGFAULT and more
Fixed a problem, where a double free occured because the ObjC ARC freed a NSWindow automatically, where the NSWindow Handler would try the same. This led to a double free error. Implemented functionality to close dynamic backgrounds, which reside on the current space
1 parent 551dc53 commit d2313da

File tree

8 files changed

+189
-52
lines changed

8 files changed

+189
-52
lines changed

.DS_Store

2 KB
Binary file not shown.

WavyBackgroundsClient/src-tauri/Cargo.lock

Lines changed: 42 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WavyBackgroundsClient/src-tauri/src/main.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
55
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
66

7-
use icrate::AppKit::NSWindow;
8-
use icrate::objc2::rc::Id;
97
use tauri::{AppHandle, CustomMenuItem, Manager, RunEvent, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, SystemTraySubmenu, WindowBuilder, WindowUrl};
108
use libResourceManager::{chec_for_local, delete_local_resource, get_full_database, LocalSaveCheck, WallpaperVideoEntry};
119
use libVisualPanic::ErrorHandlingOption;
@@ -36,9 +34,8 @@ fn get_full_database_command(app_handle: AppHandle) -> Vec<WallpaperVideoEntry>{
3634
.add_submenu(favorite_submenu)
3735
.add_submenu(all_submenu)
3836
.add_native_item(SystemTrayMenuItem::Separator)
39-
.add_item(CustomMenuItem::new("close_backgrounds", "Remove all dynamic wallpapers"));
40-
// Currently produces a segfault.
41-
//.add_item(CustomMenuItem::new("close_background_active_space", "Remove dynamic wallpapers on active space"))
37+
.add_item(CustomMenuItem::new("close_backgrounds", "Remove all dynamic wallpapers"))
38+
.add_item(CustomMenuItem::new("close_background_active_space", "Remove dynamic wallpapers on active space"));
4239

4340
app_handle.tray_handle().set_menu(tray_menu).unwrap();
4441

@@ -57,21 +54,31 @@ fn check_if_local_exists(identifier: String) -> LocalSaveCheck {
5754

5855
#[tauri::command]
5956
fn apply_to_screen(identifier: String) {
60-
let window = libDynamicWallpapaper::apply_to_screen(identifier);
61-
unsafe { WINDOW_VEC.push(window); };
57+
let window_identifier = libDynamicWallpapaper::apply_to_screen(identifier);
58+
unsafe { WINDOW_VEC.push(window_identifier); };
6259
}
6360

6461
#[tauri::command]
6562
fn remove_all() {
6663
unsafe {
67-
WINDOW_VEC.retain(|window| {
68-
libDynamicWallpapaper::close_window(window);
69-
return true;
64+
WINDOW_VEC.retain(|window_identfier| {
65+
libDynamicWallpapaper::close_window(window_identfier.to_string());
66+
return false;
7067
});
7168
}
7269
}
7370

74-
static mut WINDOW_VEC: Vec<Id<NSWindow>> = vec![];
71+
#[tauri::command]
72+
fn remove_current_space() {
73+
unsafe {
74+
WINDOW_VEC.retain(|window_identfier| {
75+
let remove_this = libDynamicWallpapaper::close_window_on_screen(window_identfier.to_string());
76+
return remove_this;
77+
});
78+
}
79+
}
80+
81+
static mut WINDOW_VEC: Vec<String> = vec![];
7582

7683
fn main() {
7784

@@ -87,15 +94,14 @@ fn main() {
8794
.add_submenu(favorite_submenu)
8895
.add_submenu(all_submenu)
8996
.add_native_item(SystemTrayMenuItem::Separator)
90-
.add_item(CustomMenuItem::new("close_backgrounds", "Remove all dynamic wallpapers"));
91-
// Currently produces a segfault.
92-
//.add_item(CustomMenuItem::new("close_background_active_space", "Remove dynamic wallpapers on active space"));
97+
.add_item(CustomMenuItem::new("close_backgrounds", "Remove all dynamic wallpapers"))
98+
.add_item(CustomMenuItem::new("close_background_active_space", "Remove dynamic wallpapers on active space"));
9399

94100
let tray = SystemTray::new().with_menu(tray_menu).with_tooltip("WavyBackgrounds");
95101

96102
tauri::Builder::default()
97103
.system_tray(tray)
98-
.invoke_handler(tauri::generate_handler![get_full_database_command, download_file, delete_local, check_if_local_exists, apply_to_screen, remove_all])
104+
.invoke_handler(tauri::generate_handler![get_full_database_command, download_file, delete_local, check_if_local_exists, apply_to_screen, remove_all, remove_current_space])
99105
.setup(|_app| {
100106
Ok(())
101107
})
@@ -117,23 +123,20 @@ fn main() {
117123
}
118124
else if id.as_str() == "close_backgrounds" {
119125
unsafe {
120-
unsafe {
121-
WINDOW_VEC.retain(|window| {
122-
libDynamicWallpapaper::close_window(window);
123-
return true;
124-
});
125-
}
126+
WINDOW_VEC.retain(|window_identfier| {
127+
libDynamicWallpapaper::close_window(window_identfier.to_string());
128+
return false;
129+
});
126130
}
127131
}
128-
/* Currently produces a segfault.
129132
else if id.as_str() == "close_background_active_space" {
130133
unsafe {
131-
WINDOW_VEC.retain(|window| {
132-
return !libDynamicWallpapaper::close_window_on_screen(window.clone());
134+
WINDOW_VEC.retain(|window_identfier| {
135+
let remove_this = libDynamicWallpapaper::close_window_on_screen(window_identfier.to_string());
136+
return remove_this;
133137
});
134138
}
135139
}
136-
*/
137140
else {
138141
apply_to_screen(id);
139142
}

WavyBackgroundsClient/src/App.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
.footerSpaceSelection {
3232
display: flex;
3333
align-items: center;
34+
column-gap: 10px;
3435
}
3536

3637
.selector {

WavyBackgroundsClient/src/App.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface WallpaperVideoEntry {
2121

2222
function App() {
2323

24-
function downloadVideo() {
24+
async function downloadVideo() {
2525
let selected_card = selected();
2626
let wallpaper_struct = entries.get(selected_card);
2727
let download_url = wallpaper_struct.video_url;
@@ -30,7 +30,7 @@ function App() {
3030
let unlisten = listen("progress_" + identifier, (event) => {
3131
wallpaper_struct.download_progress[1]((event.payload[1]/event.payload[0]*100).toString());
3232
})
33-
invoke("download_file", {identifier: identifier, url: download_url}).then((result: string | null) => {
33+
await invoke("download_file", {identifier: identifier, url: download_url}).then((result: string | null) => {
3434
if(result === null) {
3535

3636
} else {
@@ -77,11 +77,21 @@ function App() {
7777
<button onClick={async () => {
7878
await invoke("remove_all");
7979
}}>Remove all dynamic backgrounds</button>
80+
<button onClick={async ()=> {
81+
await invoke("remove_current_space");
82+
}}>Remove dynamic backgrounds on current space</button>
8083
</div>
8184
<div class={"footerButtons"}>
8285
<button onClick={() => downloadVideo()}>Download</button>
8386
<button class={"applyButton"} onclick={async () => {
84-
await invoke("apply_to_screen", {identifier: selected()});
87+
await invoke("check_if_local_exists", {identifier: selected()}).then(async (answer)=> {
88+
if(answer.is_saved) {
89+
await invoke("apply_to_screen", {identifier: selected()});
90+
} else {
91+
await downloadVideo();
92+
await invoke("apply_to_screen", {identifier: selected()});
93+
}
94+
});
8595
}}>Apply</button>
8696
</div>
8797
</div>

libDynamicWallpapaper/Cargo.lock

Lines changed: 44 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libDynamicWallpapaper/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
icrate = {version = "0.0.4", features = ["AppKit", "AppKit_NSWindow", "AppKit_NSScreen", "AppKit_NSView", "Foundation", "Foundation_NSString", "Foundation_NSURL"]}
10-
libResourceManager = { path = "../libResourceManager" }
9+
icrate = {version = "0.0.4", features = ["AppKit", "AppKit_NSWindow", "AppKit_NSScreen", "AppKit_NSView", "Foundation", "Foundation_NSString", "Foundation_NSURL", "AppKit_NSApplication"]}
10+
objc2 = {version = "0.5.0", features = ["catch-all", "unstable-autoreleasesafe"]}
11+
libResourceManager = { path = "../libResourceManager" }
12+
globals = "1.0.3"

0 commit comments

Comments
 (0)