Touchbar Workaround

Mac OSX specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Touchbar Workaround

Post by mk-soft »

Not only Purebasic has a problem with the touchbar.
As long as this is not solved, I have found a workaround.
The setting for this application remembers the OS. So if the announcement with Touchbar to run, must also be allowed again.

Update v 1.03

Code: Select all

;-TOP

; Touchbar workaround by mk-soft
; Version v1.03
; Date 08/15/2017

Procedure IsTouchbar()
  Protected standardUserDefaults, r1
  standardUserDefaults = CocoaMessage(0, 0, "NSUserDefaults standardUserDefaults")
  r1 = CocoaMessage(0, standardUserDefaults, "integerForKey:$", @"NSFunctionBarAPIEnabled")
  ProcedureReturn r1
EndProcedure

Procedure DisableTouchbar()
  Protected standardUserDefaults
  If IsTouchbar()
    standardUserDefaults = CocoaMessage(0, 0, "NSUserDefaults standardUserDefaults")
    CocoaMessage(0, standardUserDefaults, "setBool:", #NO, "forKey:$", @"NSFunctionBarAPIEnabled")
    RunProgram(ProgramFilename(), ProgramParameter(), GetCurrentDirectory())
    End
  EndIf
EndProcedure

Procedure EnableTouchbar()
  Protected standardUserDefaults
  If IsTouchbar() = 0
    standardUserDefaults = CocoaMessage(0, 0, "NSUserDefaults standardUserDefaults")
    CocoaMessage(0, standardUserDefaults, "setBool:", #YES, "forKey:$", @"NSFunctionBarAPIEnabled")
    RunProgram(ProgramFilename(), ProgramParameter(), GetCurrentDirectory())
    End
  EndIf
EndProcedure

; ***************************************************************************************

CompilerIf #PB_Compiler_IsMainFile
  
  DisableTouchbar()
  
  If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    Delay(100)
    ; this website doesn't crash the app
    ;WebGadget(0, 10, 10, 580, 280, "http://www.apple.com") 
    ; this website crashes the app
    WebGadget(0, 10, 10, 580, 280, "http://google.com") 
    
    Repeat 
      ; crash with "http://google.com"
    Until WaitWindowEvent() = #PB_Event_CloseWindow  ; <- Invalid memory access
  EndIf
CompilerEndIf
Last edited by mk-soft on Tue Aug 15, 2017 1:08 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Touchbar Workaround

Post by mk-soft »

Update v1.02
- Added IsTouchbar()
- Optimize code

Update v1.03
- Fix current directory
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Touchbar Workaround

Post by Fred »

A relauch is needed to have this setting applied ?

According to this post: http://indiestack.com/2016/12/touch-bar ... rotection/ it should work if put as soon as possible. Also seems to confirm it's an Apple issue. I will try to release a new lib for you to test, thank you to have took the time to look into it !
Post Reply