Skip to content

Commit 49bef69

Browse files
committed
feat: macos open with handling
1 parent 191e84b commit 49bef69

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ define(function (require, exports, module) {
16331633

16341634
async function _singleInstanceHandler(args) {
16351635
const isPrimary = await Phoenix.app.isPrimaryDesktopPhoenixWindow();
1636-
if(!isPrimary){
1636+
const bootTimeMacOsFlag = (args[0] === "macOSBootTimeDeepLink");
1637+
if(!bootTimeMacOsFlag && !isPrimary){
16371638
// only primary phoenix windows can open a new window, else every window is going to make its own
16381639
// window and cause a runaway phoenix window explosion.
16391640
return;

src/phoenix/shell.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Phoenix.app = {
157157
* double clicking a file in file explorer in os, the handler will be called with the command line args with the
158158
* file that was double-clicked (or folder using open with) in os file explorer/cli.
159159
* @param {function(cliArgs, cwd)} handlerFn - the handler function will receive two args on callback, the cliArgs
160-
* of the other phoenix process that was invoked to open the file and its current working dir.
160+
* of the other phoenix process that was invoked to open the file and its current working dir. cwd may be null
161161
* @return {*}
162162
*/
163163
setSingleInstanceCLIArgsHandler: function (handlerFn) {
@@ -171,10 +171,25 @@ Phoenix.app = {
171171
window.__TAURI__.event.listen("single-instance", ({payload})=> {
172172
handlerFn(payload.args, payload.cwd);
173173
});
174+
window.__TAURI__.tauri.invoke("get_mac_deep_link_requests").then(filesURLList=>{
175+
if(!filesURLList.length){
176+
return;
177+
}
178+
// this is special handling for open with to work from mac finder. Mac will raise and event which will
179+
// be buffered in the shell till the app reads the opened file list. Once read, the file list will be
180+
// emptied in shell and no other instances will get the data, so we have to process it here.
181+
const platformSimulatedArgs = ["macOSBootTimeDeepLink"];
182+
for(const fileURL of filesURLList){
183+
platformSimulatedArgs.push(fileURL.replace("file://", ""));
184+
}
185+
handlerFn(platformSimulatedArgs, "");
186+
});
174187
window.__TAURI__.event.listen("scheme-request-received", (receivedEvent)=> {
175188
// this is for mac-os open with processing from finder.
176-
console.error("Macos not handled", receivedEvent);
177-
alert(JSON.stringify(receivedEvent));
189+
console.log("Macos received Event from OS:", receivedEvent);
190+
const fileURL = receivedEvent.payload;
191+
window.__TAURI__.tauri.invoke("get_mac_deep_link_requests");// this will clear the cached queue in shell
192+
handlerFn(["macOSEvent", fileURL.replace("file://", "")], "");
178193
});
179194
}
180195
},

0 commit comments

Comments
 (0)